Skip to content

Commit 2d8ff6c

Browse files
committed
--parallel=auto option
1 parent 81462c5 commit 2d8ff6c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/command.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const fs = require('fs');
3+
const os = require('os');
34
const unWindows = require('./unWindows');
45

56
exports = module.exports = Command;
@@ -114,9 +115,15 @@ function parseOptions(argv, isWindows) {
114115
} else if (arg.match("^--reporter=")) {
115116
reporter = arg.match("^--reporter=(.*)")[1];
116117
} else if (arg.match("^--parallel=(.*)")) {
117-
numWorkers = parseFloat(arg.match("^--parallel=(.*)")[1]);
118-
if (isNaN(numWorkers) || numWorkers < 2 || numWorkers !== Math.floor(numWorkers)) {
119-
usageErrors.push('Argument to --parallel= must be an integer greater than 1');
118+
const w = arg.match("^--parallel=(.*)")[1];
119+
if (w === 'auto') {
120+
// A reasonable default in most situations
121+
numWorkers = os.cpus().length -1;
122+
} else {
123+
numWorkers = parseFloat(w);
124+
if (isNaN(numWorkers) || numWorkers < 2 || numWorkers !== Math.floor(numWorkers)) {
125+
usageErrors.push('Argument to --parallel= must be an integer greater than 1');
126+
}
120127
}
121128
} else if (arg === '--') {
122129
break;
@@ -291,6 +298,7 @@ function help(options) {
291298

292299
print('Options:');
293300
print('%s\tRun in parallel with N workers', lPad('--parallel=N', 18));
301+
print('%s\tRun in parallel with an automatically chosen number of workers', lPad('--parallel=auto', 18));
294302
print('%s\tturn off color in spec output', lPad('--no-color', 18));
295303
print('%s\tforce turn on color in spec output', lPad('--color', 18));
296304
print('%s\tfilter specs to run only those that match the given string', lPad('--filter=', 18));

spec/command_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const os = require('os');
34
const Command = require('../lib/command');
45
const Loader = require("../lib/loader");
56

@@ -398,6 +399,16 @@ describe('command', function() {
398399
expect(this.parallelRunner.execute).toHaveBeenCalled();
399400
});
400401

402+
it('sets the number of workers to 1 less than CPUs if --paralell is auto', async function() {
403+
await this.command.run(['node', 'bin/jasmine.js', '--parallel=auto']);
404+
expect(this.fakeJasmine.execute).not.toHaveBeenCalled();
405+
expect(this.ParallelRunner).toHaveBeenCalledWith({
406+
projectBaseDir,
407+
numWorkers: os.cpus().length - 1
408+
});
409+
expect(this.parallelRunner.execute).toHaveBeenCalled();
410+
});
411+
401412
it('shows usage if --parallel is not a number', async function() {
402413
this.command.run(['node', 'bin/jasmine.js', '--parallel=twelve']);
403414
expect(this.out.getOutput()).toContain(

0 commit comments

Comments
 (0)