mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
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.
35 lines
933 B
JavaScript
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(' '));
|