Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 24 additions & 5 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,13 @@
}

additionalEntries.push(
`${require.resolve("../client/index.js")}?${webSocketURLStr}`,
`${this.getClientEntry()}?${webSocketURLStr}`,
);
}

if (this.options.hot === "only") {
additionalEntries.push(require.resolve("webpack/hot/only-dev-server"));
} else if (this.options.hot) {
additionalEntries.push(require.resolve("webpack/hot/dev-server"));
const clientHotEntry = this.getClientHotEntry();
if (clientHotEntry) {
additionalEntries.push(clientHotEntry);
}

const webpack = compiler.webpack || require("webpack");
Expand Down Expand Up @@ -1676,6 +1675,26 @@
return implementation;
}

/**
* @private
* @returns {string}
*/
getClientEntry() {
return require.resolve("../client/index.js");
}

/**
* @private
* @returns {string | void}
*/
getClientHotEntry() {
if (this.options.hot === "only") {
return require.resolve("webpack/hot/only-dev-server");

Check warning on line 1692 in lib/Server.js

View check run for this annotation

Codecov / codecov/patch

lib/Server.js#L1692

Added line #L1692 was not covered by tests
} else if (this.options.hot) {
return require.resolve("webpack/hot/dev-server");
}
}

/**
* @private
* @returns {void}
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/__snapshots__/client.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exports[`client option default behaviour responds with a 200 status code for /ws

exports[`client option default behaviour responds with a 200 status code for /ws path: response status 1`] = `200`;

exports[`client option override client entry should disable client entry: response status 1`] = `200`;

exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: console messages 1`] = `[]`;

exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: page errors 1`] = `[]`;
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,60 @@ describe("client option", () => {
});
});

describe("override client entry", () => {
let compiler;
let server;
let page;
let browser;

class OverrideServer extends Server {
// eslint-disable-next-line class-methods-use-this
getClientEntry() {
return require.resolve(
"../fixtures/custom-client/CustomClientEntry.js",
);
}
// eslint-disable-next-line class-methods-use-this
getClientHotEntry() {
return require.resolve(
"../fixtures/custom-client/CustomClientHotEntry.js",
);
}
}

beforeEach(async () => {
compiler = webpack(config);

server = new OverrideServer(
{
port,
},
compiler,
);

await server.start();

({ page, browser } = await runBrowser());
});

afterEach(async () => {
await browser.close();
await server.stop();
});

it("should disable client entry", async () => {
const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
waitUntil: "networkidle0",
});

expect(response.status()).toMatchSnapshot("response status");

const content = await response.text();
expect(content).toContain("CustomClientEntry.js");
expect(content).toContain("CustomClientHotEntry.js");
});
});

describe("webSocketTransport", () => {
const clientModes = [
{
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/custom-client/CustomClientEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

console.log("custom client entry");
3 changes: 3 additions & 0 deletions test/fixtures/custom-client/CustomClientHotEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

console.log("custom client hot entry");
10 changes: 10 additions & 0 deletions types/lib/Server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,16 @@ declare class Server<
* @returns {T}
*/
private getServerTransport;
/**
* @private
* @returns {string}
*/
private getClientEntry;
/**
* @private
* @returns {string | void}
*/
private getClientHotEntry;
/**
* @private
* @returns {void}
Expand Down
Loading