Skip to content

Commit 7deabf4

Browse files
authored
[engineering] add testSplit option to unit-test runner (microsoft#253049)
helpful to run tests in parallel
1 parent dadbc58 commit 7deabf4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/unit/electron/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const minimist = require('minimist');
3030
* grep: string;
3131
* run: string;
3232
* runGlob: string;
33+
* testSplit: string;
3334
* dev: boolean;
3435
* reporter: string;
3536
* 'reporter-options': string;
@@ -46,7 +47,7 @@ const minimist = require('minimist');
4647
* }}
4748
*/
4849
const args = minimist(process.argv.slice(2), {
49-
string: ['grep', 'run', 'runGlob', 'reporter', 'reporter-options', 'waitServer', 'timeout', 'crash-reporter-directory', 'tfs', 'coveragePath', 'coverageFormats'],
50+
string: ['grep', 'run', 'runGlob', 'reporter', 'reporter-options', 'waitServer', 'timeout', 'crash-reporter-directory', 'tfs', 'coveragePath', 'coverageFormats', 'testSplit'],
5051
boolean: ['build', 'coverage', 'help', 'dev', 'per-test-coverage'],
5152
alias: {
5253
'grep': ['g', 'f'],
@@ -67,6 +68,7 @@ Options:
6768
--grep, -g, -f <pattern> only run tests matching <pattern>
6869
--run <file> only run tests from <file>
6970
--runGlob, --glob, --runGrep <file_pattern> only run tests matching <file_pattern>
71+
--testSplit <i>/<n> split tests into <n> parts and run the <i>th part
7072
--build run with build output (out-build)
7173
--coverage generate coverage report
7274
--per-test-coverage generate a per-test V8 coverage report, only valid with the full-json-stream reporter

test/unit/electron/renderer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ async function loadTestModules(opts) {
171171

172172
const pattern = opts.runGlob || _tests_glob;
173173
const files = await globAsync(pattern, { cwd: loadFn._out });
174-
const modules = files.map(file => file.replace(/\.js$/, ''));
174+
let modules = files.map(file => file.replace(/\.js$/, ''));
175+
if (opts.testSplit) {
176+
const [i, n] = opts.testSplit.split('/').map(Number);
177+
const chunkSize = Math.floor(modules.length / n);
178+
const start = (i - 1) * chunkSize;
179+
const end = i === n ? modules.length : i * chunkSize;
180+
modules = modules.slice(start, end);
181+
}
175182
return loadModules(modules);
176183
}
177184

0 commit comments

Comments
 (0)