Skip to content

Commit

Permalink
test: fix test for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhleung committed Aug 2, 2018
1 parent 59d2146 commit e153ae7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
14 changes: 10 additions & 4 deletions fixtures/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"name": "sandbox",
"private": true,
"dependencies": {
"enzyme": "3.0.0",
"enzyme-adapter-react-16": "1.1.1",
"react": "16.0.0",
"react-dom": "16.0.0"
"angular": "^1.7.2",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.9.1",
"react": "^16.0.0",
"react-dom": "^16.0.0"
}
}
12 changes: 12 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ if (program.args.length === 0) {
process.exit(9);
}

// Make sure we're installing no more than one package
if (program.args.length > 1) {
console.log(
`${
C.errorText
} Please specify ONE package at a time to install with peerDeps.`
);
// An exit code of "9" indicates an invalid argument
// See https://nodejs.org/api/process.html#process_exit_codes
process.exit(9);
}

// The first argument after the options is the name of the package
const packageString = program.args[0];

Expand Down
23 changes: 17 additions & 6 deletions src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import test from "tape";
function spawnCli(extraArgs) {
return spawn(
"node",
["--require", "babel-register", "cli.js"].concat(extraArgs),
["--require", "babel-register", path.join(__dirname, "cli.js")].concat(
extraArgs
),
{ cwd: path.join(__dirname, "..", "fixtures", "sandbox") }
);
}
Expand Down Expand Up @@ -48,7 +50,11 @@ test("errors when more than one package is provided", t => {
// We should be able to do t.equal(code, 1), but earlier Node versions
// handle uncaught exceptions differently so we can't (0.10 returns 8,
// 0.12 returns 9).
t.notEqual(code, 0, `errored, exit code was ${code}`);
t.notEqual(
code,
0,
`errored, exit code was ${code}.`
);
t.end();
});
});
Expand Down Expand Up @@ -87,10 +93,15 @@ test("adds an explicit `--no-save` when using `--silent` with NPM", t => {
});

test("installs packages correctly even if package name ends with '-0'", t => {
const cli = spawnCli("enzyme-adapter-react-16@1.1.1");
cli.on("exit", code => {
t.equal(code, 0, `errored, exit code was ${code}`);
t.end();
const cli = spawnCli(["enzyme-adapter-react-16@1.1.1"]);
cli.on("exit", code => {
t.equal(
code,
0,
`errored, exit code was ${code}.`
);
t.end();
});
});
});

Expand Down

0 comments on commit e153ae7

Please sign in to comment.