Skip to content

Commit

Permalink
Add -J|--jobs-auto to automatically calculate cores
Browse files Browse the repository at this point in the history
This PR allows you to pass in -J which will automatically calculate the
number of cores using `os.cpus.length()`

Fixes: #342
Fixes: #344
  • Loading branch information
George Adams authored and isaacs committed Feb 7, 2017
1 parent 84df5ce commit f3f0a6b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/run.js
Expand Up @@ -13,6 +13,7 @@ var osHomedir = require('os-homedir')
var yaml = require('js-yaml')
var path = require('path')
var exists = require('fs-exists-cached').sync
var os = require('os');

var coverageServiceTest = process.env.COVERAGE_SERVICE_TEST === 'true'

Expand Down Expand Up @@ -158,6 +159,7 @@ function parseArgs (args, defaults) {

var singleOpts = {
j: 'jobs',
J: 'jobs-auto',
R: 'reporter',
t: 'timeout',
s: 'save'
Expand Down Expand Up @@ -240,6 +242,11 @@ function parseArgs (args, defaults) {
options.jobs = +val
continue

case '--jobs-auto':
val = os.cpus().length;
options.jobs = +val
continue

case '--coverage-report':
options.coverageReport = val || args[++i]
if (options.coverageReport === 'html')
Expand Down
6 changes: 6 additions & 0 deletions bin/usage.txt
Expand Up @@ -23,6 +23,12 @@ Options:
cannot be reported, and older TAP
parsers may get upset.

-J --jobs-auto Run test files in parallel (auto calculated)
Note that this causes tests to be run in
"buffered" mode, so line-by-line results
cannot be reported, and older TAP
parsers may get upset.

-c --color Use colors (Default for TTY)

-C --no-color Do not use colors (Default for non-TTY)
Expand Down
33 changes: 33 additions & 0 deletions test/runner-jobs.js
@@ -0,0 +1,33 @@
var t = require('../')
var spawn = require('child_process').spawn
var expect = {
jobs: require('os').cpus().length
}
var node = process.execPath
var run = require.resolve('../bin/run.js')

var args = [
['-J'],
['--jobs=99999', '-J'],
['--jobs-auto'],
['--jobs=99999', '--jobs-auto']
]

t.plan(args.length)

args.forEach(function (arg) {
t.test(arg.join(' '), function (t) {
var child = spawn(node, [run, '-J', '--dump-config'])
var out = ''
child.stdout.on('data', function (c) {
out += c
})
child.on('close', function (code, signal) {
t.notOk(code)
t.notOk(signal)
t.match(JSON.parse(out), expect)
t.end()
})
})
})

0 comments on commit f3f0a6b

Please sign in to comment.