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

Function runTestStdout

smoketests/helpers.js:87–138  ·  view source on GitHub ↗
({ packageName, cliArgs, logMessage, isSubPackage, cwd } = {})

Source from the content-addressed store, hash-verified

85};
86
87const runTestStdout = async ({ packageName, cliArgs, logMessage, isSubPackage, cwd } = {}) => {
88 // Simulate package missing
89 swapPkgName(packageName, isSubPackage);
90
91 const { execa } = await import("execa");
92 const abortController = new AbortController();
93 const proc = execa(CLI_ENTRY_PATH, cliArgs, {
94 cwd: cwd || __dirname,
95 reject: false,
96 gracefulCancel: true,
97 cancelSignal: abortController.signal,
98 });
99
100 proc.stdin.setDefaultEncoding("utf8");
101
102 return new Promise((resolve) => {
103 const timeout = setTimeout(() => {
104 console.log(" timeout: killing process");
105 proc.kill();
106 }, 60000);
107
108 let hasPassed = false;
109
110 proc.stdout.on("data", (chunk) => {
111 const data = stripVTControlCharacters(chunk.toString());
112
113 console.log(` stdout: ${data}`);
114
115 if (data.includes(logMessage)) {
116 hasPassed = true;
117 abortController.abort();
118 }
119 });
120
121 proc.stderr.on("data", (chunk) => {
122 const data = stripVTControlCharacters(chunk.toString());
123 console.log(` stderr: ${data}`);
124 });
125
126 proc.on("exit", () => {
127 swapPkgName(`.${packageName}`, isSubPackage);
128 clearTimeout(timeout);
129 resolve(hasPassed);
130 });
131
132 proc.on("error", () => {
133 swapPkgName(`.${packageName}`, isSubPackage);
134 clearTimeout(timeout);
135 resolve(false);
136 });
137 });
138};
139
140const runTestStdoutWithInput = async ({
141 packageName,

Callers 4

versionCommandFunction · 0.85
helpCommandFunction · 0.85
infoCommandFunction · 0.85

Calls 2

swapPkgNameFunction · 0.85
resolveFunction · 0.85

Tested by 4

versionCommandFunction · 0.68
helpCommandFunction · 0.68
infoCommandFunction · 0.68