Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

Commit c3928e5

Browse files
committed
start adding tests
1 parent ad94628 commit c3928e5

File tree

10 files changed

+831
-20
lines changed

10 files changed

+831
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ npm-debug.log
44
advisories.json
55
!test/data/advisories.json
66
.drone.sec.yml
7+
coverage.html

commands/check.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const Fs = require('fs');
34
const Path = require('path');
45

56
const API = require('../lib/api');
@@ -60,7 +61,7 @@ exports.handler = Command.wrap('check', (args) => {
6061

6162
let pkg;
6263
try {
63-
pkg = require(Path.join(args.path, 'package.json'));
64+
pkg = JSON.parse(Fs.readFileSync(Path.join(args.path, 'package.json')));
6465
}
6566
catch (err) {
6667
return Promise.reject(new Error(`Unable to load package.json for project: ${Path.basename(args.path)}`));
@@ -69,13 +70,13 @@ exports.handler = Command.wrap('check', (args) => {
6970

7071
let shrinkwrap;
7172
try {
72-
shrinkwrap = require(Path.join(args.path, 'npm-shrinkwrap.json'));
73+
shrinkwrap = JSON.parse(Fs.readFileSync(Path.join(args.path, 'npm-shrinkwrap.json')));
7374
}
7475
catch (err) {}
7576

7677
let packagelock;
7778
try {
78-
packagelock = require(Path.join(args.path, 'package-lock.json'));
79+
packagelock = JSON.parse(Fs.readFileSync(Path.join(args.path, 'package-lock.json')));
7980
}
8081
catch (err) {}
8182

@@ -88,10 +89,10 @@ exports.handler = Command.wrap('check', (args) => {
8889
let advisories;
8990
try {
9091
if (args.advisories) {
91-
advisories = require(Path.resolve(process.cwd(), args.advisories));
92+
advisories = JSON.parse(Fs.readFileSync(Path.resolve(process.cwd(), args.advisories)));
9293
}
9394
else {
94-
advisories = require(Path.join(__dirname, '..', 'advisories.json'));
95+
advisories = JSON.parse(Fs.readFileSync(Path.join(args.path, 'advisories.json')));
9596
}
9697
}
9798
catch (err) {

commands/login.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exports.builder = {
2222

2323
exports.handler = Command.wrap('login', (args) => {
2424

25+
// $lab:coverage:off$
2526
let input = Promise.resolve();
2627
if (process.stdout.isTTY) {
2728
if (!args.email) {
@@ -58,6 +59,7 @@ exports.handler = Command.wrap('login', (args) => {
5859
return Promise.reject(new Error('Email and password required for non-interactive logins'));
5960
}
6061
}
62+
// $lab:coverage:on$
6163

6264
return input.then(() => {
6365

contributing.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ When making a pull request for this repo, please make sure of a few things
77

88
## Rebuilding the shrinkwrap
99

10-
Because of the differences beween npm versions 2 and 3, you will want to use npm 2. A shrinkwrap built under npm 2 will also work under npm 3. A shrinkwrap built under npm 3 will *not* work under npm 2.
11-
12-
The simplest way to build a new shrinkwrap is to start with an empty node_modules. Once you've done that and have made sure you're using npm 2:
13-
1410
```sh
1511
$ npm install
16-
$ npm run shrinkwrap
12+
$ npm shrinkwrap
1713
```
18-
19-
Note that it is `npm run shrinkwrap` not `npm shrinkwrap`. This is because we have a shrinkwrap script that not only runs the shrinkwrap itself but also runs `shrinkydink`, a post-processor that cleans out some unneeded info we don't want.

lib/command.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ exports.wrap = function (name, handler) {
9292

9393
if (name === 'check' &&
9494
result.data.length > 0 &&
95-
args.warnOnly === false) {
95+
!args['warn-only']) {
9696

9797
if (!args.threshold ||
9898
(args.threshold && maxCvss > args.threshold)) {
@@ -124,7 +124,7 @@ exports.wrap = function (name, handler) {
124124

125125
return output.then(() => {
126126

127-
if (args.warnOnly === false) {
127+
if (!args['warn-only']) {
128128
if (err.isServer) {
129129
if (!args['ignore-server-errors']) {
130130
process.exit(2);

0 commit comments

Comments
 (0)