forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(obligatory 'yo dawg' reference)
- Loading branch information
Showing
2 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
/* eslint-disable standard/no-callback-literal */ | ||
module.exports = test | ||
|
||
const testCmd = require('./utils/lifecycle-cmd.js')('test') | ||
const { completion, usage } = testCmd | ||
const cmd = (args, cb) => testCmd(args, er => { | ||
if (er && er.code === 'ELIFECYCLE') { | ||
cb('Test failed. See above for more details.') | ||
} else { | ||
cb(er) | ||
} | ||
}) | ||
|
||
test.usage = testCmd.usage | ||
|
||
function test (args, cb) { | ||
testCmd(args, function (er) { | ||
if (!er) return cb() | ||
if (er.code === 'ELIFECYCLE') { | ||
return cb('Test failed. See above for more details.') | ||
} | ||
return cb(er) | ||
}) | ||
} | ||
module.exports = Object.assign(cmd, { completion, usage }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const t = require('tap') | ||
const requireInject = require('require-inject') | ||
let RUN_ARGS = null | ||
const npmock = { | ||
commands: { | ||
run: (args, cb) => { | ||
RUN_ARGS = args | ||
cb() | ||
} | ||
} | ||
} | ||
const test = requireInject('../../lib/test.js', { | ||
'../../lib/npm.js': npmock | ||
}) | ||
|
||
t.test('run a test', t => { | ||
test([], (er) => { | ||
t.strictSame(RUN_ARGS, ['test'], 'added "test" to the args') | ||
}) | ||
test(['hello', 'world'], (er) => { | ||
t.strictSame(RUN_ARGS, ['test', 'hello', 'world'], 'added positional args') | ||
}) | ||
|
||
const lcErr = Object.assign(new Error('should not see this'), { | ||
code: 'ELIFECYCLE' | ||
}) | ||
const otherErr = new Error('should see this') | ||
|
||
npmock.commands.run = (args, cb) => cb(lcErr) | ||
test([], (er) => { | ||
t.equal(er, 'Test failed. See above for more details.') | ||
}) | ||
|
||
npmock.commands.run = (args, cb) => cb(otherErr) | ||
test([], (er) => { | ||
t.match(er, { message: 'should see this' }) | ||
}) | ||
|
||
t.end() | ||
}) |