Skip to content

fix: postpone initialize #3467

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

Merged
merged 33 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6ef561c
fix: postpone initialize
alexander-akait Jun 21, 2021
ca22b00
test: added and fixed
alexander-akait Jun 21, 2021
6eead33
refactor: test
alexander-akait Jun 21, 2021
811d7d6
test: more
alexander-akait Jun 21, 2021
5afad3e
fix: merge
alexander-akait Jun 21, 2021
c265919
refactor: tests
alexander-akait Jun 22, 2021
01afa31
refactor: tests
alexander-akait Jun 22, 2021
908a593
refactor: tests
alexander-akait Jun 22, 2021
b96a386
refactor: tests
alexander-akait Jun 22, 2021
7094305
refactor: tests
alexander-akait Jun 22, 2021
cfd7019
refactor: tests
alexander-akait Jun 22, 2021
9fb4e15
refactor: tests
alexander-akait Jun 22, 2021
2aef919
refactor: tests
alexander-akait Jun 22, 2021
cc1a5e9
refactor: tests
alexander-akait Jun 22, 2021
2bc1449
refactor: tests
alexander-akait Jun 22, 2021
9d008f3
refactor: tests
alexander-akait Jun 22, 2021
7398b3b
refactor: tests
alexander-akait Jun 22, 2021
03cc661
refactor: tests
alexander-akait Jun 22, 2021
97c6f81
refactor: tests
alexander-akait Jun 22, 2021
3cec59d
refactor: tests
alexander-akait Jun 22, 2021
abc765e
refactor: tests
alexander-akait Jun 22, 2021
bc1a06a
Merge branch 'master' into issue-3351
alexander-akait Jun 22, 2021
613aa00
test: fix
alexander-akait Jun 22, 2021
c0db824
test: fix
alexander-akait Jun 22, 2021
9814bf3
test: fix
alexander-akait Jun 22, 2021
535f144
test: fix
alexander-akait Jun 22, 2021
b5e1694
test: fix
alexander-akait Jun 22, 2021
c531718
test: fix
alexander-akait Jun 22, 2021
2d7c7f4
test: fix
alexander-akait Jun 22, 2021
74275ff
test: debug
alexander-akait Jun 22, 2021
36b6621
test: fix
alexander-akait Jun 22, 2021
6069a02
test: fix
alexander-akait Jun 23, 2021
9b5833e
test: fix
alexander-akait Jun 23, 2021
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
18 changes: 13 additions & 5 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class Server {
this.logger,
Server.findCacheDir()
);
}

initialize() {
this.applyDevServerPlugin();

this.webSocketServerImplementation = getSocketServerImplementation(
Expand Down Expand Up @@ -924,6 +926,8 @@ class Server {
.then((foundPort) => {
this.options.port = foundPort;

this.initialize();

return this.server.listen(
this.options.port,
this.options.host,
Expand Down Expand Up @@ -966,12 +970,16 @@ class Server {
);
this.staticWatchers = [];

this.server.kill(() => {
// watchers must be closed before closing middleware
prom.then(() => {
this.middleware.close(callback);
if (this.server) {
this.server.kill(() => {
// watchers must be closed before closing middleware
prom.then(() => {
this.middleware.close(callback);
});
});
});
} else if (callback) {
callback();
}
}

getStats(statsObj) {
Expand Down
2 changes: 0 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ exports[`options validate should throw an error on the "webSocketServer" option
object { type?, options? }"
`;

exports[`options validate should throw an error on the "webSocketServer" option with 'nonexistent-implementation' value 1`] = `"Error: When you use custom web socket implementation you must explicitly specify client.transport. client.transport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class "`;

exports[`options validate should throw an error on the "webSocketServer" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
Expand Down
2 changes: 0 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ exports[`options validate should throw an error on the "webSocketServer" option
object { type?, options? }"
`;

exports[`options validate should throw an error on the "webSocketServer" option with 'nonexistent-implementation' value 1`] = `"Error: When you use custom web socket implementation you must explicitly specify client.transport. client.transport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class "`;

exports[`options validate should throw an error on the "webSocketServer" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
Expand Down
20 changes: 0 additions & 20 deletions test/cli/client-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,4 @@ describe('"client" CLI option', () => {

expect(exitCode).toEqual(0);
});

it('should add "/ws" web socket path by default', async () => {
const { exitCode, stdout } = await testBin(
null,
'./test/fixtures/dev-server/client-default-path-config.js'
);

expect(exitCode).toEqual(0);
expect(stdout).toContain('ws%3A%2F%2F0.0.0.0%2Fws');
});

it('should use "client.webSocketURL.pathname" from configuration', async () => {
const { exitCode, stdout } = await testBin(
null,
'./test/fixtures/dev-server/client-custom-path-config.js'
);

expect(exitCode).toEqual(0);
expect(stdout).toContain('ws%3A%2F%2F0.0.0.0%2Fcustom%2Fpath');
});
});
37 changes: 29 additions & 8 deletions test/client/bundle.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const webpack = require('webpack');
const acorn = require('acorn');
const request = require('supertest');
const testServer = require('../helpers/test-server');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map').bundle;
const isWebpack5 = require('../helpers/isWebpack5');
Expand All @@ -12,16 +13,36 @@ describe('bundle', () => {
let server;
let req;

beforeAll((done) => {
server = testServer.start(
{ ...config, target: isWebpack5 ? ['es5', 'web'] : 'web' },
{ port },
done
);
beforeAll(async () => {
const compiler = webpack({
...config,
target: isWebpack5 ? ['es5', 'web'] : 'web',
});

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

await new Promise((resolve, reject) => {
server.listen(port, '127.0.0.1', (error) => {
if (error) {
reject(error);

return;
}

resolve();
});
});

req = request(server.app);
});

afterAll(testServer.close);
afterAll(async () => {
await new Promise((resolve) => {
server.close(() => {
resolve();
});
});
});

it('should get full user bundle and parse with ES5', async () => {
const { text } = await req
Expand Down
55 changes: 55 additions & 0 deletions test/e2e/__snapshots__/stats.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`stats should work using "{ assets: false }" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "{ warningsFilter: 'test' }" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "{}" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "errors-only" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "false" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "undefined" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;
64 changes: 64 additions & 0 deletions test/e2e/__snapshots__/stats.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`stats should work and respect the "ignoreWarnings" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "{ assets: false }" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "{ warningsFilter: 'test' }" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "{}" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "errors-only" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "false" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`stats should work using "undefined" value for the "stats" option 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,72 @@ Array [

exports[`web socket server URL should work behind proxy, when hostnames are same and ports are different ("ws"): page errors 1`] = `Array []`;

exports[`web socket server URL should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("sockjs"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("sockjs"): page errors 1`] = `Array []`;

exports[`web socket server URL should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("ws"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("ws"): page errors 1`] = `Array []`;

exports[`web socket server URL should work when "host" option is "local-ip" ("sockjs"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work when "host" option is "local-ip" ("sockjs"): page errors 1`] = `Array []`;

exports[`web socket server URL should work when "host" option is "local-ip" ("ws"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work when "host" option is "local-ip" ("ws"): page errors 1`] = `Array []`;

exports[`web socket server URL should work when "host" option is "local-ipv4" ("sockjs"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work when "host" option is "local-ipv4" ("sockjs"): page errors 1`] = `Array []`;

exports[`web socket server URL should work when "host" option is "local-ipv4" ("ws"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`web socket server URL should work when "host" option is "local-ipv4" ("ws"): page errors 1`] = `Array []`;

exports[`web socket server URL should work when "host" option is IPv4 ("sockjs"): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
Loading