feat: add the ability to run with '--production' (#75)
* feat: add the ability to run with '--production' Adding the config options to run npm audit with the --production flag. Contributes to: #74 Signed-off-by: Stelios Gkiokas <s_giokas@hotmail.com> * fix: add tests Adding the relevant tests for the new production flag. Contributes to: #74 Signed-off-by: Stelios Gkiokas <s_giokas@hotmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@ describe('run', () => {
|
||||
mocked(child_process).spawnSync.mockClear()
|
||||
})
|
||||
|
||||
test('finds vulnerabilities', () => {
|
||||
test('finds vulnerabilities with default values', () => {
|
||||
mocked(child_process).spawnSync.mockImplementation((): any => {
|
||||
const stdout = fs.readFileSync(
|
||||
path.join(__dirname, 'testdata/audit/error.txt')
|
||||
@@ -30,7 +30,28 @@ describe('run', () => {
|
||||
}
|
||||
})
|
||||
|
||||
audit.run('low')
|
||||
audit.run('low', 'false')
|
||||
expect(audit.foundVulnerability()).toBeTruthy()
|
||||
})
|
||||
|
||||
test('finds vulnerabilities with production flag enabled', () => {
|
||||
mocked(child_process).spawnSync.mockImplementation((): any => {
|
||||
const stdout = fs.readFileSync(
|
||||
path.join(__dirname, 'testdata/audit/error.txt')
|
||||
)
|
||||
|
||||
return {
|
||||
pid: 100,
|
||||
output: [stdout],
|
||||
stdout,
|
||||
stderr: '',
|
||||
status: 1,
|
||||
signal: null,
|
||||
error: null
|
||||
}
|
||||
})
|
||||
|
||||
audit.run('low', 'true')
|
||||
expect(audit.foundVulnerability()).toBeTruthy()
|
||||
})
|
||||
|
||||
@@ -51,7 +72,7 @@ describe('run', () => {
|
||||
}
|
||||
})
|
||||
|
||||
audit.run('low')
|
||||
audit.run('low', 'false')
|
||||
expect(audit.foundVulnerability()).toBeFalsy()
|
||||
})
|
||||
|
||||
@@ -70,7 +91,7 @@ describe('run', () => {
|
||||
|
||||
expect.assertions(1)
|
||||
const e = new Error('Something is wrong')
|
||||
expect(() => audit.run('low')).toThrowError(e)
|
||||
expect(() => audit.run('low', 'false')).toThrowError(e)
|
||||
})
|
||||
|
||||
test('throws an error if status is null', () => {
|
||||
@@ -88,7 +109,7 @@ describe('run', () => {
|
||||
|
||||
expect.assertions(1)
|
||||
const e = new Error('the subprocess terminated due to a signal.')
|
||||
expect(() => audit.run('low')).toThrowError(e)
|
||||
expect(() => audit.run('low', 'false')).toThrowError(e)
|
||||
})
|
||||
|
||||
test('throws an error if stderr is null', () => {
|
||||
@@ -106,6 +127,6 @@ describe('run', () => {
|
||||
|
||||
expect.assertions(1)
|
||||
const e = new Error('Something is wrong')
|
||||
expect(() => audit.run('low')).toThrowError(e)
|
||||
expect(() => audit.run('low', 'false')).toThrowError(e)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user