1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai = require("chai");
|
19 | const environment_utils_1 = require("./environment-utils");
|
20 | const expect = chai.expect;
|
21 | describe('EnvironmentUtils', function () {
|
22 | describe('#mergeProcessEnv', function () {
|
23 | this.timeout(5000);
|
24 | let utils;
|
25 | const PATH = 'PATH';
|
26 | beforeEach(function () {
|
27 | utils = new environment_utils_1.EnvironmentUtils();
|
28 | });
|
29 | it('should validate the presence of a known process variable', function () {
|
30 | const mergedEnv = utils.mergeProcessEnv({});
|
31 | expect(mergedEnv[PATH]).length.greaterThan(0);
|
32 | });
|
33 | for (const platform of ['linux', 'darwin']) {
|
34 | it(`should conserve case for keys on "${platform}"`, function () {
|
35 | utils['getPlatform'] = () => platform;
|
36 | process.env['TestKey'] = 'test_value';
|
37 | const mergedEnv = utils.mergeProcessEnv({});
|
38 | expect(mergedEnv['TestKey']).equal('test_value');
|
39 | expect(mergedEnv['TESTKEY']).equal(undefined);
|
40 | });
|
41 | }
|
42 | it('should uppercase keys on "win32"', function () {
|
43 | utils['getPlatform'] = () => 'win32';
|
44 | process.env['TestKey'] = 'test_value';
|
45 | const mergedEnv = utils.mergeProcessEnv({});
|
46 | expect(mergedEnv['TestKey']).equal(undefined);
|
47 | expect(mergedEnv['TESTKEY']).equal('test_value');
|
48 | });
|
49 | it('should be possible to remove a known process variable', function () {
|
50 |
|
51 | const customizedEnv = { [PATH]: null };
|
52 | const mergedEnv = utils.mergeProcessEnv(customizedEnv);
|
53 | expect(mergedEnv[PATH]).equal(undefined);
|
54 | });
|
55 | it('should be possible to override the value of a known process variable', function () {
|
56 | const expectedValue = '/path/to/one';
|
57 | const customizedEnv = { [PATH]: expectedValue };
|
58 | const mergedEnv = utils.mergeProcessEnv(customizedEnv);
|
59 | expect(mergedEnv[PATH]).equals(expectedValue);
|
60 | });
|
61 | it('should not produce a different result when merging a previous result', function () {
|
62 | const variableName = 'NEW_VARIABLE';
|
63 | const expectedValue = 'true';
|
64 | const customizedEnv = { [variableName]: expectedValue };
|
65 | const mergedEnv = utils.mergeProcessEnv(customizedEnv);
|
66 | expect(mergedEnv[variableName]).equals(expectedValue);
|
67 | });
|
68 | it('should not produce a different result when performing multiple merges', function () {
|
69 | const variableName = 'NEW_VARIABLE';
|
70 | const expectedValue = 'true';
|
71 | const customizedEnv = { [variableName]: expectedValue };
|
72 | const mergedEnv = utils.mergeProcessEnv(customizedEnv);
|
73 | const mergedSecondPass = utils.mergeProcessEnv(mergedEnv);
|
74 | expect(mergedEnv).to.deep.equal(mergedSecondPass);
|
75 | });
|
76 | });
|
77 | });
|
78 |
|
\ | No newline at end of file |