File tree 4 files changed +36
-9
lines changed
4 files changed +36
-9
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
+ // tap runs tests in a non-TTY environment, that's why supports-color will return false.
3
+ // Since we're going to check for colored output in our tests, we need to override that.
4
+ process . env . FORCE_COLOR = true ;
5
+
2
6
const fs = require ( 'fs' ) ;
3
7
const path = require ( 'path' ) ;
4
8
const childProcess = require ( 'child_process' ) ;
@@ -16,12 +20,6 @@ const colors = require('../lib/colors');
16
20
17
21
const cliPath = path . join ( __dirname , '../cli.js' ) ;
18
22
19
- // For some reason chalk is disabled by default
20
- chalk . enabled = true ;
21
- for ( const key of Object . keys ( colors ) ) {
22
- colors [ key ] . enabled = true ;
23
- }
24
-
25
23
function execCli ( args , opts , cb ) {
26
24
let dirname ;
27
25
let env ;
Original file line number Diff line number Diff line change
1
+ import chalk from 'chalk' ;
2
+ import test from '../../' ;
3
+
4
+ test ( 'should not support colors' , t => {
5
+ t . false ( chalk . enabled ) ;
6
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import chalk from 'chalk' ;
2
+ import test from '../../' ;
3
+
4
+ test ( 'should support colors' , t => {
5
+ t . true ( chalk . enabled ) ;
6
+ } ) ;
Original file line number Diff line number Diff line change @@ -7,15 +7,15 @@ const CachingPrecompiler = require('../lib/caching-precompiler');
7
7
const cacheDir = path . join ( __dirname , '../node_modules/.cache/ava' ) ;
8
8
const precompiler = new CachingPrecompiler ( { path : cacheDir } ) ;
9
9
10
- function fork ( testPath ) {
10
+ function fork ( testPath , options ) {
11
11
const hash = precompiler . precompileFile ( testPath ) ;
12
12
const precompiled = { } ;
13
13
precompiled [ testPath ] = hash ;
14
14
15
- return _fork ( testPath , {
15
+ return _fork ( testPath , Object . assign ( {
16
16
cacheDir,
17
17
precompiled
18
- } ) ;
18
+ } , options ) ) ;
19
19
}
20
20
21
21
function fixture ( name ) {
@@ -125,3 +125,20 @@ test('babelrc is ignored', t => {
125
125
t . end ( ) ;
126
126
} ) ;
127
127
} ) ;
128
+
129
+ test ( 'color support is initialized correctly' , t => {
130
+ t . plan ( 1 ) ;
131
+
132
+ return Promise . all ( [
133
+ fork ( fixture ( 'chalk-enabled.js' ) , { color : true } ) . run ( { } ) ,
134
+ fork ( fixture ( 'chalk-disabled.js' ) , { color : false } ) . run ( { } ) ,
135
+ fork ( fixture ( 'chalk-disabled.js' ) , { } ) . run ( { } )
136
+ ] ) . then ( info => {
137
+ info . forEach ( info => {
138
+ if ( info . stats . failCount > 0 ) {
139
+ throw new Error ( `${ info . file } failed` ) ;
140
+ }
141
+ } ) ;
142
+ t . is ( info . length , 3 ) ;
143
+ } ) ;
144
+ } ) ;
You can’t perform that action at this time.
0 commit comments