mirror of
https://github.com/zhigang1992/yarn.git
synced 2026-05-11 22:12:59 +08:00
* test IGNORE ME * Update npm-registry to inject env vars into npm configuration the same way npm does * Add type annotation to config object iteration * Update envReplace function * Move env-replace function to a separate util module. Add unit tests * Correct the env-replace tests * Updates per @kittens' comments
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
/* @flow */
|
|
import envReplace from '../../src/util/env-replace';
|
|
import assert from 'assert';
|
|
|
|
describe('environment variable replacement', () => {
|
|
it('will replace a token that exists in the environment', () => {
|
|
let result = envReplace('test ${a} replacement', {a: 'token'});
|
|
assert(result === 'test token replacement', `result: ${result}`);
|
|
|
|
result = envReplace('${a} replacement', {a: 'token'});
|
|
assert(result === 'token replacement', `result: ${result}`);
|
|
|
|
result = envReplace('${a}', {a: 'token'});
|
|
assert(result === 'token', `result: ${result}`);
|
|
});
|
|
|
|
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;
|
|
assert(err.message === 'Failed to replace env in config: ${a}', `error message: ${err.message}`);
|
|
}
|
|
assert(thrown);
|
|
});
|
|
|
|
it('will not replace a token when a the token-replacement mechanism is prefixed a backslash literal', () => {
|
|
const result = envReplace('\\${a} replacement', {a: 'token'});
|
|
assert(result === '\\${a} replacement', `result: ${result}`);
|
|
});
|
|
});
|