diff options
author | Bryant Williams <b.n.williams@gmail.com> | 2012-08-14 08:37:52 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-02-27 06:40:08 +0300 |
commit | d3df7c7847ac51e8b547e4568bdab5aea84fafc4 (patch) | |
tree | d56142742ac8f9485e182b3f49c570b5b356d4f0 /test | |
parent | 2f6a1df3e1e3e0a3bc4abb69e40f59a64204e7aa (diff) |
run-script: test run-script restart defaults
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/graceful-restart.js | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/test/tap/graceful-restart.js b/test/tap/graceful-restart.js new file mode 100644 index 000000000..bd1f31144 --- /dev/null +++ b/test/tap/graceful-restart.js @@ -0,0 +1,118 @@ +var fs = require('fs') +var resolve = require('path').resolve + +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') + +var pkg = resolve(__dirname, 'graceful-restart') + +test('setup', function (t) { + bootstrap() + t.end() +}) + +test('graceless restart', function (t) { + fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceless) + createChild(['run-script', 'restart'], function (err, code, out) { + t.ifError(err, 'restart finished successfully') + t.equal(code, 0, 'npm run-script exited with code') + t.equal(out, outGraceless, 'expected all scripts to run') + t.end() + }) +}) + +test('graceful restart', function (t) { + fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceful) + createChild(['run-script', 'restart'], function (err, code, out) { + t.ifError(err, 'restart finished successfully') + t.equal(code, 0, 'npm run-script exited with code') + t.equal(out, outGraceful, 'expected only *restart scripts to run') + t.end() + }) +}) + +test('clean', function (t) { + cleanup() + t.end() +}) + +var outGraceless = [ + 'prerestart', + 'prestop', + 'stop', + 'poststop', + 'prestart', + 'start', + 'poststart', + 'postrestart', + '' +].join('\n') + +var outGraceful = [ + 'prerestart', + 'restart', + 'postrestart', + '' +].join('\n') + +var pjGraceless = JSON.stringify({ + name: 'graceless', + version: '1.2.3', + scripts: { + 'prestop': 'echo prestop', + 'stop': 'echo stop', + 'poststop': 'echo poststop', + 'prerestart': 'echo prerestart', + 'postrestart': 'echo postrestart', + 'prestart': 'echo prestart', + 'start': 'echo start', + 'poststart': 'echo poststart' + } +}, null, 2) + '\n' + +var pjGraceful = JSON.stringify({ + name: 'graceful', + version: '1.2.3', + scripts: { + 'prestop': 'echo prestop', + 'stop': 'echo stop', + 'poststop': 'echo poststop', + 'prerestart': 'echo prerestart', + 'restart': 'echo restart', + 'postrestart': 'echo postrestart', + 'prestart': 'echo prestart', + 'start': 'echo start', + 'poststart': 'echo poststart' + } +}, null, 2) + '\n' + +function bootstrap () { + mkdirp.sync(pkg) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} + +function createChild (args, cb) { + var env = { + HOME: process.env.HOME, + Path: process.env.PATH, + PATH: process.env.PATH, + 'npm_config_loglevel': 'silent' + } + + if (process.platform === 'win32') + env.npm_config_cache = '%APPDATA%\\npm-cache' + + return common.npm(args, { + cwd: pkg, + stdio: ['ignore', 'pipe', 'ignore'], + env: env + }, cb) +} |