]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/ignore-scripts.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / ignore-scripts.js
1 var fs = require('graceful-fs')
2 var path = require('path')
3
4 var mkdirp = require('mkdirp')
5 var rimraf = require('rimraf')
6 var test = require('tap').test
7
8 var common = require('../common-tap')
9
10 // ignore-scripts/package.json has scripts that always exit with non-zero error
11 // codes.
12 var pkg = path.resolve(__dirname, 'ignore-scripts')
13
14 var gypfile = 'bad_binding_file\n'
15 var json = {
16   author: 'Milton the Aussie',
17   name: 'ignore-scripts',
18   version: '0.0.0',
19   scripts: {
20     prepublish: 'exit 123',
21     publish: 'exit 123',
22     postpublish: 'exit 123',
23     preinstall: 'exit 123',
24     install: 'exit 123',
25     postinstall: 'exit 123',
26     preuninstall: 'exit 123',
27     uninstall: 'exit 123',
28     postuninstall: 'exit 123',
29     pretest: 'exit 123',
30     test: 'exit 123',
31     posttest: 'exit 123',
32     prestop: 'exit 123',
33     stop: 'exit 123',
34     poststop: 'exit 123',
35     prestart: 'exit 123',
36     start: 'exit 123',
37     poststart: 'exit 123',
38     prerestart: 'exit 123',
39     restart: 'exit 123',
40     postrestart: 'exit 123',
41     preversion: 'exit 123',
42     version: 'exit 123',
43     postversion: 'exit 123'
44   }
45 }
46
47 test('setup', function (t) {
48   setup()
49   t.end()
50 })
51
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')
56     t.end()
57   })
58 })
59
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')
64     t.end()
65   })
66 })
67
68 var scripts = [
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'
77 ]
78
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')
84       t.end()
85     })
86   })
87 })
88
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')
94       t.end()
95     })
96   })
97 })
98
99 test('cleanup', function (t) {
100   cleanup()
101   t.end()
102 })
103
104 function cleanup () {
105   rimraf.sync(pkg)
106 }
107
108 function setup () {
109   cleanup()
110   mkdirp.sync(pkg)
111   fs.writeFileSync(path.join(pkg, 'binding.gyp'), gypfile)
112   fs.writeFileSync(
113     path.join(pkg, 'package.json'),
114     JSON.stringify(json, null, 2)
115   )
116 }
117
118 function createChild (args, cb) {
119   return common.npm(
120     args.concat(['--loglevel', 'silent']),
121     { cwd: pkg },
122     cb
123   )
124 }