MCPcopy
hub / github.com/vercel/next.js / runNextCommandDev

Function runNextCommandDev

test/lib/next-test-utils.ts:419–508  ·  view source on GitHub ↗
(
  argv: string[],
  stdOut?: boolean,
  opts: NextDevOptions = {}
)

Source from the content-addressed store, hash-verified

417}
418
419export function runNextCommandDev(
420 argv: string[],
421 stdOut?: boolean,
422 opts: NextDevOptions = {}
423): Promise<(typeof stdOut extends true ? string : ChildProcess) | undefined> {
424 const nextDir = path.dirname(require.resolve('next/package'))
425 const nextBin = opts.nextBin || path.join(nextDir, 'dist/bin/next')
426 const cwd = opts.cwd || nextDir
427 const env = {
428 ...process.env,
429 // @ts-ignore packages/next/types/global.d.ts should allow undefined NODE_ENV
430 NODE_ENV: undefined as NodeJS.ProcessEnv['NODE_ENV'],
431 __NEXT_TEST_MODE: 'true',
432 ...opts.env,
433 }
434
435 const nodeArgs = opts.nodeArgs || []
436 return new Promise((resolve, reject) => {
437 const instance = spawn(
438 'node',
439 [...nodeArgs, '--no-deprecation', nextBin, ...argv],
440 {
441 cwd,
442 env,
443 }
444 )
445 let didResolve = false
446
447 const bootType =
448 opts.nextStart || stdOut ? 'start' : opts?.turbo ? 'turbo' : 'dev'
449
450 function handleStdout(data) {
451 const message = data.toString()
452 const bootupMarkers = {
453 dev: /✓ ready/i,
454 turbo: /✓ ready/i,
455 start: /✓ ready/i,
456 }
457
458 const strippedMessage = stripAnsi(message) as any
459
460 if (
461 (opts.bootupMarker && opts.bootupMarker.test(strippedMessage)) ||
462 bootupMarkers[bootType].test(strippedMessage)
463 ) {
464 if (!didResolve) {
465 didResolve = true
466 // Pass down the original message
467 resolve(stdOut ? message : instance)
468 }
469 }
470
471 if (typeof opts.onStdout === 'function') {
472 opts.onStdout(message)
473 }
474
475 if (opts.stdout !== false) {
476 process.stdout.write(message)

Callers 4

index.test.tsFile · 0.90
index.test.tsFile · 0.90
launchAppFunction · 0.70
nextStartFunction · 0.70

Calls 7

resolveMethod · 0.65
spawnFunction · 0.50
resolveFunction · 0.50
rejectFunction · 0.50
joinMethod · 0.45
onMethod · 0.45
removeListenerMethod · 0.45

Tested by

no test coverage detected