env-cmd/test/expand-envs.spec.ts
2025-08-06 00:26:33 -08:00

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')
}
})
})