diff options
Diffstat (limited to 'test/tap/startstop.js')
-rw-r--r-- | test/tap/startstop.js | 57 |
1 files changed, 18 insertions, 39 deletions
diff --git a/test/tap/startstop.js b/test/tap/startstop.js index d5a0026ce..a1c0a6544 100644 --- a/test/tap/startstop.js +++ b/test/tap/startstop.js @@ -9,41 +9,16 @@ var common = require('../common-tap') , tmp = pkg + '/tmp' , node = process.execPath , npm = path.resolve(__dirname, '../../cli.js') + , opts = { cwd: pkg } -function run (command, t, parse) { - var c = '' - , e = '' - , node = process.execPath - , child = spawn(node, [npm, command], { - cwd: pkg - }) - - child.stderr.on('data', function (chunk) { - e += chunk - }) - - child.stdout.on('data', function (chunk) { - c += chunk - }) - - child.stdout.on('end', function () { - if (e) { - throw new Error('npm ' + command + ' stderr: ' + e.toString()) - } - if (parse) { - // custom parsing function - c = parse(c) - t.equal(c.actual, c.expected) - t.end() - return - } - - c = c.trim().split('\n') - c = c[c.length - 1] - t.equal(c, command) - t.end() - }) +function testOutput (t, c, e, o) { + if (e) + throw new Error('npm ' + command + ' stderr: ' + e.toString()) + c = c.trim().split('\n') + c = c[c.length - 1] + t.equal(c, o.cmd[1]) + t.end() } function cleanup () { @@ -56,23 +31,27 @@ test('setup', function (t) { mkdirp.sync(pkg + '/cache') mkdirp.sync(pkg + '/tmp') t.end() - }) test('npm start', function (t) { - run('start', t) + common.run([npm, 'start'], t, opts, testOutput) }) test('npm stop', function (t) { - run('stop', t) + common.run([npm, 'stop'], t, opts, testOutput) }) test('npm restart', function (t) { - run ('restart', t, function (output) { - output = output.split('\n').filter(function (val) { + common.run([npm, 'restart'], t, opts, function (t, c, e) { + if (e) + throw new Error('npm ' + command + ' stderr: ' + e.toString()) + + var output = c.split('\n').filter(function (val) { return val.match(/^s/) }) - return {actual: output, expected: output} + + t.same(output.sort(), ['start', 'stop'].sort()) + t.end() }) }) |