Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix serve errors on windows #3784

Merged
merged 12 commits into from
May 11, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ exports[`basic serve usage should throw error when same ports in multicompiler:

exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;

exports[`basic serve usage should work and log warning on the \`watch option in a configuration: stderr 1`] = `
exports[`basic serve usage should work and log warning on the 'watch' option in a configuration: stderr 1`] = `
"[webpack-cli] No need to use the 'serve' command together with '{ watch: true | false }' or '--watch'/'--no-watch' configuration, it does not make sense.
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
Expand Down
8 changes: 3 additions & 5 deletions test/serve/basic/serve-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe("basic serve usage", () => {
expect(stdout).toContain("development");
});

it("should work and log warning on the `watch option in a configuration", async () => {
it("should work and log warning on the 'watch' option in a configuration", async () => {
const { stderr, stdout } = await runWatch(__dirname, [
"serve",
"--config",
Expand All @@ -371,18 +371,16 @@ describe("basic serve usage", () => {
});

it("should log error on using '--watch' flag with serve", async () => {
const { exitCode, stdout, stderr } = await runWatch(testPath, ["serve", "--watch"]);
const { stdout, stderr } = await runWatch(__dirname, ["serve", "--watch", "--port", port]);

expect(exitCode).toBe(0);
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
expect(stdout).toContain("HotModuleReplacementPlugin");
expect(stdout).toContain("main.js");
});

it("should log warning on using '-w' alias with serve", async () => {
const { exitCode, stdout, stderr } = await runWatch(testPath, ["serve", "-w"]);
const { stdout, stderr } = await runWatch(__dirname, ["serve", "-w", "--port", port]);

expect(exitCode).toBe(0);
Comment on lines +382 to -385
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't test on the exit code for the serve because we exit forcefully and the exit code is different on Linux/windows.

const processKill = (process) => {
if (isWindows) {
exec("taskkill /pid " + process.pid + " /T /F");
} else {
process.kill();
}
};

expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
expect(stdout).toContain("HotModuleReplacementPlugin");
expect(stdout).toContain("main.js");
Expand Down