2 var resolve = require('path').resolve
4 var osenv = require('osenv')
5 var mkdirp = require('mkdirp')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
9 var common = require('../common-tap.js')
11 var pkg = resolve(__dirname, 'graceful-restart')
32 var pjGraceless = JSON.stringify({
36 'prestop': 'echo prestop',
38 'poststop': 'echo poststop',
39 'prerestart': 'echo prerestart',
40 'postrestart': 'echo postrestart',
41 'prestart': 'echo prestart',
42 'start': 'echo start',
43 'poststart': 'echo poststart'
47 var pjGraceful = JSON.stringify({
51 'prestop': 'echo prestop',
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'
63 test('setup', function (t) {
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')
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')
88 test('clean', function (t) {
93 function bootstrap () {
98 process.chdir(osenv.tmpdir())
102 function createChild (args, cb) {
104 HOME: process.env.HOME,
105 Path: process.env.PATH,
106 PATH: process.env.PATH,
107 'npm_config_loglevel': 'silent'
110 if (process.platform === 'win32')
111 env.npm_config_cache = '%APPDATA%\\npm-cache'
113 return common.npm(args, {
115 stdio: ['ignore', 'pipe', 'ignore'],