Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/lib/start.js')
-rw-r--r--deps/npm/test/lib/start.js48
1 files changed, 34 insertions, 14 deletions
diff --git a/deps/npm/test/lib/start.js b/deps/npm/test/lib/start.js
index 4e77f9691b8..5c38c71a9a6 100644
--- a/deps/npm/test/lib/start.js
+++ b/deps/npm/test/lib/start.js
@@ -1,16 +1,36 @@
const t = require('tap')
-let runArgs
-const npm = {
- commands: {
- 'run-script': (args, cb) => {
- runArgs = args
- cb()
- },
- },
-}
-const Start = require('../../lib/start.js')
-const start = new Start(npm)
-start.exec(['foo'], () => {
- t.match(runArgs, ['start', 'foo'])
- t.end()
+const spawk = require('spawk')
+const { real: mockNpm } = 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 stop script from package.json', async t => {
+ const prefix = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'x',
+ version: '1.2.3',
+ scripts: {
+ start: 'node ./test-start.js',
+ },
+ }),
+ })
+ const { command, npm } = mockNpm(t)
+ await npm.load()
+ npm.log.level = 'silent'
+ npm.localPrefix = prefix
+ const [scriptShell] = makeSpawnArgs({ path: 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 command('start', ['foo'])
+ t.ok(script.called, 'script ran')
})