aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/ignore-scripts.js
blob: 0115b7571d8955790c05f9bf8506ed6ca5a0ccc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var test = require("tap").test
var npm = require.resolve("../../bin/npm-cli.js")

var spawn = require("child_process").spawn
var node = process.execPath

// ignore-scripts/package.json has scripts that always exit with non-zero error
// codes. The "install" script is omitted so that npm tries to run node-gyp,
// which should also fail.
var pkg = __dirname + "/ignore-scripts"

test("ignore-scripts: install using the option", function(t) {
  createChild([npm, "install", "--ignore-scripts"]).on("close", function(code) {
    t.equal(code, 0)
    t.end()
  })
})

test("ignore-scripts: install NOT using the option", function(t) {
  createChild([npm, "install"]).on("close", function(code) {
    t.notEqual(code, 0)
    t.end()
  })
})

var scripts = [
  "prepublish", "publish", "postpublish",
  "preinstall", "install", "postinstall",
  "preuninstall", "uninstall", "postuninstall",
  "preupdate", "update", "postupdate",
  "pretest", "test", "posttest",
  "prestop", "stop", "poststop",
  "prestart", "start", "poststart",
  "prerestart", "restart", "postrestart"
]

scripts.forEach(function(script) {
  test("ignore-scripts: run-script "+script+" using the option", function(t) {
    createChild([npm, "--ignore-scripts", "run-script", script])
      .on("close", function(code) {
        t.equal(code, 0)
        t.end()
      })
  })
})

scripts.forEach(function(script) {
  test("ignore-scripts: run-script "+script+" NOT using the option", function(t) {
    createChild([npm, "run-script", script]).on("close", function(code) {
      t.notEqual(code, 0)
      t.end()
    })
  })
})

function createChild (args) {
  var env = {
    HOME: process.env.HOME,
    Path: process.env.PATH,
    PATH: process.env.PATH,
    npm_config_loglevel: "silent"
  }

  if (process.platform === "win32")
    env.npm_config_cache = "%APPDATA%\\npm-cache"

  return spawn(node, args, {
    cwd: pkg,
    stdio: "inherit",
    env: env
  })
}