Skip to content

Commit b581983

Browse files
committed
Don't highlight formatted values with --no-color
Fixes #843 (#843 (comment)). Values shouldn't be highlighted during formatting if colors are disabled.
1 parent 941c42e commit b581983

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/format-assert-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const chalk = require('chalk');
55
const diff = require('diff');
66
const DiffMatchPatch = require('diff-match-patch');
77
const indentString = require('indent-string');
8+
const globals = require('./globals');
89

910
function formatValue(value, options) {
1011
return prettyFormat(value, Object.assign({
1112
callToJSON: false,
1213
plugins: [reactTestPlugin],
13-
highlight: true
14+
highlight: globals.options.color !== false
1415
}, options));
1516
}
1617
exports.formatValue = formatValue;

test/cli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const proxyquire = require('proxyquire');
1111
const sinon = require('sinon');
1212
const uniqueTempDir = require('unique-temp-dir');
1313
const execa = require('execa');
14+
const stripAnsi = require('strip-ansi');
1415

1516
const cliPath = path.join(__dirname, '../cli.js');
1617

@@ -525,3 +526,19 @@ test('snapshots work', t => {
525526
});
526527
});
527528
});
529+
530+
test('--no-color disables formatting colors', t => {
531+
execCli(['--no-color', '--verbose', 'formatting-color.js'], {dirname: 'fixture'}, (err, stdout, stderr) => {
532+
t.ok(err);
533+
t.is(stripAnsi(stderr), stderr);
534+
t.end();
535+
});
536+
});
537+
538+
test('--color enables formatting colors', t => {
539+
execCli(['--color', '--verbose', 'formatting-color.js'], {dirname: 'fixture'}, (err, stdout, stderr) => {
540+
t.ok(err);
541+
t.isNot(stripAnsi(stderr), stderr);
542+
t.end();
543+
});
544+
});

test/fixture/formatting-color.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../..';
2+
3+
test(t => {
4+
t.deepEqual({foo: 1}, {foo: 2});
5+
});

0 commit comments

Comments
 (0)