forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentConfiguration.test.ts
More file actions
98 lines (74 loc) · 3.56 KB
/
EnvironmentConfiguration.test.ts
File metadata and controls
98 lines (74 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'path';
import { EnvironmentConfiguration } from '../EnvironmentConfiguration';
describe('EnvironmentConfiguration', () => {
let _oldEnv: typeof process.env;
beforeEach(() => {
EnvironmentConfiguration.reset();
_oldEnv = process.env;
process.env = {};
});
afterEach(() => {
process.env = _oldEnv;
});
describe('initialize', () => {
it('correctly allows no environment variables', () => {
expect(EnvironmentConfiguration.initialize).not.toThrow();
});
it('allows known environment variables', () => {
process.env['RUSH_TEMP_FOLDER'] = '/var/temp'; // eslint-disable-line dot-notation
expect(EnvironmentConfiguration.initialize).not.toThrow();
});
it('does not allow unknown environment variables', () => {
process.env['rush_foobar'] = 'asdf'; // eslint-disable-line dot-notation
expect(EnvironmentConfiguration.initialize).toThrow();
});
it('can be re-initialized', () => {
process.env['RUSH_TEMP_FOLDER'] = '/var/tempA'; // eslint-disable-line dot-notation
EnvironmentConfiguration.initialize({ doNotNormalizePaths: true });
expect(EnvironmentConfiguration.rushTempFolderOverride).toEqual('/var/tempA');
process.env['RUSH_TEMP_FOLDER'] = '/var/tempB'; // eslint-disable-line dot-notation
EnvironmentConfiguration.initialize({ doNotNormalizePaths: true });
expect(EnvironmentConfiguration.rushTempFolderOverride).toEqual('/var/tempB');
});
});
describe('rushTempDirOverride', () => {
it('throws if EnvironmentConfiguration is not initialized', () => {
expect(() => EnvironmentConfiguration.rushTempFolderOverride).toThrow();
});
it('returns undefined for unset environment variables', () => {
EnvironmentConfiguration.initialize();
expect(EnvironmentConfiguration.rushTempFolderOverride).not.toBeDefined();
});
it('returns the value for a set environment variable', () => {
const expectedValue: string = '/var/temp';
process.env['RUSH_TEMP_FOLDER'] = expectedValue; // eslint-disable-line dot-notation
EnvironmentConfiguration.initialize({ doNotNormalizePaths: true });
expect(EnvironmentConfiguration.rushTempFolderOverride).toEqual(expectedValue);
});
});
describe('pnpmStorePathOverride', () => {
const ENV_VAR: string = 'RUSH_PNPM_STORE_PATH';
it('throws if EnvironmentConfiguration is not initialized', () => {
expect(() => EnvironmentConfiguration.pnpmStorePathOverride).toThrow();
});
it('returns undefined for unset environment variable', () => {
EnvironmentConfiguration.initialize();
expect(EnvironmentConfiguration.pnpmStorePathOverride).not.toBeDefined();
});
it('returns the expected path from environment variable without normalization', () => {
const expectedValue: string = '/var/temp';
process.env[ENV_VAR] = expectedValue;
EnvironmentConfiguration.initialize({ doNotNormalizePaths: true });
expect(EnvironmentConfiguration.pnpmStorePathOverride).toEqual(expectedValue);
})
it('returns expected path from environment variable with normalization', () => {
const expectedValue: string = path.resolve(path.join(process.cwd(), 'temp'));
const envVar: string = './temp';
process.env[ENV_VAR] = envVar;
EnvironmentConfiguration.initialize();
expect(EnvironmentConfiguration.pnpmStorePathOverride).toEqual(expectedValue);
})
})
});