/
stop.js
33 lines (29 loc) · 948 Bytes
/
stop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const t = require('tap')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
const spawk = tspawk(t)
const isCmdRe = /(?:^|\\)cmd(?:\.exe)?$/i
t.test('should run stop script from package.json', async t => {
const { npm } = await loadMockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'x',
version: '1.2.3',
scripts: {
stop: 'node ./test-stop.js',
},
}),
},
config: {
loglevel: 'silent',
scriptShell: process.platform === 'win32' ? process.env.COMSPEC : 'sh',
},
})
const scriptShell = npm.config.get('scriptShell')
const scriptArgs = isCmdRe.test(scriptShell)
? ['/d', '/s', '/c', 'node ./test-stop.js foo']
: ['-c', 'node ./test-stop.js foo']
const script = spawk.spawn(scriptShell, scriptArgs)
await npm.exec('stop', ['foo'])
t.ok(script.called, 'script ran')
})