mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
fix: typo update in test & ts lint update in ts
This commit is contained in:
parent
ec18721023
commit
9da35b5277
@ -6,7 +6,7 @@ const SIGNALS_TO_HANDLE: NodeJS.Signals[] = [
|
|||||||
|
|
||||||
export class TermSignals {
|
export class TermSignals {
|
||||||
private readonly terminateSpawnedProcessFuncHandlers: { [key: string]: any } = {}
|
private readonly terminateSpawnedProcessFuncHandlers: { [key: string]: any } = {}
|
||||||
private readonly verbose: boolean = false;
|
private readonly verbose: boolean = false
|
||||||
public _exitCalled = false
|
public _exitCalled = false
|
||||||
|
|
||||||
constructor (options: { verbose?: boolean } = {}) {
|
constructor (options: { verbose?: boolean } = {}) {
|
||||||
|
|||||||
@ -91,7 +91,7 @@ describe('EnvCmd', (): void => {
|
|||||||
assert.equal(spawnStub.callCount, 1)
|
assert.equal(spawnStub.callCount, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should should override existing env vars if noOverride option is false/missing',
|
it('should override existing env vars if noOverride option is false/missing',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
process.env.BOB = 'cool'
|
process.env.BOB = 'cool'
|
||||||
getEnvVarsStub.returns({ BOB: 'test' })
|
getEnvVarsStub.returns({ BOB: 'test' })
|
||||||
@ -113,7 +113,7 @@ describe('EnvCmd', (): void => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
it('should should not override existing env vars if noOverride option is true',
|
it('should not override existing env vars if noOverride option is true',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
process.env.BOB = 'cool'
|
process.env.BOB = 'cool'
|
||||||
getEnvVarsStub.returns({ BOB: 'test' })
|
getEnvVarsStub.returns({ BOB: 'test' })
|
||||||
@ -138,7 +138,7 @@ describe('EnvCmd', (): void => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
it('should should spawn process with shell option if useShell option is true',
|
it('should spawn process with shell option if useShell option is true',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
process.env.BOB = 'cool'
|
process.env.BOB = 'cool'
|
||||||
getEnvVarsStub.returns({ BOB: 'test' })
|
getEnvVarsStub.returns({ BOB: 'test' })
|
||||||
@ -163,7 +163,7 @@ describe('EnvCmd', (): void => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
it('should should spawn process with command and args expanded if expandEnvs option is true',
|
it('should spawn process with command and args expanded if expandEnvs option is true',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
getEnvVarsStub.returns({ PING: 'PONG', CMD: 'node' })
|
getEnvVarsStub.returns({ PING: 'PONG', CMD: 'node' })
|
||||||
await envCmdLib.EnvCmd({
|
await envCmdLib.EnvCmd({
|
||||||
|
|||||||
@ -28,11 +28,11 @@ describe('getEnvVars', (): void => {
|
|||||||
|
|
||||||
it('should parse the json .rc file from the default path with the given environment',
|
it('should parse the json .rc file from the default path with the given environment',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
getRCFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getRCFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars({ rc: { environments: ['production'] } })
|
const envs = await getEnvVars({ rc: { environments: ['production'] } })
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getRCFileVarsStub.callCount, 1)
|
assert.equal(getRCFileVarsStub.callCount, 1)
|
||||||
assert.lengthOf(getRCFileVarsStub.args[0][0].environments, 1)
|
assert.lengthOf(getRCFileVarsStub.args[0][0].environments, 1)
|
||||||
assert.equal(getRCFileVarsStub.args[0][0].environments[0], 'production')
|
assert.equal(getRCFileVarsStub.args[0][0].environments[0], 'production')
|
||||||
@ -43,7 +43,7 @@ describe('getEnvVars', (): void => {
|
|||||||
it('should print path of custom .rc file and environments to info for verbose',
|
it('should print path of custom .rc file and environments to info for verbose',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
logInfoStub = sinon.stub(console, 'info')
|
logInfoStub = sinon.stub(console, 'info')
|
||||||
getRCFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getRCFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
await getEnvVars({ rc: { environments: ['production'] }, verbose: true })
|
await getEnvVars({ rc: { environments: ['production'] }, verbose: true })
|
||||||
assert.equal(logInfoStub.callCount, 1)
|
assert.equal(logInfoStub.callCount, 1)
|
||||||
}
|
}
|
||||||
@ -53,11 +53,11 @@ describe('getEnvVars', (): void => {
|
|||||||
const pathError = new Error()
|
const pathError = new Error()
|
||||||
pathError.name = 'PathError'
|
pathError.name = 'PathError'
|
||||||
getRCFileVarsStub.rejects(pathError)
|
getRCFileVarsStub.rejects(pathError)
|
||||||
getRCFileVarsStub.onThirdCall().returns({ THANKS: 'FORALLTHEFISH' })
|
getRCFileVarsStub.onThirdCall().returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars({ rc: { environments: ['production'] } })
|
const envs = await getEnvVars({ rc: { environments: ['production'] } })
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getRCFileVarsStub.callCount, 3)
|
assert.equal(getRCFileVarsStub.callCount, 3)
|
||||||
assert.lengthOf(getRCFileVarsStub.args[2][0].environments, 1)
|
assert.lengthOf(getRCFileVarsStub.args[2][0].environments, 1)
|
||||||
assert.equal(getRCFileVarsStub.args[2][0].environments[0], 'production')
|
assert.equal(getRCFileVarsStub.args[2][0].environments[0], 'production')
|
||||||
@ -118,13 +118,13 @@ describe('getEnvVars', (): void => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should find .rc file at custom path path', async (): Promise<void> => {
|
it('should find .rc file at custom path path', async (): Promise<void> => {
|
||||||
getRCFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getRCFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars({
|
const envs = await getEnvVars({
|
||||||
rc: { environments: ['production'], filePath: '../.custom-rc' }
|
rc: { environments: ['production'], filePath: '../.custom-rc' }
|
||||||
})
|
})
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getRCFileVarsStub.callCount, 1)
|
assert.equal(getRCFileVarsStub.callCount, 1)
|
||||||
assert.lengthOf(getRCFileVarsStub.args[0][0].environments, 1)
|
assert.lengthOf(getRCFileVarsStub.args[0][0].environments, 1)
|
||||||
assert.equal(getRCFileVarsStub.args[0][0].environments[0], 'production')
|
assert.equal(getRCFileVarsStub.args[0][0].environments[0], 'production')
|
||||||
@ -133,7 +133,7 @@ describe('getEnvVars', (): void => {
|
|||||||
|
|
||||||
it('should print custom .rc file path to info for verbose', async (): Promise<void> => {
|
it('should print custom .rc file path to info for verbose', async (): Promise<void> => {
|
||||||
logInfoStub = sinon.stub(console, 'info')
|
logInfoStub = sinon.stub(console, 'info')
|
||||||
getRCFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getRCFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
await getEnvVars({
|
await getEnvVars({
|
||||||
rc: { environments: ['production'], filePath: '../.custom-rc' },
|
rc: { environments: ['production'], filePath: '../.custom-rc' },
|
||||||
verbose: true
|
verbose: true
|
||||||
@ -206,18 +206,18 @@ describe('getEnvVars', (): void => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
it('should parse the env file from a custom path', async (): Promise<void> => {
|
it('should parse the env file from a custom path', async (): Promise<void> => {
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars({ envFile: { filePath: '../.env-file' } })
|
const envs = await getEnvVars({ envFile: { filePath: '../.env-file' } })
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getEnvFileVarsStub.callCount, 1)
|
assert.equal(getEnvFileVarsStub.callCount, 1)
|
||||||
assert.equal(getEnvFileVarsStub.args[0][0], '../.env-file')
|
assert.equal(getEnvFileVarsStub.args[0][0], '../.env-file')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should print path of .env file to info for verbose', async (): Promise<void> => {
|
it('should print path of .env file to info for verbose', async (): Promise<void> => {
|
||||||
logInfoStub = sinon.stub(console, 'info')
|
logInfoStub = sinon.stub(console, 'info')
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
await getEnvVars({ envFile: { filePath: '../.env-file' }, verbose: true })
|
await getEnvVars({ envFile: { filePath: '../.env-file' }, verbose: true })
|
||||||
assert.equal(logInfoStub.callCount, 1)
|
assert.equal(logInfoStub.callCount, 1)
|
||||||
})
|
})
|
||||||
@ -249,11 +249,11 @@ describe('getEnvVars', (): void => {
|
|||||||
'path not found and fallback option provided',
|
'path not found and fallback option provided',
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
getEnvFileVarsStub.onFirstCall().rejects('File not found.')
|
getEnvFileVarsStub.onFirstCall().rejects('File not found.')
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars({ envFile: { filePath: '../.env-file', fallback: true } })
|
const envs = await getEnvVars({ envFile: { filePath: '../.env-file', fallback: true } })
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getEnvFileVarsStub.callCount, 2)
|
assert.equal(getEnvFileVarsStub.callCount, 2)
|
||||||
assert.equal(getEnvFileVarsStub.args[1][0], './.env')
|
assert.equal(getEnvFileVarsStub.args[1][0], './.env')
|
||||||
}
|
}
|
||||||
@ -265,36 +265,36 @@ describe('getEnvVars', (): void => {
|
|||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
logInfoStub = sinon.stub(console, 'info')
|
logInfoStub = sinon.stub(console, 'info')
|
||||||
getEnvFileVarsStub.onFirstCall().rejects('File not found.')
|
getEnvFileVarsStub.onFirstCall().rejects('File not found.')
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
await getEnvVars({ envFile: { filePath: '../.env-file', fallback: true }, verbose: true })
|
await getEnvVars({ envFile: { filePath: '../.env-file', fallback: true }, verbose: true })
|
||||||
assert.equal(logInfoStub.callCount, 2)
|
assert.equal(logInfoStub.callCount, 2)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
it('should parse the env file from the default path', async (): Promise<void> => {
|
it('should parse the env file from the default path', async (): Promise<void> => {
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars()
|
const envs = await getEnvVars()
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getEnvFileVarsStub.callCount, 1)
|
assert.equal(getEnvFileVarsStub.callCount, 1)
|
||||||
assert.equal(getEnvFileVarsStub.args[0][0], './.env')
|
assert.equal(getEnvFileVarsStub.args[0][0], './.env')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should print path of .env file to info for verbose', async (): Promise<void> => {
|
it('should print path of .env file to info for verbose', async (): Promise<void> => {
|
||||||
logInfoStub = sinon.stub(console, 'info')
|
logInfoStub = sinon.stub(console, 'info')
|
||||||
getEnvFileVarsStub.returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
await getEnvVars({ verbose: true })
|
await getEnvVars({ verbose: true })
|
||||||
assert.equal(logInfoStub.callCount, 1)
|
assert.equal(logInfoStub.callCount, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should search all default env file paths', async (): Promise<void> => {
|
it('should search all default env file paths', async (): Promise<void> => {
|
||||||
getEnvFileVarsStub.throws('Not found.')
|
getEnvFileVarsStub.throws('Not found.')
|
||||||
getEnvFileVarsStub.onThirdCall().returns({ THANKS: 'FORALLTHEFISH' })
|
getEnvFileVarsStub.onThirdCall().returns({ THANKS: 'FOR ALL THE FISH' })
|
||||||
const envs = await getEnvVars()
|
const envs = await getEnvVars()
|
||||||
assert.isOk(envs)
|
assert.isOk(envs)
|
||||||
assert.lengthOf(Object.keys(envs), 1)
|
assert.lengthOf(Object.keys(envs), 1)
|
||||||
assert.equal(envs.THANKS, 'FORALLTHEFISH')
|
assert.equal(envs.THANKS, 'FOR ALL THE FISH')
|
||||||
assert.equal(getEnvFileVarsStub.callCount, 3)
|
assert.equal(getEnvFileVarsStub.callCount, 3)
|
||||||
assert.isTrue(getEnvFileVarsStub.calledWithExactly('./.env.json'))
|
assert.isTrue(getEnvFileVarsStub.calledWithExactly('./.env.json'))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user