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