Skip to content

Commit

Permalink
--parallel=auto option
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Apr 26, 2023
1 parent 81462c5 commit 2d8ff6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const os = require('os');
const unWindows = require('./unWindows');

exports = module.exports = Command;
Expand Down Expand Up @@ -114,9 +115,15 @@ function parseOptions(argv, isWindows) {
} else if (arg.match("^--reporter=")) {
reporter = arg.match("^--reporter=(.*)")[1];
} else if (arg.match("^--parallel=(.*)")) {
numWorkers = parseFloat(arg.match("^--parallel=(.*)")[1]);
if (isNaN(numWorkers) || numWorkers < 2 || numWorkers !== Math.floor(numWorkers)) {
usageErrors.push('Argument to --parallel= must be an integer greater than 1');
const w = arg.match("^--parallel=(.*)")[1];
if (w === 'auto') {
// A reasonable default in most situations
numWorkers = os.cpus().length -1;
} else {
numWorkers = parseFloat(w);
if (isNaN(numWorkers) || numWorkers < 2 || numWorkers !== Math.floor(numWorkers)) {
usageErrors.push('Argument to --parallel= must be an integer greater than 1');
}
}
} else if (arg === '--') {
break;
Expand Down Expand Up @@ -291,6 +298,7 @@ function help(options) {

print('Options:');
print('%s\tRun in parallel with N workers', lPad('--parallel=N', 18));
print('%s\tRun in parallel with an automatically chosen number of workers', lPad('--parallel=auto', 18));
print('%s\tturn off color in spec output', lPad('--no-color', 18));
print('%s\tforce turn on color in spec output', lPad('--color', 18));
print('%s\tfilter specs to run only those that match the given string', lPad('--filter=', 18));
Expand Down
11 changes: 11 additions & 0 deletions spec/command_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const os = require('os');
const Command = require('../lib/command');
const Loader = require("../lib/loader");

Expand Down Expand Up @@ -398,6 +399,16 @@ describe('command', function() {
expect(this.parallelRunner.execute).toHaveBeenCalled();
});

it('sets the number of workers to 1 less than CPUs if --paralell is auto', async function() {
await this.command.run(['node', 'bin/jasmine.js', '--parallel=auto']);
expect(this.fakeJasmine.execute).not.toHaveBeenCalled();
expect(this.ParallelRunner).toHaveBeenCalledWith({
projectBaseDir,
numWorkers: os.cpus().length - 1
});
expect(this.parallelRunner.execute).toHaveBeenCalled();
});

it('shows usage if --parallel is not a number', async function() {
this.command.run(['node', 'bin/jasmine.js', '--parallel=twelve']);
expect(this.out.getOutput()).toContain(
Expand Down

0 comments on commit 2d8ff6c

Please sign in to comment.