mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
36 lines
961 B
TypeScript
36 lines
961 B
TypeScript
/* eslint @typescript-eslint/no-non-null-assertion: 0 */
|
|
import { assert } from 'chai'
|
|
import { expandEnvs } from '../src/expand-envs.js'
|
|
|
|
describe('expandEnvs', (): void => {
|
|
const envs = {
|
|
notvar: 'this is not used',
|
|
dollar: 'money',
|
|
PING: 'PONG',
|
|
IP1: '127.0.0.1',
|
|
THANKSFORALLTHEFISH: '42',
|
|
BRINGATOWEL: 'true',
|
|
}
|
|
|
|
const args = [
|
|
'notvar', '$dollar', '\\$notvar', '-4',
|
|
'$PING', '$IP1', '\\$IP1', '$NONEXIST',
|
|
'${PING}', '${NONEXIST}', '\\${PING}',
|
|
'$PING}', '${PING2'
|
|
]
|
|
const argsExpanded = [
|
|
'notvar', 'money', '\\$notvar', '-4',
|
|
'PONG', '127.0.0.1', '\\$IP1', '$NONEXIST',
|
|
'PONG', '${NONEXIST}', '\\${PING}',
|
|
'PONG}', '${PING2'
|
|
]
|
|
|
|
it('should replace environment variables in args', (): void => {
|
|
const res = args.map(arg => expandEnvs(arg, envs))
|
|
assert.sameOrderedMembers(res, argsExpanded)
|
|
for (const arg of args) {
|
|
assert.typeOf(arg, 'string')
|
|
}
|
|
})
|
|
})
|