Skip to content

test: don't use --runInBand and improve execution performance #2005

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 1 commit into from
Jun 10, 2019
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
31 changes: 31 additions & 0 deletions globalSetupTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

// eslint-disable-next-line import/no-extraneous-dependencies
const tcpPortUsed = require('tcp-port-used');
const ports = require('./test/ports-map');

async function validatePorts() {
const samples = [];

Object.entries(ports).forEach(([key, value]) => {
const arr = Array.isArray(value) ? value : [value];

arr.forEach((port) => {
const check = tcpPortUsed.check(port, 'localhost').then((inUse) => {
if (inUse) throw new Error(`${port} has already used. [${key}]`);
});

samples.push(check);
});
});

try {
await Promise.all(samples);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
process.exit(1);
}
}

module.exports = validatePorts;
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
moduleFileExtensions: ['js', 'json'],
testMatch: ['**/test/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
globalSetup: '<rootDir>/globalSetupTest.js',
};
85 changes: 55 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lint": "npm-run-all -l -p \"lint:**\"",
"commitlint": "commitlint --from=master",
"security": "npm audit",
"test:only": "jest --runInBand",
"test:only": "jest",
"test:coverage": "npm run test:only -- --coverage",
"test:watch": "npm run test:coverage --watch",
"test": "npm run test:coverage",
Expand Down Expand Up @@ -103,6 +103,7 @@
"standard-version": "^6.0.1",
"style-loader": "^0.23.1",
"supertest": "^4.0.2",
"tcp-port-used": "^1.0.1",
"url-loader": "^2.0.0",
"webpack": "^4.33.0",
"webpack-cli": "^3.3.3",
Expand Down
6 changes: 4 additions & 2 deletions test/cli/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ describe('CLI', () => {
const cliPath = resolve(__dirname, '../../bin/webpack-dev-server.js');
const examplePath = resolve(__dirname, '../../examples/cli/public');

const cp = execa('node', [cliPath], { cwd: examplePath });
const cp2 = execa('node', [cliPath], { cwd: examplePath });
const cp = execa('node', [cliPath, '--colors=false'], { cwd: examplePath });
const cp2 = execa('node', [cliPath, '--colors=false'], {
cwd: examplePath,
});

const runtime = {
cp: {
Expand Down
5 changes: 3 additions & 2 deletions test/client/clients/SockJSClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const express = require('express');
const sockjs = require('sockjs');
const SockJSClient = require('../../../client-src/clients/SockJSClient');
const timer = require('../../helpers/timer');
const port = require('../../ports-map').sockJSClient;

describe('SockJSClient', () => {
let socketServer;
Expand All @@ -15,7 +16,7 @@ describe('SockJSClient', () => {
const app = new express();

listeningApp = http.createServer(app);
listeningApp.listen(8080, 'localhost', () => {
listeningApp.listen(port, 'localhost', () => {
socketServer = sockjs.createServer();
socketServer.installHandlers(listeningApp, {
prefix: '/sockjs-node',
Expand All @@ -33,7 +34,7 @@ describe('SockJSClient', () => {
connection.close();
});

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

client.onOpen(() => {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const reloadConfig = require('../fixtures/reload-config/webpack.config');
const { writeAsync } = require('../helpers/fs');
const testServer = require('../helpers/test-server');
const runBrowser = require('../helpers/run-browser');
const port = require('../ports-map').Client;

const cssFilePath = resolve(__dirname, '../fixtures/reload-config/main.css');

Expand All @@ -20,7 +21,7 @@ describe('reload', () => {
'body { background-color: rgb(0, 0, 255); }'
);
const options = {
port: 9000,
port,
host: '0.0.0.0',
inline: true,
hot: true,
Expand All @@ -41,7 +42,7 @@ describe('reload', () => {
const { page, browser } = await runBrowser();
let refreshed = false;

page.goto('http://localhost:9000/main');
page.goto(`http://localhost:${port}/main`);
await page.waitForNavigation({ waitUntil: 'load' });

{
Expand All @@ -59,7 +60,7 @@ describe('reload', () => {
if (
req.isNavigationRequest() &&
req.frame() === page.mainFrame() &&
req.url() === 'http://localhost:9000/main'
req.url() === `http://localhost:${port}/main`
) {
refreshed = true;
}
Expand Down
Loading