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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
// ignore-scripts/package.json has scripts that always exit with non-zero error
// codes.
var pkg = path.resolve(__dirname, 'ignore-scripts')
var gypfile = 'bad_binding_file\n'
var json = {
author: 'Milton the Aussie',
name: 'ignore-scripts',
version: '0.0.0',
scripts: {
prepublish: 'exit 123',
publish: 'exit 123',
postpublish: 'exit 123',
preinstall: 'exit 123',
install: 'exit 123',
postinstall: 'exit 123',
preuninstall: 'exit 123',
uninstall: 'exit 123',
postuninstall: 'exit 123',
pretest: 'exit 123',
test: 'exit 123',
posttest: 'exit 123',
prestop: 'exit 123',
stop: 'exit 123',
poststop: 'exit 123',
prestart: 'exit 123',
start: 'exit 123',
poststart: 'exit 123',
prerestart: 'exit 123',
restart: 'exit 123',
postrestart: 'exit 123',
preversion: 'exit 123',
version: 'exit 123',
postversion: 'exit 123',
preshrinkwrap: 'exit 123',
shrinkwrap: 'exit 123',
postshrinkwrap: 'exit 123'
}
}
test('setup', function (t) {
setup()
t.end()
})
test('ignore-scripts: install using the option', function (t) {
createChild(['install', '--ignore-scripts'], function (err, code) {
t.ifError(err, 'install with scripts ignored finished successfully')
t.equal(code, 0, 'npm install exited with code')
t.end()
})
})
test('ignore-scripts: install NOT using the option', function (t) {
createChild(['install'], function (err, code) {
t.ifError(err, 'install with scripts successful')
t.notEqual(code, 0, 'npm install exited with code')
t.end()
})
})
var scripts = [
'prepublish', 'publish', 'postpublish',
'preinstall', 'install', 'postinstall',
'preuninstall', 'uninstall', 'postuninstall',
'pretest', 'test', 'posttest',
'prestop', 'stop', 'poststop',
'prestart', 'start', 'poststart',
'prerestart', 'restart', 'postrestart',
'preversion', 'version', 'postversion',
'preshrinkwrap', 'shrinkwrap', 'postshrinkwrap'
]
scripts.forEach(function (script) {
test('ignore-scripts: run-script ' + script + ' using the option', function (t) {
createChild(['--ignore-scripts', 'run-script', script], function (err, code, stdout, stderr) {
t.ifError(err, 'run-script ' + script + ' with ignore-scripts successful')
t.equal(code, 0, 'npm run-script exited with code')
t.end()
})
})
})
scripts.forEach(function (script) {
test('ignore-scripts: run-script ' + script + ' NOT using the option', function (t) {
createChild(['run-script', script], function (err, code) {
t.ifError(err, 'run-script ' + script + ' finished successfully')
t.notEqual(code, 0, 'npm run-script exited with code')
t.end()
})
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
rimraf.sync(pkg)
}
function setup () {
cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(path.join(pkg, 'binding.gyp'), gypfile)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
}
function createChild (args, cb) {
return common.npm(
args.concat(['--loglevel', 'silent']),
{ cwd: pkg },
cb
)
}
|