npm: Upgrade to 1.3.17
[platform/upstream/nodejs.git] / deps / npm / test / tap / startstop.js
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'
9   , tmp = pkg + '/tmp'
10   , node = process.execPath
11   , npm = path.resolve(__dirname, '../../cli.js')
12
13 function run (command, t, parse) {
14   var c = ''
15     , node = process.execPath
16     , child = spawn(node, [npm, command], {
17       cwd: pkg
18     })
19
20     child.stderr.on('data', function (chunk) {
21       throw new Error('npm ' + command + ' stderr: ' + chunk.toString())
22     })
23
24     child.stdout.on('data', function (chunk) {
25       c += chunk
26     })
27
28     child.stdout.on('end', function () {
29       if (parse) {
30         // custom parsing function
31         c = parse(c)
32         t.equal(c.actual, c.expected)
33         t.end()
34         return
35       }
36
37       c = c.trim().split('\n')
38       c = c[c.length - 1]
39       t.equal(c, command)
40       t.end()
41     })
42
43 }
44
45 function cleanup () {
46   rimraf.sync(pkg + '/cache')
47   rimraf.sync(pkg + '/tmp')
48 }
49
50 test('setup', function (t) {
51   cleanup()
52   mkdirp.sync(pkg + '/cache')
53   mkdirp.sync(pkg + '/tmp')
54   t.end()
55
56 })
57
58 test('npm start', function (t) {
59   run('start', t)
60 })
61
62 test('npm stop', function (t) {
63   run('stop', t)
64 })
65
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/)
70     })
71     return {actual: output, expected: output}
72   })
73 })
74
75 test('cleanup', function (t) {
76   cleanup()
77   t.end()
78 })