MCPcopy Create free account
hub / github.com/webpack/webpack-cli / runTest

Function runTest

smoketests/helpers.js:24–85  ·  view source on GitHub ↗
(pkg, cliArgs = [], logMessage = undefined, isSubPackage = false)

Source from the content-addressed store, hash-verified

22const CLI_ENTRY_PATH = path.resolve(ROOT_PATH, "./packages/webpack-cli/bin/cli.js");
23
24const runTest = async (pkg, cliArgs = [], logMessage = undefined, isSubPackage = false) => {
25 // Simulate package missing
26 swapPkgName(pkg, isSubPackage);
27
28 const { execa } = await import("execa");
29 const abortController = new AbortController();
30 const proc = execa(CLI_ENTRY_PATH, cliArgs, {
31 cwd: __dirname,
32 reject: false,
33 gracefulCancel: true,
34 cancelSignal: abortController.signal,
35 });
36
37 proc.stdin.setDefaultEncoding("utf8");
38
39 proc.stdout.on("data", (chunk) => {
40 console.log(` stdout: ${chunk.toString()}`);
41 });
42
43 return new Promise((resolve) => {
44 const timeout = setTimeout(() => {
45 console.log(" timeout: killing process");
46 proc.kill();
47 }, 60000);
48
49 const prompt = "Would you like to install";
50 let hasLogMessage = false;
51 let hasPrompt = false;
52 let hasPassed = false;
53
54 proc.stderr.on("data", (chunk) => {
55 const data = stripVTControlCharacters(chunk.toString());
56
57 console.log(` stderr: ${data}`);
58
59 if (data.includes(logMessage)) {
60 hasLogMessage = true;
61 }
62
63 if (data.includes(prompt)) {
64 hasPrompt = true;
65 }
66
67 if (hasLogMessage && hasPrompt) {
68 abortController.abort();
69 hasPassed = true;
70 }
71 });
72
73 proc.on("exit", () => {
74 swapPkgName(`.${pkg}`, isSubPackage);
75 clearTimeout(timeout);
76 resolve(hasPassed);
77 });
78
79 proc.on("error", () => {
80 swapPkgName(`.${pkg}`, isSubPackage);
81 clearTimeout(timeout);

Callers 7

webpackDevServerTestFunction · 0.85
noCommandFunction · 0.85
buildCommandFunction · 0.85
watchCommandFunction · 0.85
serveCommandFunction · 0.85
configtestCommandFunction · 0.85

Calls 2

swapPkgNameFunction · 0.85
resolveFunction · 0.85

Tested by 7

webpackDevServerTestFunction · 0.68
noCommandFunction · 0.68
buildCommandFunction · 0.68
watchCommandFunction · 0.68
serveCommandFunction · 0.68
configtestCommandFunction · 0.68