Files
electron/script/split-tests.js
Samuel Attard e90456a9d6 build: distribute spec/serial/* across shards alongside parallel files
split-tests now buckets spec/*.spec.ts and spec/serial/*.spec.ts as two
independent sets (each sorted by test count, round-robined) so every shard
gets a proportional slice of both. run.js already routes spec/serial/* to
the --no-file-parallelism phase, so within a shard serial files still run
one-at-a-time. This also fixes the serial phase never running on CI — it
was skipped because split-tests only emitted parallel positionals.
2026-04-13 01:00:15 -07:00

35 lines
933 B
JavaScript

const glob = require('glob');
const fs = require('node:fs');
const path = require('node:path');
const currentShard = parseInt(process.argv[2], 10);
const shardCount = parseInt(process.argv[3], 10);
const buckets = [];
for (let i = 0; i < shardCount; i++) {
buckets.push([]);
}
function testCountIn(file) {
return fs.readFileSync(file, 'utf8').split('it(').length;
}
function distribute(files) {
files.sort((a, b) => testCountIn(b) - testCountIn(a));
let shard = 0;
for (const file of files) {
buckets[shard].push(path.normalize(file));
shard++;
if (shard === shardCount) shard = 0;
}
}
// Parallel and serial sets are distributed independently so each shard gets a
// proportional slice of both; run.js routes spec/serial/* to the
// --no-file-parallelism phase.
distribute(glob.sync('spec/*.spec.ts'));
distribute(glob.sync('spec/serial/*.spec.ts'));
console.log(buckets[currentShard - 1].join(' '));