add unit test and cleanup (#28)
* remove unnessary import * use mock for child_process.spawnSync() * document useful resources * use v1.1.0 for daily scan
This commit is contained in:
@@ -1,15 +1,57 @@
|
||||
import * as child_process from 'child_process'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import {mocked} from 'ts-jest/utils'
|
||||
import {Audit} from '../src/audit'
|
||||
|
||||
jest.mock('child_process')
|
||||
|
||||
const audit = new Audit()
|
||||
|
||||
describe('npm audit', () => {
|
||||
describe('run', () => {
|
||||
beforeEach(() => {
|
||||
mocked(child_process).spawnSync.mockClear()
|
||||
})
|
||||
|
||||
test('finds vulnerabilities', () => {
|
||||
audit.status = 1
|
||||
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()
|
||||
expect(audit.foundVulnerability()).toBeTruthy()
|
||||
})
|
||||
|
||||
test('does not find vulnerabilities', () => {
|
||||
audit.status = 0
|
||||
mocked(child_process).spawnSync.mockImplementation((): any => {
|
||||
const stdout = fs.readFileSync(
|
||||
path.join(__dirname, 'testdata/audit/success.txt')
|
||||
)
|
||||
|
||||
return {
|
||||
pid: 100,
|
||||
output: [stdout],
|
||||
stdout,
|
||||
stderr: '',
|
||||
status: 0,
|
||||
signal: null,
|
||||
error: null
|
||||
}
|
||||
})
|
||||
|
||||
audit.run()
|
||||
expect(audit.foundVulnerability()).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import {mocked} from 'ts-jest/utils'
|
||||
import axios, {AxiosResponse} from 'axios'
|
||||
import {Audit} from '../src/audit'
|
||||
import {run} from '../src/main'
|
||||
import * as pr from '../src/pr'
|
||||
|
||||
Reference in New Issue
Block a user