]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/graceful-restart.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / graceful-restart.js
1 var fs = require('fs')
2 var resolve = require('path').resolve
3
4 var osenv = require('osenv')
5 var mkdirp = require('mkdirp')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8
9 var common = require('../common-tap.js')
10
11 var pkg = resolve(__dirname, 'graceful-restart')
12
13 var outGraceless = [
14   'prerestart',
15   'prestop',
16   'stop',
17   'poststop',
18   'prestart',
19   'start',
20   'poststart',
21   'postrestart',
22   ''
23 ].join('\n')
24
25 var outGraceful = [
26   'prerestart',
27   'restart',
28   'postrestart',
29   ''
30 ].join('\n')
31
32 var pjGraceless = JSON.stringify({
33   name: 'graceless',
34   version: '1.2.3',
35   scripts: {
36     'prestop': 'echo prestop',
37     'stop': 'echo stop',
38     'poststop': 'echo poststop',
39     'prerestart': 'echo prerestart',
40     'postrestart': 'echo postrestart',
41     'prestart': 'echo prestart',
42     'start': 'echo start',
43     'poststart': 'echo poststart'
44   }
45 }, null, 2) + '\n'
46
47 var pjGraceful = JSON.stringify({
48   name: 'graceful',
49   version: '1.2.3',
50   scripts: {
51     'prestop': 'echo prestop',
52     'stop': 'echo stop',
53     'poststop': 'echo poststop',
54     'prerestart': 'echo prerestart',
55     'restart': 'echo restart',
56     'postrestart': 'echo postrestart',
57     'prestart': 'echo prestart',
58     'start': 'echo start',
59     'poststart': 'echo poststart'
60   }
61 }, null, 2) + '\n'
62
63 test('setup', function (t) {
64   bootstrap()
65   t.end()
66 })
67
68 test('graceless restart', function (t) {
69   fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceless)
70   createChild(['run-script', 'restart'], function (err, code, out) {
71     t.ifError(err, 'restart finished successfully')
72     t.equal(code, 0, 'npm run-script exited with code')
73     t.equal(out, outGraceless, 'expected all scripts to run')
74     t.end()
75   })
76 })
77
78 test('graceful restart', function (t) {
79   fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceful)
80   createChild(['run-script', 'restart'], function (err, code, out) {
81     t.ifError(err, 'restart finished successfully')
82     t.equal(code, 0, 'npm run-script exited with code')
83     t.equal(out, outGraceful, 'expected only *restart scripts to run')
84     t.end()
85   })
86 })
87
88 test('clean', function (t) {
89   cleanup()
90   t.end()
91 })
92
93 function bootstrap () {
94   mkdirp.sync(pkg)
95 }
96
97 function cleanup () {
98   process.chdir(osenv.tmpdir())
99   rimraf.sync(pkg)
100 }
101
102 function createChild (args, cb) {
103   var env = {
104     HOME: process.env.HOME,
105     Path: process.env.PATH,
106     PATH: process.env.PATH,
107     'npm_config_loglevel': 'silent'
108   }
109
110   if (process.platform === 'win32')
111     env.npm_config_cache = '%APPDATA%\\npm-cache'
112
113   return common.npm(args, {
114     cwd: pkg,
115     stdio: ['ignore', 'pipe', 'ignore'],
116     env: env
117   }, cb)
118 }