Skip to content

Commit 7418d61

Browse files
committed
test: allow to run tests in parallel
1 parent 417cf78 commit 7418d61

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

test/test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const pc = require('picocolors');
77
const { globSync } = require('tinyglobby');
88
const utils = require('./utils.js');
99
const { spawn } = require('child_process');
10+
const { cpus } = require('os');
1011
const host = 'node' + utils.getNodeMajorVersion();
1112
let target = process.argv[2] || 'host';
1213
if (target === 'host') target = host;
@@ -18,7 +19,9 @@ if (target === 'host') target = host;
1819

1920
const flavor = process.env.FLAVOR || process.argv[3] || 'all';
2021

21-
const isCI = process.env.CI === 'true';
22+
// const isCI = process.env.CI === 'true';
23+
24+
const maxConcurrency = flavor === 'only-npm' ? 1 : Math.max(cpus().length, 4);
2225

2326
console.log('');
2427
console.log('*************************************');
@@ -151,20 +154,13 @@ function runTest(file) {
151154
});
152155
}
153156

154-
const clearLastLine = () => {
155-
if (isCI) return;
156-
process.stdout.moveCursor(0, -1); // up one line
157-
process.stdout.clearLine(1); // from cursor to end
158-
};
159-
160157
async function run() {
161158
let done = 0;
162159
let ok = 0;
163160
let failed = [];
164161
const start = Date.now();
165162

166163
function addLog(log, isError = false) {
167-
clearLastLine();
168164
if (isError) {
169165
console.error(log);
170166
} else {
@@ -176,9 +172,6 @@ async function run() {
176172
file = path.resolve(file);
177173
const startTest = Date.now();
178174
try {
179-
if (!isCI) {
180-
console.log(pc.gray(`⏳ ${file} - ${done}/${files.length}`));
181-
}
182175
await runTest(file);
183176
ok++;
184177
addLog(
@@ -203,8 +196,8 @@ async function run() {
203196
done++;
204197
});
205198

206-
for (let i = 0; i < promises.length; i++) {
207-
await promises[i]();
199+
for (let i = 0; i < promises.length; i += maxConcurrency) {
200+
await Promise.all(promises.slice(i, i + maxConcurrency).map((p) => p()));
208201
}
209202

210203
const end = Date.now();
@@ -236,6 +229,8 @@ function cleanup() {
236229
for (const process of activeProcesses) {
237230
process.kill();
238231
}
232+
233+
process.exit(1);
239234
}
240235

241236
process.on('SIGINT', cleanup);

0 commit comments

Comments
 (0)