-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run: default the 'start' script when server.js present
- Loading branch information
Showing
2 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,11 @@ const output = [] | |
|
||
const npmlog = { level: 'warn' } | ||
const getRS = windows => requireInject('../../lib/run-script.js', { | ||
'@npmcli/run-script': async opts => { | ||
'@npmcli/run-script': Object.assign(async opts => { | ||
RUN_SCRIPTS.push(opts) | ||
}, | ||
}, { | ||
isServerPackage: require('@npmcli/run-script').isServerPackage, | ||
}), | ||
npmlog, | ||
'../../lib/npm.js': npm, | ||
'../../lib/utils/is-windows-shell.js': windows, | ||
|
@@ -90,10 +92,29 @@ t.test('fail if no package.json', async t => { | |
await runScript(['test'], er => t.match(er, { code: 'ENOENT' })) | ||
}) | ||
|
||
t.test('default env and restart scripts', async t => { | ||
t.test('default env, start, and restart scripts', async t => { | ||
npm.localPrefix = t.testdir({ | ||
'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }) | ||
'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }), | ||
'server.js': 'console.log("hello, world")', | ||
}) | ||
|
||
await runScript(['start'], er => { | ||
if (er) { | ||
throw er | ||
} | ||
t.match(RUN_SCRIPTS, [ | ||
{ | ||
path: npm.localPrefix, | ||
args: [], | ||
scriptShell: undefined, | ||
stdio: 'inherit', | ||
stdioString: true, | ||
pkg: { name: 'x', version: '1.2.3', _id: '[email protected]', scripts: {}}, | ||
event: 'start' | ||
} | ||
]) | ||
}) | ||
RUN_SCRIPTS.length = 0 | ||
|
||
await runScript(['env'], er => { | ||
if (er) { | ||
|