diff --git a/test/cli.js b/test/cli.js index abbf6e841..102ba4d9e 100644 --- a/test/cli.js +++ b/test/cli.js @@ -5,23 +5,15 @@ const childProcess = require('child_process'); const test = require('tap').test; const getStream = require('get-stream'); const figures = require('figures'); -const chalk = require('chalk'); const mkdirp = require('mkdirp'); const touch = require('touch'); const proxyquire = require('proxyquire'); const sinon = require('sinon'); const uniqueTempDir = require('unique-temp-dir'); const execa = require('execa'); -const colors = require('../lib/colors'); const cliPath = path.join(__dirname, '../cli.js'); -// For some reason chalk is disabled by default -chalk.enabled = true; -for (const key of Object.keys(colors)) { - colors[key].enabled = true; -} - function execCli(args, opts, cb) { let dirname; let env; @@ -74,12 +66,12 @@ function execCli(args, opts, cb) { } test('disallow invalid babel config shortcuts', t => { - execCli(['--color', 'es2015.js'], {dirname: 'fixture/invalid-babel-config'}, (err, stdout, stderr) => { + execCli(['es2015.js'], {dirname: 'fixture/invalid-babel-config'}, (err, stdout, stderr) => { t.ok(err); let expectedOutput = '\n '; - expectedOutput += colors.error(figures.cross) + ' Unexpected Babel configuration for AVA.'; - expectedOutput += ' See ' + chalk.underline('https://github.com/avajs/ava#es2015-support') + ' for allowed values.'; + expectedOutput += figures.cross + ' Unexpected Babel configuration for AVA.'; + expectedOutput += ' See https://github.com/avajs/ava#es2015-support for allowed values.'; expectedOutput += '\n'; t.is(stderr, expectedOutput); diff --git a/test/fixture/chalk-disabled.js b/test/fixture/chalk-disabled.js new file mode 100644 index 000000000..21caccf3e --- /dev/null +++ b/test/fixture/chalk-disabled.js @@ -0,0 +1,6 @@ +import chalk from 'chalk'; +import test from '../../'; + +test('should not support colors', t => { + t.false(chalk.enabled); +}); diff --git a/test/fixture/chalk-enabled.js b/test/fixture/chalk-enabled.js new file mode 100644 index 000000000..a7e0ff640 --- /dev/null +++ b/test/fixture/chalk-enabled.js @@ -0,0 +1,6 @@ +import chalk from 'chalk'; +import test from '../../'; + +test('should support colors', t => { + t.true(chalk.enabled); +}); diff --git a/test/fork.js b/test/fork.js index 256e65fca..266e50652 100644 --- a/test/fork.js +++ b/test/fork.js @@ -7,15 +7,15 @@ const CachingPrecompiler = require('../lib/caching-precompiler'); const cacheDir = path.join(__dirname, '../node_modules/.cache/ava'); const precompiler = new CachingPrecompiler({path: cacheDir}); -function fork(testPath) { +function fork(testPath, options) { const hash = precompiler.precompileFile(testPath); const precompiled = {}; precompiled[testPath] = hash; - return _fork(testPath, { + return _fork(testPath, Object.assign({ cacheDir, precompiled - }); + }, options)); } function fixture(name) { @@ -125,3 +125,20 @@ test('babelrc is ignored', t => { t.end(); }); }); + +test('color support is initialized correctly', t => { + t.plan(1); + + return Promise.all([ + fork(fixture('chalk-enabled.js'), {color: true}).run({}), + fork(fixture('chalk-disabled.js'), {color: false}).run({}), + fork(fixture('chalk-disabled.js'), {}).run({}) + ]).then(info => { + info.forEach(info => { + if (info.stats.failCount > 0) { + throw new Error(`${info.file} failed`); + } + }); + t.is(info.length, 3); + }); +});