Skip to content

Commit 591b810

Browse files
test: refactor
1 parent b85f651 commit 591b810

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+400
-440
lines changed

globalSetupTest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ async function validatePorts() {
1717

1818
arr.forEach((port) => {
1919
const check = tcpPortUsed.check(port, 'localhost').then((inUse) => {
20-
if (inUse) throw new Error(`${port} has already used. [${key}]`);
20+
if (inUse) {
21+
throw new Error(`${port} has already used. [${key}]`);
22+
}
2123
});
2224

2325
samples.push(check);

jest.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ module.exports = {
99
'<rootDir>/client/',
1010
],
1111
testPathIgnorePatterns: ['<rootDir>/bin/this/process-arguments.js'],
12-
moduleFileExtensions: ['js', 'json'],
13-
testMatch: ['**/test/**/*.test.js'],
1412
snapshotResolver: '<rootDir>/test/helpers/snapshotResolver.js',
1513
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
1614
globalSetup: '<rootDir>/globalSetupTest.js',
17-
testSequencer: '<rootDir>/test/testSequencer.js',
1815
};

lib/Server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ class Server {
789789
function runPortFinder() {
790790
return new Promise((resolve, reject) => {
791791
// default port
792-
portfinder.basePort = 8080;
792+
portfinder.basePort = process.env.WEBPACK_DEV_SERVER_BASE_PORT || 8080;
793793
portfinder.getPort((error, foundPort) => {
794794
if (error) {
795795
return reject(error);
@@ -802,7 +802,8 @@ class Server {
802802

803803
// Try to find unused port and listen on it for 3 times,
804804
// if port is not specified in options.
805-
const defaultPortRetry = parseInt(process.env.DEFAULT_PORT_RETRY, 10) || 3;
805+
const defaultPortRetry =
806+
parseInt(process.env.WEBPACK_DEV_SERVER_PORT_RETRY, 10) || 3;
806807

807808
return pRetry(runPortFinder, { retries: defaultPortRetry });
808809
}

package-lock.json

Lines changed: 32 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"@babel/runtime": "^7.14.5",
6868
"@commitlint/cli": "^12.1.3",
6969
"@commitlint/config-conventional": "^12.1.4",
70-
"@jest/test-sequencer": "^27.0.4",
7170
"acorn": "^8.2.4",
7271
"babel-jest": "^27.0.2",
7372
"babel-loader": "^8.2.2",

test/cli/__snapshots__/basic.test.js.snap.webpack4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`basic basic should work using "--host localhost --port 9999": stderr 1`] = `
3+
exports[`basic basic should work using "--host localhost --port <port>": stderr 1`] = `
44
"<i> [webpack-dev-server] Project is running at:
55
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
66
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"

test/cli/__snapshots__/basic.test.js.snap.webpack5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`basic basic should work using "--host localhost --port 9999": stderr 1`] = `
3+
exports[`basic basic should work using "--host localhost --port <port>": stderr 1`] = `
44
"<i> [webpack-dev-server] Project is running at:
55
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
66
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"

test/cli/basic.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const schema = require('../../lib/options.json');
88
const cliOptions = require('../../bin/cli-flags');
99
const { testBin, normalizeStderr } = require('../helpers/test-bin');
1010
const isWebpack5 = require('../helpers/isWebpack5');
11+
const port = require('../ports-map')['cli-basic'];
1112

1213
const isMacOS = process.platform === 'darwin';
1314
const webpack5Test = isWebpack5 ? it : it.skip;
@@ -48,12 +49,12 @@ describe('basic', () => {
4849
expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr');
4950
});
5051

51-
it('should work using "--host localhost --port 9999"', async () => {
52+
it('should work using "--host localhost --port <port>"', async () => {
5253
const { exitCode, stderr } = await testBin([
5354
'--host',
5455
'localhost',
5556
'--port',
56-
9999,
57+
port,
5758
]);
5859

5960
expect(exitCode).toEqual(0);

test/cli/port-option.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22

33
const { testBin, normalizeStderr } = require('../helpers/test-bin');
4+
const port = require('../ports-map')['cli-port-option'];
45

56
describe('"port" CLI option', () => {
67
it('should work using "--port <string>"', async () => {
7-
const { exitCode, stderr } = await testBin(['--port', '8080']);
8+
const { exitCode, stderr } = await testBin(['--port', port]);
89

910
expect(exitCode).toEqual(0);
1011
expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr');

test/client/clients/SockJSClient.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const http = require('http');
88
const express = require('express');
99
const sockjs = require('sockjs');
10-
const port = require('../../ports-map').sockJSClient;
10+
const port = require('../../ports-map')['sockjs-client'];
1111

1212
jest.setMock('../../../client-src/utils/log', {
1313
log: {

test/client/clients/WebsocketClient.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const http = require('http');
88
const express = require('express');
99
const ws = require('ws');
10-
const port = require('../../ports-map').WebsocketClient;
10+
const port = require('../../ports-map')['web-socket-client'];
1111

1212
jest.setMock('../../../client-src/utils/log', {
1313
log: {

0 commit comments

Comments
 (0)