Skip to content

Commit 13b214b

Browse files
committed
Do not clobber forked process color level.
Chalk uses `supports-color` to determine what color level should be rendered. However, currently our parent `ava` process uses that to colorize its output, however, when we fork our test processes we clobber the color configuration that `supports-color` uses to determine the level (see https://github.com/chalk/supports-color/blob/master/index.js#L37-L42) This PR carries the current color level through to the forked processes so if they log output that is colorized it will remain so with the same fidelity of colors as the parent ava process.
1 parent a1afbe3 commit 13b214b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/fork.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ const path = require('path');
44
const fs = require('fs');
55
const Promise = require('bluebird');
66
const debug = require('debug')('ava');
7+
const supportsColor = require('supports-color');
78
const AvaError = require('./ava-error');
89

10+
const colorLevels = {
11+
0: 'false',
12+
1: 'true',
13+
2: '256',
14+
3: '16m'
15+
};
16+
const currentColorLevel = colorLevels[supportsColor.level];
17+
918
if (fs.realpathSync(__filename) !== __filename) {
1019
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`.');
1120
}
@@ -36,7 +45,9 @@ module.exports = (file, opts, execArgv) => {
3645
} : false
3746
}, opts);
3847

39-
const args = [JSON.stringify(opts), opts.color ? '--color' : '--no-color'];
48+
const colorArg = opts.color ? `--color=${currentColorLevel}` : '--no-color';
49+
50+
const args = [JSON.stringify(opts), colorArg];
4051

4152
const ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), args, {
4253
cwd: opts.projectDir,

0 commit comments

Comments
 (0)