1 var fs = require('graceful-fs')
2 var path = require('path')
4 var mkdirp = require('mkdirp')
5 var rimraf = require('rimraf')
6 var test = require('tap').test
8 var common = require('../common-tap')
10 // ignore-scripts/package.json has scripts that always exit with non-zero error
12 var pkg = path.resolve(__dirname, 'ignore-scripts')
14 var gypfile = 'bad_binding_file\n'
16 author: 'Milton the Aussie',
17 name: 'ignore-scripts',
20 prepublish: 'exit 123',
22 postpublish: 'exit 123',
23 preinstall: 'exit 123',
25 postinstall: 'exit 123',
26 preuninstall: 'exit 123',
27 uninstall: 'exit 123',
28 postuninstall: 'exit 123',
37 poststart: 'exit 123',
38 prerestart: 'exit 123',
40 postrestart: 'exit 123',
41 preversion: 'exit 123',
43 postversion: 'exit 123'
47 test('setup', function (t) {
52 test('ignore-scripts: install using the option', function (t) {
53 createChild(['install', '--ignore-scripts'], function (err, code) {
54 t.ifError(err, 'install with scripts ignored finished successfully')
55 t.equal(code, 0, 'npm install exited with code')
60 test('ignore-scripts: install NOT using the option', function (t) {
61 createChild(['install'], function (err, code) {
62 t.ifError(err, 'install with scripts successful')
63 t.notEqual(code, 0, 'npm install exited with code')
69 'prepublish', 'publish', 'postpublish',
70 'preinstall', 'install', 'postinstall',
71 'preuninstall', 'uninstall', 'postuninstall',
72 'pretest', 'test', 'posttest',
73 'prestop', 'stop', 'poststop',
74 'prestart', 'start', 'poststart',
75 'prerestart', 'restart', 'postrestart',
76 'preversion', 'version', 'postversion'
79 scripts.forEach(function (script) {
80 test('ignore-scripts: run-script ' + script + ' using the option', function (t) {
81 createChild(['--ignore-scripts', 'run-script', script], function (err, code, stdout, stderr) {
82 t.ifError(err, 'run-script ' + script + ' with ignore-scripts successful')
83 t.equal(code, 0, 'npm run-script exited with code')
89 scripts.forEach(function (script) {
90 test('ignore-scripts: run-script ' + script + ' NOT using the option', function (t) {
91 createChild(['run-script', script], function (err, code) {
92 t.ifError(err, 'run-script ' + script + ' finished successfully')
93 t.notEqual(code, 0, 'npm run-script exited with code')
99 test('cleanup', function (t) {
104 function cleanup () {
111 fs.writeFileSync(path.join(pkg, 'binding.gyp'), gypfile)
113 path.join(pkg, 'package.json'),
114 JSON.stringify(json, null, 2)
118 function createChild (args, cb) {
120 args.concat(['--loglevel', 'silent']),