diff --git a/lib/fork.js b/lib/fork.js index e24340c8c..51fd0ecdf 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -4,8 +4,17 @@ const path = require('path'); const fs = require('fs'); const Promise = require('bluebird'); const debug = require('debug')('ava'); +const supportsColor = require('supports-color'); const AvaError = require('./ava-error'); +const colorLevels = { + 0: 'false', + 1: 'true', + 2: '256', + 3: '16m' +}; +const currentColorLevel = colorLevels[supportsColor.level]; + if (fs.realpathSync(__filename) !== __filename) { console.warn('WARNING: `npm link ava` and the `--preserve-symlink` flag are incompatible. We have detected that AVA is linked via `npm link`, and that you are using either an early version of Node 6, or the `--preserve-symlink` flag. This breaks AVA. You should upgrade to Node 6.2.0+, avoid the `--preserve-symlink` flag, or avoid using `npm link ava`.'); } @@ -34,7 +43,8 @@ module.exports = (file, opts, execArgv) => { } : false }, opts); - const args = [JSON.stringify(opts), opts.color ? '--color' : '--no-color'].concat(opts.workerArgv); + const colorArg = opts.color ? `--color=${currentColorLevel}` : '--no-color'; + const args = [JSON.stringify(opts), colorArg].concat(opts.workerArgv); const ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), args, { cwd: opts.projectDir,