electron/script/split-tests.js
trop[bot] f269ca1d93
test: fix visibility-state-spec.ts flaky test (#44199)
* test: refactor visibility-state-spec

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* ci: shard tests

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* test: update split-tests for use on Windows

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* test: run visibility-state-spec.ts first

Co-Authored-By: John Kleinschmidt <jkleinsc@electronjs.org>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-10-14 09:39:19 -04:00

34 lines
821 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 specFiles = glob.sync('spec/*-spec.ts');
const buckets = [];
for (let i = 0; i < shardCount; i++) {
buckets.push([]);
}
const testsInSpecFile = Object.create(null);
for (const specFile of specFiles) {
const testContent = fs.readFileSync(specFile, 'utf8');
testsInSpecFile[specFile] = testContent.split('it(').length;
}
specFiles.sort((a, b) => {
return testsInSpecFile[b] - testsInSpecFile[a];
});
let shard = 0;
for (const specFile of specFiles) {
buckets[shard].push(path.normalize(specFile));
shard++;
if (shard === shardCount) shard = 0;
}
console.log(buckets[currentShard - 1].join(' '));