MCPcopy Index your code
hub / github.com/blitz-js/blitz / runBlitzCommand

Function runBlitzCommand

integration-tests/utils/next-test-utils.ts:144–221  ·  view source on GitHub ↗
(argv, options: RunNextCommandOptions = {})

Source from the content-addressed store, hash-verified

142}
143
144export function runBlitzCommand(argv, options: RunNextCommandOptions = {}) {
145 const nextnextbin = getCommandBin("blitz", options.cwd)
146 const blitzBin = path.join(nextnextbin, "dist/index.cjs")
147 const cwd = options.cwd || process.cwd()
148 // Let Next.js decide the environment
149 const env = {
150 ...process.env,
151 NODE_ENV: "production" as const,
152 __NEXT_TEST_MODE: "true",
153 ...options.env,
154 }
155
156 return new Promise((resolve, reject) => {
157 console.log(`Running command "blitz ${argv.join(" ")}"`)
158 const instance = spawn("node", [blitzBin, ...argv], {
159 cwd,
160 env,
161 stdio: ["ignore", "pipe", "pipe"],
162 })
163
164 if (typeof options.instance === "function") {
165 options.instance(instance)
166 }
167
168 let mergedStdio = ""
169
170 let stderrOutput = ""
171 if (options.stderr) {
172 instance.stderr?.on("data", function (chunk) {
173 mergedStdio += chunk
174 stderrOutput += chunk
175
176 if (options.stderr === "log") {
177 console.log(chunk.toString())
178 }
179 })
180 } else {
181 instance.stderr?.on("data", function (chunk) {
182 mergedStdio += chunk
183 })
184 }
185
186 let stdoutOutput = ""
187 if (options.stdout) {
188 instance.stdout?.on("data", function (chunk) {
189 mergedStdio += chunk
190 stdoutOutput += chunk
191
192 if (options.stdout === "log") {
193 console.log(chunk.toString())
194 }
195 })
196 } else {
197 instance.stdout?.on("data", function (chunk) {
198 mergedStdio += chunk
199 })
200 }
201

Callers 9

index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
blitzBuildFunction · 0.85
nextLintFunction · 0.85

Calls 4

toStringMethod · 0.80
getCommandBinFunction · 0.70
logMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected