Skip to content

Commit

Permalink
fix: npm run fails silently. closes npm#2959
Browse files Browse the repository at this point in the history
if the missing command is "test", logs a text error, otherwise creates an actual error.
fixed so test always "passes" and doesn't exit
Fix ignore-scripts test
Add unit tests
  • Loading branch information
flipside authored and smikes committed Nov 4, 2014
1 parent e249262 commit 1a08b0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/run-script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module.exports = runScript

var lifecycle = require("./utils/lifecycle.js")
Expand Down Expand Up @@ -124,6 +123,13 @@ function run (pkg, wd, cmd, args, cb) {
"prestart", "start", "poststart"
]
} else {
if (!pkg.scripts[cmd]) {
if (cmd === "test") {
pkg.scripts.test = "echo \"Error: no test specified\"";
} else {
return cb(new Error("missing script: " + cmd));
}
}
cmds = [cmd]
}

Expand Down
1 change: 1 addition & 0 deletions test/tap/ignore-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"preinstall": "exit 123",
"postinstall": "exit 123",
"preuninstall": "exit 123",
"install": "exit 123",
"uninstall": "exit 123",
"postuninstall": "exit 123",
"preupdate": "exit 123",
Expand Down
20 changes: 19 additions & 1 deletion test/tap/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,25 @@ test("npm run-script explicitly call pre script with arg", function (t) {
common.npm(["run-script", "prewith-pre", "--", "an arg"], opts, testOutput.bind(null, t, "an arg"))
})

test("cleanup", function (t) {
test('npm run-script test', function (t) {
common.npm(['run-script', 'test'], opts, function (er, code, stdout, stderr) {
if (er)
throw er
t.notOk(stderr, 'should not generate errors')
t.end()
})
})

test('npm run-script nonexistent-script', function (t) {
common.npm(['run-script', 'nonexistent-script'], opts, function (er, code, stdout, stderr) {
if (er)
throw er
t.ok(stderr, 'should generate errors')
t.end()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
})

0 comments on commit 1a08b0c

Please sign in to comment.