2020-10-02 17:52:19 -04:00
|
|
|
const t = require('tap')
|
2022-03-31 22:43:17 +00:00
|
|
|
const tspawk = require('../../fixtures/tspawk')
|
2021-12-02 22:04:46 +00:00
|
|
|
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
2021-08-19 17:47:33 +00:00
|
|
|
|
2022-03-31 22:43:17 +00:00
|
|
|
const spawk = tspawk(t)
|
2021-08-19 17:47:33 +00:00
|
|
|
|
2022-12-06 22:18:33 -05:00
|
|
|
const isCmdRe = /(?:^|\\)cmd(?:\.exe)?$/i
|
2021-08-19 17:47:33 +00:00
|
|
|
|
|
|
|
t.test('should run stop script from package.json', async t => {
|
2021-12-02 22:04:46 +00:00
|
|
|
const { npm } = await loadMockNpm(t, {
|
2022-03-17 20:22:31 +00:00
|
|
|
prefixDir: {
|
2021-12-02 22:04:46 +00:00
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'x',
|
|
|
|
version: '1.2.3',
|
|
|
|
scripts: {
|
|
|
|
stop: 'node ./test-stop.js',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
loglevel: 'silent',
|
2023-01-16 22:38:23 -05:00
|
|
|
'script-shell': process.platform === 'win32' ? process.env.COMSPEC : 'sh',
|
2021-12-02 22:04:46 +00:00
|
|
|
},
|
2021-08-19 17:47:33 +00:00
|
|
|
})
|
2022-12-06 22:18:33 -05:00
|
|
|
|
2023-01-16 22:38:23 -05:00
|
|
|
const scriptShell = npm.config.get('script-shell')
|
2022-12-06 22:18:33 -05:00
|
|
|
const scriptArgs = isCmdRe.test(scriptShell)
|
|
|
|
? ['/d', '/s', '/c', 'node ./test-stop.js foo']
|
|
|
|
: ['-c', 'node ./test-stop.js foo']
|
2022-08-11 07:35:43 -07:00
|
|
|
const script = spawk.spawn(scriptShell, scriptArgs)
|
2021-11-04 20:42:47 +00:00
|
|
|
await npm.exec('stop', ['foo'])
|
2021-08-19 17:47:33 +00:00
|
|
|
t.ok(script.called, 'script ran')
|
2021-03-04 17:40:28 -05:00
|
|
|
})
|