forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalSetupTest.js
38 lines (30 loc) · 923 Bytes
/
globalSetupTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
// eslint-disable-next-line import/no-extraneous-dependencies
const tcpPortUsed = require("tcp-port-used");
const { version } = require("webpack");
const ports = require("./test/ports-map");
// eslint-disable-next-line no-console
console.log(`\n Running tests for webpack @${version} \n`);
async function validatePorts() {
const samples = [];
Object.keys(ports).forEach((key) => {
const value = ports[key];
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;