npm: Upgrade to 1.3.19
[platform/upstream/nodejs.git] / deps / npm / test / tap / ignore-scripts.js
1 var test = require("tap").test
2 var npm = require.resolve("../../bin/npm-cli.js")
3
4 var spawn = require("child_process").spawn
5 var node = process.execPath
6
7 // ignore-scripts/package.json has scripts that always exit with non-zero error
8 // codes. The "install" script is omitted so that npm tries to run node-gyp,
9 // which should also fail.
10 var pkg = __dirname + "/ignore-scripts"
11
12 test("ignore-scripts: install using the option", function(t) {
13   createChild([npm, "install", "--ignore-scripts"]).on("close", function(code) {
14     t.equal(code, 0)
15     t.end()
16   })
17 })
18
19 test("ignore-scripts: install NOT using the option", function(t) {
20   createChild([npm, "install"]).on("close", function(code) {
21     t.notEqual(code, 0)
22     t.end()
23   })
24 })
25
26 var scripts = [
27   "prepublish", "publish", "postpublish",
28   "preinstall", "install", "postinstall",
29   "preuninstall", "uninstall", "postuninstall",
30   "preupdate", "update", "postupdate",
31   "pretest", "test", "posttest",
32   "prestop", "stop", "poststop",
33   "prestart", "start", "poststart",
34   "prerestart", "restart", "postrestart"
35 ]
36
37 scripts.forEach(function(script) {
38   test("ignore-scripts: run-script"+script+" using the option", function(t) {
39     createChild([npm, "--ignore-scripts", "run-script", script])
40       .on("close", function(code) {
41         t.equal(code, 0)
42         t.end()
43       })
44   })
45 })
46
47 scripts.forEach(function(script) {
48   test("ignore-scripts: run-script "+script+" NOT using the option", function(t) {
49     createChild([npm, "run-script", script]).on("close", function(code) {
50       t.notEqual(code, 0)
51       t.end()
52     })
53   })
54 })
55
56 function createChild (args) {
57   var env = {
58     HOME: process.env.HOME,
59     Path: process.env.PATH,
60     PATH: process.env.PATH
61   }
62
63   if (process.platform === "win32")
64     env.npm_config_cache = "%APPDATA%\\npm-cache"
65
66   return spawn(node, args, {
67     cwd: pkg,
68     stdio: "inherit",
69     env: env
70   })
71 }