11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst tspawk = require('../../fixtures/tspawk')
31cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst spawk = tspawk(t)
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst isCmdRe = /(?:^|\\)cmd(?:\.exe)?$/i
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_cit.test('should run test script from package.json', async t => {
101cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
111cb0ef41Sopenharmony_ci    prefixDir: {
121cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
131cb0ef41Sopenharmony_ci        name: 'x',
141cb0ef41Sopenharmony_ci        version: '1.2.3',
151cb0ef41Sopenharmony_ci        scripts: {
161cb0ef41Sopenharmony_ci          test: 'node ./test-test.js',
171cb0ef41Sopenharmony_ci        },
181cb0ef41Sopenharmony_ci      }),
191cb0ef41Sopenharmony_ci    },
201cb0ef41Sopenharmony_ci    config: {
211cb0ef41Sopenharmony_ci      loglevel: 'silent',
221cb0ef41Sopenharmony_ci      'script-shell': process.platform === 'win32' ? process.env.COMSPEC : 'sh',
231cb0ef41Sopenharmony_ci    },
241cb0ef41Sopenharmony_ci  })
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const scriptShell = npm.config.get('script-shell')
271cb0ef41Sopenharmony_ci  const scriptArgs = isCmdRe.test(scriptShell)
281cb0ef41Sopenharmony_ci    ? ['/d', '/s', '/c', 'node ./test-test.js foo']
291cb0ef41Sopenharmony_ci    : ['-c', 'node ./test-test.js foo']
301cb0ef41Sopenharmony_ci  const script = spawk.spawn(scriptShell, scriptArgs)
311cb0ef41Sopenharmony_ci  await npm.exec('test', ['foo'])
321cb0ef41Sopenharmony_ci  t.ok(script.called, 'script ran')
331cb0ef41Sopenharmony_ci})
34