Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"del-cli": "^7.0.0",
"eslint": "^10.9.1",
"eslint-config-webpack": "^4.9.6",
"execa": "^9.6.1",
"execa": "^10.0.1",
"get-port": "^7.2.0",
"husky": "^9.1.7",
"jest": "^30.4.2",
Expand Down
20 changes: 12 additions & 8 deletions smoketests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const swapPkgName = (current, isSubPackage = false) => {
fs.renameSync(getPkgPath(current, isSubPackage), getPkgPath(next, isSubPackage));
};

// Since execa v10 the subprocess is a plain promise, Node.js `ChildProcess` APIs
// like `.on()` are only available through `subprocess.nodeChildProcess`
const getChildProcess = (proc) => proc.nodeChildProcess ?? proc;

const CLI_ENTRY_PATH = path.resolve(ROOT_PATH, "./packages/webpack-cli/bin/cli.js");

const runTest = async (pkg, cliArgs = [], logMessage = undefined, isSubPackage = false) => {
Expand Down Expand Up @@ -70,13 +74,13 @@ const runTest = async (pkg, cliArgs = [], logMessage = undefined, isSubPackage =
}
});

proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
swapPkgName(`.${pkg}`, isSubPackage);
clearTimeout(timeout);
resolve(hasPassed);
});

proc.on("error", () => {
getChildProcess(proc).on("error", () => {
swapPkgName(`.${pkg}`, isSubPackage);
clearTimeout(timeout);
resolve(false);
Expand Down Expand Up @@ -123,13 +127,13 @@ const runTestStdout = async ({ packageName, cliArgs, logMessage, isSubPackage, c
console.log(` stderr: ${data}`);
});

proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
swapPkgName(`.${packageName}`, isSubPackage);
clearTimeout(timeout);
resolve(hasPassed);
});

proc.on("error", () => {
getChildProcess(proc).on("error", () => {
swapPkgName(`.${packageName}`, isSubPackage);
clearTimeout(timeout);
resolve(false);
Expand Down Expand Up @@ -187,13 +191,13 @@ const runTestStdoutWithInput = async ({
console.log(` stderr: ${data}`);
});

proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
swapPkgName(`.${packageName}`, isSubPackage);
clearTimeout(timeout);
resolve(hasPassed);
});

proc.on("error", () => {
getChildProcess(proc).on("error", () => {
swapPkgName(`.${packageName}`, isSubPackage);
clearTimeout(timeout);
resolve(false);
Expand Down Expand Up @@ -250,13 +254,13 @@ const runTestWithHelp = async (pkg, cliArgs = [], logMessage = undefined, isSubP
}
});

proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
swapPkgName(`.${pkg}`, isSubPackage);
clearTimeout(timeout);
resolve(hasPassed);
});

proc.on("error", () => {
getChildProcess(proc).on("error", () => {
swapPkgName(`.${pkg}`, isSubPackage);
clearTimeout(timeout);
resolve(false);
Expand Down
10 changes: 10 additions & 0 deletions test/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ const hyphenToUpperCase = (name) => {
return name.replaceAll(/-([a-z])/g, (g) => g[1].toUpperCase());
};

// Since execa v10 the subprocess is a plain promise, Node.js `ChildProcess` APIs
// like `.on()` are only available through `subprocess.nodeChildProcess`
/**
* Get the underlying Node.js child process of an execa subprocess.
* @param {import("execa").ResultPromise} proc execa subprocess
* @returns {import("node:child_process").ChildProcess} child process
*/
const getChildProcess = (proc) => proc.nodeChildProcess ?? proc;

const processKill = (process) => {
if (isWindows) {
exec(`taskkill /pid ${process.pid} /T /F`);
Expand Down Expand Up @@ -389,6 +398,7 @@ const uniqueDirectoryForTest = async () => {
};

module.exports = {
getChildProcess,
getWebpackCliArguments,
hyphenToUpperCase,
isWindows,
Expand Down
18 changes: 9 additions & 9 deletions test/watch/stdin/stdin.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { processKill, runWatch } = require("../../utils/test-utils");
const { getChildProcess, processKill, runWatch } = require("../../utils/test-utils");

describe("--watch-options-stdin", () => {
it('should stop the process when stdin ends using "--watch" and "--watch-options-stdin" options', async () => {
let semaphore = false;

await runWatch(__dirname, ["--watch", "--watch-options-stdin"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -24,7 +24,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["watch", "--watch-options-stdin"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -42,7 +42,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["--config", "./watch.config.js"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -60,7 +60,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["--config", "./multi-watch.config.js"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -78,7 +78,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["serve", "--watch-options-stdin"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -96,7 +96,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["serve", "--stdin"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -114,7 +114,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["serve", "--config", "./serve.config.js"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand All @@ -132,7 +132,7 @@ describe("--watch-options-stdin", () => {

await runWatch(__dirname, ["--config", "./multi-watch.config.js"], {
handler: (proc) => {
proc.on("exit", () => {
getChildProcess(proc).on("exit", () => {
expect(semaphore).toBe(true);

processKill(proc);
Expand Down
Loading