node/deps/npm/test/lib/commands/start.js
npm team 76d85a82ea deps: upgrade npm to 8.5.5
PR-URL: https://github.com/nodejs/node/pull/42382
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-03-18 18:55:25 -07:00

39 lines
1.1 KiB
JavaScript

const t = require('tap')
const spawk = require('spawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
spawk.preventUnmatched()
t.teardown(() => {
spawk.unload()
})
// TODO this ... smells. npm "script-shell" config mentions defaults but those
// are handled by run-script, not npm. So for now we have to tie tests to some
// pretty specific internals of runScript
const makeSpawnArgs = require('@npmcli/run-script/lib/make-spawn-args.js')
t.test('should run start script from package.json', async t => {
t.plan(2)
const { npm } = await loadMockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'x',
version: '1.2.3',
scripts: {
start: 'node ./test-start.js',
},
}),
},
config: {
loglevel: 'silent',
},
})
const [scriptShell] = makeSpawnArgs({ path: npm.prefix })
const script = spawk.spawn(scriptShell, (args) => {
t.ok(args.includes('node ./test-start.js "foo"'), 'ran start script with extra args')
return true
})
await npm.exec('start', ['foo'])
t.ok(script.called, 'script ran')
})