Skip to content

Commit

Permalink
Don't highlight formatted values with --no-color
Browse files Browse the repository at this point in the history
Fixes #843
(#843 (comment)). Values
shouldn't be highlighted during formatting if colors are disabled.
  • Loading branch information
novemberborn committed Apr 3, 2017
1 parent 941c42e commit b581983
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/format-assert-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const chalk = require('chalk');
const diff = require('diff');
const DiffMatchPatch = require('diff-match-patch');
const indentString = require('indent-string');
const globals = require('./globals');

function formatValue(value, options) {
return prettyFormat(value, Object.assign({
callToJSON: false,
plugins: [reactTestPlugin],
highlight: true
highlight: globals.options.color !== false
}, options));
}
exports.formatValue = formatValue;
Expand Down
17 changes: 17 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const proxyquire = require('proxyquire');
const sinon = require('sinon');
const uniqueTempDir = require('unique-temp-dir');
const execa = require('execa');
const stripAnsi = require('strip-ansi');

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

Expand Down Expand Up @@ -525,3 +526,19 @@ test('snapshots work', t => {
});
});
});

test('--no-color disables formatting colors', t => {
execCli(['--no-color', '--verbose', 'formatting-color.js'], {dirname: 'fixture'}, (err, stdout, stderr) => {
t.ok(err);
t.is(stripAnsi(stderr), stderr);
t.end();
});
});

test('--color enables formatting colors', t => {
execCli(['--color', '--verbose', 'formatting-color.js'], {dirname: 'fixture'}, (err, stdout, stderr) => {
t.ok(err);
t.isNot(stripAnsi(stderr), stderr);
t.end();
});
});
5 changes: 5 additions & 0 deletions test/fixture/formatting-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from '../..';

test(t => {
t.deepEqual({foo: 1}, {foo: 2});
});

0 comments on commit b581983

Please sign in to comment.