diff --git a/bin/run.js b/bin/run.js index d107e18fc..11f97c670 100755 --- a/bin/run.js +++ b/bin/run.js @@ -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' @@ -158,6 +159,7 @@ function parseArgs (args, defaults) { var singleOpts = { j: 'jobs', + J: 'jobs-auto', R: 'reporter', t: 'timeout', s: 'save' @@ -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') diff --git a/bin/usage.txt b/bin/usage.txt index 42489cd9b..fe9f82530 100644 --- a/bin/usage.txt +++ b/bin/usage.txt @@ -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) diff --git a/test/runner-jobs.js b/test/runner-jobs.js new file mode 100644 index 000000000..2c49a2bc3 --- /dev/null +++ b/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() + }) + }) +}) +