Skip to content

Commit 40ce9e9

Browse files
committed
fix: use ci to spawn tests separately
1 parent b3985c1 commit 40ce9e9

File tree

3 files changed

+91
-15
lines changed

3 files changed

+91
-15
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request:
88

99
jobs:
10-
test:
10+
build:
1111
strategy:
1212
fail-fast: false # prevent test to stop if one fails
1313
matrix:
@@ -29,7 +29,38 @@ jobs:
2929
- if: matrix['node-version'] == '18.x' && matrix['os'] == 'ubuntu-latest'
3030
run: yarn lint
3131
- run: yarn build
32-
- run: yarn test
33-
env:
34-
CI: true
35-
timeout-minutes: 30
32+
test_host:
33+
strategy:
34+
fail-fast: false # prevent test to stop if one fails
35+
matrix:
36+
node-version: [18.x, 20.x]
37+
os: [ubuntu-latest, windows-latest, macos-latest]
38+
uses: ./.github/workflows/test.yml
39+
with:
40+
node_version: ${{ matrix.node-version }}
41+
os: ${{ matrix.os }}
42+
npm_command: test:host
43+
44+
test_18:
45+
strategy:
46+
fail-fast: false # prevent test to stop if one fails
47+
matrix:
48+
node-version: [18.x, 20.x]
49+
os: [ubuntu-latest, windows-latest, macos-latest]
50+
uses: ./.github/workflows/test.yml
51+
with:
52+
node_version: ${{ matrix.node-version }}
53+
os: ${{ matrix.os }}
54+
npm_command: test:18
55+
56+
test_20:
57+
strategy:
58+
fail-fast: false # prevent test to stop if one fails
59+
matrix:
60+
node-version: [18.x, 20.x]
61+
os: [ubuntu-latest, windows-latest, macos-latest]
62+
uses: ./.github/workflows/test.yml
63+
with:
64+
node_version: ${{ matrix.node-version }}
65+
os: ${{ matrix.os }}
66+
npm_command: test:20

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node_version:
7+
description: 'Node.js version'
8+
type: string
9+
required: true
10+
default: '18.x'
11+
os:
12+
description: 'Operating system'
13+
type: string
14+
required: true
15+
default: 'ubuntu-latest'
16+
npm_command:
17+
description: 'NPM command to run'
18+
type: string
19+
required: true
20+
default: 'install'
21+
22+
23+
jobs:
24+
test:
25+
runs-on: ${{ inputs.os }}
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version: ${{ inputs.node_version }}
31+
- uses: actions/cache@v3
32+
with:
33+
path: ~/.pkg-cache/
34+
key: ${{ inputs.os }}-${{ inputs.node_version }}
35+
36+
- run: yarn install
37+
38+
- run: yarn build
39+
- run: yarn ${{ inputs.npm_command }}
40+
env:
41+
CI: true
42+
timeout-minutes: 30

test/test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ 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');
1110
const host = 'node' + utils.getNodeMajorVersion();
1211
let target = process.argv[2] || 'host';
1312
if (target === 'host') target = host;
@@ -19,11 +18,7 @@ if (target === 'host') target = host;
1918

2019
const flavor = process.env.FLAVOR || process.argv[3] || 'all';
2120

22-
// const isCI = process.env.CI === 'true';
23-
24-
// based on tests using too high concurrency make tests slower
25-
const maxConcurrency =
26-
flavor === 'only-npm' ? 1 : Math.max(cpus().length - 1, 2);
21+
const isCI = process.env.CI === 'true';
2722

2823
console.log('');
2924
console.log('*************************************');
@@ -156,13 +151,20 @@ function runTest(file) {
156151
});
157152
}
158153

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+
159160
async function run() {
160161
let done = 0;
161162
let ok = 0;
162163
let failed = [];
163164
const start = Date.now();
164165

165166
function addLog(log, isError = false) {
167+
clearLastLine();
166168
if (isError) {
167169
console.error(log);
168170
} else {
@@ -174,6 +176,9 @@ async function run() {
174176
file = path.resolve(file);
175177
const startTest = Date.now();
176178
try {
179+
if (!isCI) {
180+
console.log(pc.gray(`⏳ ${file} - ${done}/${files.length}`));
181+
}
177182
await runTest(file);
178183
ok++;
179184
addLog(
@@ -198,8 +203,8 @@ async function run() {
198203
done++;
199204
});
200205

201-
for (let i = 0; i < promises.length; i += maxConcurrency) {
202-
await Promise.all(promises.slice(i, i + maxConcurrency).map((p) => p()));
206+
for (let i = 0; i < promises.length; i++) {
207+
await promises[i]();
203208
}
204209

205210
const end = Date.now();
@@ -231,8 +236,6 @@ function cleanup() {
231236
for (const process of activeProcesses) {
232237
process.kill();
233238
}
234-
235-
process.exit(1);
236239
}
237240

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

0 commit comments

Comments
 (0)