Catch errors thrown by Audit.run and increase child process buffer size (#67)

* Audit.run does not need to be async

* Set max buffer size for npm audit subprocess to 10MiB
This commit is contained in:
Spencer Small
2020-07-14 02:59:28 -07:00
committed by GitHub
parent 4adc177da9
commit b0bc596f8e
3 changed files with 31 additions and 40 deletions

View File

@@ -55,7 +55,7 @@ describe('run', () => {
expect(audit.foundVulnerability()).toBeFalsy()
})
test('throws an error if error is not null', async () => {
test('throws an error if error is not null', () => {
mocked(child_process).spawnSync.mockImplementation((): any => {
return {
pid: 100,
@@ -69,12 +69,11 @@ describe('run', () => {
})
expect.assertions(1)
const r = audit.run('low')
const e = new Error('Something is wrong')
await expect(r).rejects.toEqual(e)
expect(() => audit.run('low')).toThrowError(e)
})
test('throws an error if status is null', async () => {
test('throws an error if status is null', () => {
mocked(child_process).spawnSync.mockImplementation((): any => {
return {
pid: 100,
@@ -88,12 +87,11 @@ describe('run', () => {
})
expect.assertions(1)
const r = audit.run('low')
const e = new Error('the subprocess terminated due to a signal.')
await expect(r).rejects.toEqual(e)
expect(() => audit.run('low')).toThrowError(e)
})
test('throws an error if stderr is null', async () => {
test('throws an error if stderr is null', () => {
mocked(child_process).spawnSync.mockImplementation((): any => {
return {
pid: 100,
@@ -107,8 +105,7 @@ describe('run', () => {
})
expect.assertions(1)
const r = audit.run('low')
const e = new Error('Something is wrong')
await expect(r).rejects.toEqual(e)
expect(() => audit.run('low')).toThrowError(e)
})
})