File: env-replace.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (31 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (3)
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
/* @flow */
import envReplace from '../../src/util/env-replace';

describe('environment variable replacement', () => {
  it('will replace a token that exists in the environment', () => {
    let result = envReplace('test ${a} replacement', {a: 'token'});
    expect(result).toEqual('test token replacement');

    result = envReplace('${a} replacement', {a: 'token'});
    expect(result).toEqual('token replacement');

    result = envReplace('${a}', {a: 'token'});
    expect(result).toEqual('token');
  });

  it('will not replace a token that does not exist in the environment', () => {
    let thrown = false;
    try {
      envReplace('${a} replacement', {b: 'token'});
    } catch (err) {
      thrown = true;
      expect(err.message).toEqual('Failed to replace env in config: ${a}');
    }
    expect(thrown).toEqual(true);
  });

  it('will not replace a token when a the token-replacement mechanism is prefixed a backslash literal', () => {
    const result = envReplace('\\${a} replacement', {a: 'token'});
    expect(result).toEqual('\\${a} replacement');
  });
});