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

Commit

Permalink
start adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Oct 3, 2017
1 parent ad94628 commit c3928e5
Show file tree
Hide file tree
Showing 10 changed files with 831 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
advisories.json
!test/data/advisories.json
.drone.sec.yml
coverage.html
11 changes: 6 additions & 5 deletions commands/check.js
@@ -1,5 +1,6 @@
'use strict';

const Fs = require('fs');
const Path = require('path');

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

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

let shrinkwrap;
try {
shrinkwrap = require(Path.join(args.path, 'npm-shrinkwrap.json'));
shrinkwrap = JSON.parse(Fs.readFileSync(Path.join(args.path, 'npm-shrinkwrap.json')));
}
catch (err) {}

let packagelock;
try {
packagelock = require(Path.join(args.path, 'package-lock.json'));
packagelock = JSON.parse(Fs.readFileSync(Path.join(args.path, 'package-lock.json')));
}
catch (err) {}

Expand All @@ -88,10 +89,10 @@ exports.handler = Command.wrap('check', (args) => {
let advisories;
try {
if (args.advisories) {
advisories = require(Path.resolve(process.cwd(), args.advisories));
advisories = JSON.parse(Fs.readFileSync(Path.resolve(process.cwd(), args.advisories)));
}
else {
advisories = require(Path.join(__dirname, '..', 'advisories.json'));
advisories = JSON.parse(Fs.readFileSync(Path.join(args.path, 'advisories.json')));
}
}
catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions commands/login.js
Expand Up @@ -22,6 +22,7 @@ exports.builder = {

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

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

return input.then(() => {

Expand Down
8 changes: 1 addition & 7 deletions contributing.md
Expand Up @@ -7,13 +7,7 @@ When making a pull request for this repo, please make sure of a few things

## Rebuilding the shrinkwrap

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.

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:

```sh
$ npm install
$ npm run shrinkwrap
$ npm shrinkwrap
```

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.
4 changes: 2 additions & 2 deletions lib/command.js
Expand Up @@ -92,7 +92,7 @@ exports.wrap = function (name, handler) {

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

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

return output.then(() => {

if (args.warnOnly === false) {
if (!args['warn-only']) {
if (err.isServer) {
if (!args['ignore-server-errors']) {
process.exit(2);
Expand Down

0 comments on commit c3928e5

Please sign in to comment.