MCPcopy
hub / github.com/blitz-js/blitz / runNextCommandDev

Function runNextCommandDev

integration-tests/utils/next-test-utils.ts:398–472  ·  view source on GitHub ↗
(argv, stdOut, opts: RunNextCommandDevOptions = {})

Source from the content-addressed store, hash-verified

396}
397
398export function runNextCommandDev(argv, stdOut, opts: RunNextCommandDevOptions = {}) {
399 const nextnextbin = getCommandBin("next", opts.cwd)
400 const nextDir = path.resolve(require.resolve("next/package"))
401 const nextBin = path.join(nextnextbin, "dist/bin/next")
402
403 const cwd = opts.cwd || nextDir
404 const env = {
405 ...process.env,
406 NODE_ENV: undefined,
407 __NEXT_TEST_MODE: "true",
408 ...opts.env,
409 }
410
411 const nodeArgs = opts.nodeArgs || []
412 return new Promise<void>((resolve, reject) => {
413 const instance = spawn("node", [...nodeArgs, "--no-deprecation", nextBin, ...argv], {
414 cwd,
415 env,
416 } as {})
417 let didResolve = false
418
419 function handleStdout(data) {
420 const message = data.toString()
421 console.log(message)
422 const bootupMarkers = {
423 dev: /Next.js/i,
424 start: /Next.js/i,
425 }
426 if (
427 (opts.bootupMarker && opts.bootupMarker.test(message)) ||
428 bootupMarkers[opts.nextStart || stdOut ? "start" : "dev"].test(message)
429 ) {
430 if (!didResolve) {
431 didResolve = true
432 resolve(stdOut ? message : instance)
433 }
434 }
435
436 if (typeof opts.onStdout === "function") {
437 opts.onStdout(message)
438 }
439
440 if (opts.stdout !== false) {
441 process.stdout.write(message)
442 }
443 }
444
445 function handleStderr(data) {
446 const message = data.toString()
447 if (typeof opts.onStderr === "function") {
448 opts.onStderr(message)
449 }
450
451 if (opts.stderr !== false) {
452 process.stderr.write(message)
453 }
454 }
455

Callers 2

launchAppFunction · 0.85
nextStartFunction · 0.85

Calls 2

getCommandBinFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected