1 var common = require('../common-tap')
2 , test = require('tap').test
3 , path = require('path')
4 , spawn = require('child_process').spawn
5 , rimraf = require('rimraf')
6 , mkdirp = require('mkdirp')
7 , pkg = __dirname + '/startstop'
8 , cache = pkg + '/cache'
10 , node = process.execPath
11 , npm = path.resolve(__dirname, '../../cli.js')
13 function run (command, t, parse) {
15 , node = process.execPath
16 , child = spawn(node, [npm, command], {
20 child.stderr.on('data', function (chunk) {
21 throw new Error('npm ' + command + ' stderr: ' + chunk.toString())
24 child.stdout.on('data', function (chunk) {
28 child.stdout.on('end', function () {
30 // custom parsing function
32 t.equal(c.actual, c.expected)
37 c = c.trim().split('\n')
46 rimraf.sync(pkg + '/cache')
47 rimraf.sync(pkg + '/tmp')
50 test('setup', function (t) {
52 mkdirp.sync(pkg + '/cache')
53 mkdirp.sync(pkg + '/tmp')
58 test('npm start', function (t) {
62 test('npm stop', function (t) {
66 test('npm restart', function (t) {
67 run ('restart', t, function (output) {
68 output = output.split('\n').filter(function (val) {
69 return val.match(/^s/)
71 return {actual: output, expected: output}
75 test('cleanup', function (t) {