Skip to content
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
14 changes: 3 additions & 11 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/fixture/chalk-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import chalk from 'chalk';
import test from '../../';

test('should not support colors', t => {
t.false(chalk.enabled);
});
6 changes: 6 additions & 0 deletions test/fixture/chalk-enabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import chalk from 'chalk';
import test from '../../';

test('should support colors', t => {
t.true(chalk.enabled);
});
23 changes: 20 additions & 3 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});
});