Skip to content

Commit

Permalink
polish argument passing, add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
naugtur committed Jan 23, 2020
1 parent dfe1bf6 commit d985d0e
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ The decisions you make are stored in `audit-resolve.json` to keep track of it in
### Arguments

```
--ignoreLow automatically resolve issue to ignored if severity of all vulnerabilities in that dependency is low
--yarn switched to yarn package manager as the command to support
--migrate forces migration to a new file and format even if no modifications are made to decisions
```

All other arguments are passed down to the npm/yarn audit call

### Running in CI

One of the problems this solves is running audit as part of your build pipeline.
Expand All @@ -53,6 +54,8 @@ For JSON output (similar to `npm audit --json`), run
check-audit --json
```

All other arguments are passed down to the npm/yarn audit call

## Features

Want to give it a go? Download this repo and run `npm run testdrive`
Expand Down
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
"yargs-parser": "^13.1.1",
"yargs-unparser": "^1.5.0"
},
"devDependencies": {}
"devDependencies": {
"pre-commit": "^1.2.2"
}
}
5 changes: 3 additions & 2 deletions src/pkgmanagers/npm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const unparse = require('../unparse');
const unparse = require('../unparse')
const skipArgs = require('../skipArgs')

function getCommand(action) {
// Derived from npm-audit-report
Expand All @@ -14,7 +15,7 @@ function getCommand(action) {
module.exports = {
version: 1,
getAudit({ promiseCommand, argv, shellOptions }) {
const unparsed = unparse(argv, ['json']);
const unparsed = unparse(argv, skipArgs)

return promiseCommand(`npm audit --json ${unparsed}`, shellOptions)
.then(output => {
Expand Down
5 changes: 4 additions & 1 deletion src/pkgmanagers/yarn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const packageJSON = require(require('path').resolve('./package.json'))
const jsonlines = require('jsonlines')
const unparse = require('../unparse')
const skipArgs = require('../skipArgs')


function aggregateActions(audit, entry) {
const modulename = entry.data.advisory.module_name
Expand Down Expand Up @@ -33,7 +36,7 @@ module.exports = {
version: 1,
getAudit({ promiseCommand, argv, shellOptions }) {
console.error('WARNING: yarn support is experimental')
const unparsed = unparse(argv, ['json']);
const unparsed = unparse(argv, skipArgs)

return promiseCommand(`yarn audit --json ${unparsed}`, shellOptions)
.then(output => {
Expand Down
1 change: 1 addition & 0 deletions src/skipArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = ['json', 'migrate', 'yarn', 'mock', 'fix']
18 changes: 18 additions & 0 deletions test/e2e/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,22 @@ if [ $EXITCODE -ne 0 ]; then
exit 1
fi


echo 'runs check on npm with extra args'
RESULT1=`node check.js --production --XbookmarkX --migrate | grep XbookmarkX | wc -l`
RESULT2=`node check.js --production --XbookmarkX --migrate | grep XbookmarkX | grep migrate | wc -l`

if [ $RESULT1 -ne 1 ] || [ $RESULT2 -ne 0 ]; then
echo "FAILED, expected passing arguments down to work, expected filtering out arguments to work"
exit 1
fi

echo 'runs check on yarn with extra args'
RESULT1=`node check.js --yarn --production --XbookmarkX --migrate | grep XbookmarkX | wc -l`
RESULT2=`node check.js --yarn --production --XbookmarkX --migrate | grep XbookmarkX | grep migrate | wc -l`

if [ $RESULT1 -ne 1 ] || [ $RESULT2 -ne 0 ]; then
echo "FAILED, expected passing arguments down to work, expected filtering out arguments to work"
exit 1
fi
echo '- Runs ----------------------- OK'

0 comments on commit d985d0e

Please sign in to comment.