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

Function initNextServerScript

integration-tests/utils/next-test-utils.ts:21–69  ·  view source on GitHub ↗
(scriptPath, successRegexp, env, failRegexp, opts)

Source from the content-addressed store, hash-verified

19export const pkg = _pkg
20
21export function initNextServerScript(scriptPath, successRegexp, env, failRegexp, opts) {
22 return new Promise((resolve, reject) => {
23 const instance = spawn(
24 "node",
25 [...((opts && opts.nodeArgs) || []), "--no-deprecation", scriptPath],
26 {
27 env,
28 cwd: opts && opts.cwd,
29 },
30 )
31
32 function handleStdout(data) {
33 const message = data.toString()
34 if (successRegexp.test(message)) {
35 resolve(instance)
36 }
37 process.stdout.write(message)
38
39 if (opts && opts.onStdout) {
40 opts.onStdout(message.toString())
41 }
42 }
43
44 function handleStderr(data) {
45 const message = data.toString()
46 if (failRegexp && failRegexp.test(message)) {
47 instance.kill()
48 return reject(new Error("received failRegexp"))
49 }
50 process.stderr.write(message)
51
52 if (opts && opts.onStderr) {
53 opts.onStderr(message.toString())
54 }
55 }
56
57 instance.stdout?.on("data", handleStdout)
58 instance.stderr?.on("data", handleStderr)
59
60 instance.on("close", () => {
61 instance.stdout?.removeListener("data", handleStdout)
62 instance.stderr?.removeListener("data", handleStderr)
63 })
64
65 instance.on("error", (err) => {
66 reject(err)
67 })
68 })
69}
70
71export function getFullUrl(appPortOrUrl: string | number, url: string, hostname?: string) {
72 let fullUrl =

Callers

nothing calls this directly

Calls 1

onMethod · 0.45

Tested by

no test coverage detected