Skip to content

Don't highlight formatted values with --no-color #1334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ exports.run = () => {
--verbose, -v Enable verbose output
--no-cache Disable the transpiler cache
--no-power-assert Disable Power Assert
--color Force color output
--no-color Disable color output
--match, -m Only run tests with matching title (Can be repeated)
--watch, -w Re-run tests when tests and source files change
Expand Down Expand Up @@ -74,7 +75,7 @@ exports.run = () => {
],
default: {
cache: conf.cache,
color: 'color' in conf ? conf.color : true,
color: 'color' in conf ? conf.color : require('supports-color') !== false,
concurrency: conf.concurrency,
failFast: conf.failFast,
init: conf.init,
Expand Down
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"stack-utils": "^1.0.0",
"strip-ansi": "^3.0.1",
"strip-bom-buf": "^1.0.0",
"supports-color": "^3.2.3",
"time-require": "^0.1.2",
"unique-temp-dir": "^1.0.0",
"update-notifier": "^2.1.0"
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ $ ava --help
--verbose, -v Enable verbose output
--no-cache Disable the transpiler cache
--no-power-assert Disable Power Assert
--color Force color output
--no-color Disable color output
--match, -m Only run tests with matching title (Can be repeated)
--watch, -w Re-run tests when tests and source files change
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});
});