Skip to content

Commit 8be7932

Browse files
committed
test: don't use --runInBand and improve execution performance
backport from #2005 to master branch
1 parent 90d4a7c commit 8be7932

39 files changed

+394
-167
lines changed

.babelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"presets": ["@babel/preset-env"]
2+
"presets": ["@babel/preset-env"],
3+
"env": {
4+
"test": {
5+
"plugins": ["@babel/plugin-transform-runtime"]
6+
}
7+
}
38
}

globalSetupTest.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
// eslint-disable-next-line import/no-extraneous-dependencies
4+
const tcpPortUsed = require('tcp-port-used');
5+
const ports = require('./test/ports-map');
6+
7+
async function validatePorts() {
8+
const samples = [];
9+
10+
Object.keys(ports).forEach((key) => {
11+
const value = ports[key];
12+
const arr = Array.isArray(value) ? value : [value];
13+
14+
arr.forEach((port) => {
15+
const check = tcpPortUsed.check(port, 'localhost').then((inUse) => {
16+
if (inUse) throw new Error(`${port} has already used. [${key}]`);
17+
});
18+
19+
samples.push(check);
20+
});
21+
});
22+
23+
try {
24+
await Promise.all(samples);
25+
} catch (e) {
26+
// eslint-disable-next-line no-console
27+
console.error(e);
28+
process.exit(1);
29+
}
30+
}
31+
32+
module.exports = validatePorts;

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = {
77
moduleFileExtensions: ['js', 'json'],
88
testMatch: ['**/test/**/*.test.js'],
99
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
10+
globalSetup: '<rootDir>/globalSetupTest.js',
1011
};

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint": "npm-run-all -l -p \"lint:**\"",
2020
"commitlint": "commitlint --from=master",
2121
"security": "npm audit",
22-
"test:only": "jest --runInBand",
22+
"test:only": "jest",
2323
"test:coverage": "npm run test:only -- --coverage",
2424
"test:watch": "npm run test:coverage --watch",
2525
"test": "npm run test:coverage",
@@ -70,6 +70,7 @@
7070
"devDependencies": {
7171
"@babel/cli": "^7.4.4",
7272
"@babel/core": "^7.4.5",
73+
"@babel/plugin-transform-runtime": "^7.4.4",
7374
"@babel/preset-env": "^7.4.5",
7475
"@commitlint/cli": "^7.6.1",
7576
"@commitlint/config-conventional": "^7.6.0",
@@ -102,6 +103,7 @@
102103
"standard-version": "^6.0.1",
103104
"style-loader": "^0.23.1",
104105
"supertest": "^4.0.2",
106+
"tcp-port-used": "^1.0.1",
105107
"url-loader": "^1.1.2",
106108
"webpack": "^4.33.0",
107109
"webpack-cli": "^3.3.3",

test/cli/cli.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ describe('CLI', () => {
162162
const cliPath = resolve(__dirname, '../../bin/webpack-dev-server.js');
163163
const examplePath = resolve(__dirname, '../../examples/cli/public');
164164

165-
const cp = execa('node', [cliPath], { cwd: examplePath });
166-
const cp2 = execa('node', [cliPath], { cwd: examplePath });
165+
const cp = execa('node', [cliPath, '--colors=false'], { cwd: examplePath });
166+
const cp2 = execa('node', [cliPath, '--colors=false'], {
167+
cwd: examplePath,
168+
});
167169

168170
const runtime = {
169171
cp: {

test/client/clients/SockJSClient.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const http = require('http');
44
const express = require('express');
55
const sockjs = require('sockjs');
66
const SockJSClient = require('../../../client-src/clients/SockJSClient');
7+
const port = require('../../ports-map').sockJSClient;
78

89
describe('SockJSClient', () => {
910
let socketServer;
@@ -14,7 +15,7 @@ describe('SockJSClient', () => {
1415
const app = new express();
1516

1617
listeningApp = http.createServer(app);
17-
listeningApp.listen(8080, 'localhost', () => {
18+
listeningApp.listen(port, 'localhost', () => {
1819
socketServer = sockjs.createServer();
1920
socketServer.installHandlers(listeningApp, {
2021
prefix: '/sockjs-node',
@@ -33,7 +34,7 @@ describe('SockJSClient', () => {
3334
}, 1000);
3435
});
3536

36-
const client = new SockJSClient('http://localhost:8080/sockjs-node');
37+
const client = new SockJSClient(`http://localhost:${port}/sockjs-node`);
3738
const data = [];
3839

3940
client.onOpen(() => {

0 commit comments

Comments
 (0)