UNPKG

3.93 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2021 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const chai = require("chai");
19const environment_utils_1 = require("./environment-utils");
20const expect = chai.expect;
21describe('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 // eslint-disable-next-line no-null/no-null
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//# sourceMappingURL=environment-utils.spec.js.map
\No newline at end of file