@@ -6,6 +6,7 @@ const Crypto = require('crypto');
6
6
const Fs = require ( 'fs' ) ;
7
7
const Os = require ( 'os' ) ;
8
8
const Path = require ( 'path' ) ;
9
+ const Rimraf = require ( 'rimraf' ) ;
9
10
const Stream = require ( 'stream' ) ;
10
11
const Code = require ( 'code' ) ;
11
12
const _Lab = require ( '../test_runner' ) ;
@@ -101,8 +102,7 @@ describe('Reporter', () => {
101
102
102
103
expect ( code ) . to . equal ( 0 ) ;
103
104
expect ( output ) . to . equal ( Fs . readFileSync ( filename ) . toString ( ) ) ;
104
- Fs . unlinkSync ( filename ) ;
105
- Fs . rmdirSync ( folder ) ;
105
+ Rimraf . sync ( folder ) ;
106
106
} ) ;
107
107
108
108
it ( 'outputs to a file with output is passed as an array and reporter is an array' , async ( ) => {
@@ -683,7 +683,7 @@ describe('Reporter', () => {
683
683
} ) ;
684
684
685
685
const { output } = await Lab . report ( script , { reporter : 'console' , progress : 0 , output : false , assert : false } ) ;
686
- expect ( output ) . to . match ( / ^ \u001b \[ 3 2 m 1 t e s t s c o m p l e t e \u001b \[ 0 m \n T e s t d u r a t i o n : \d + m s \n \u001b \[ 3 2 m N o g l o b a l v a r i a b l e l e a k s d e t e c t e d \u001b \[ 0 m \n \n $ / ) ;
686
+ expect ( output ) . to . match ( / ^ ( \u001b \[ 3 2 m ) ? 1 t e s t s c o m p l e t e ( \u001b \[ 0 m ) ? \n T e s t d u r a t i o n : \d + m s \n ( \u001b \[ 3 2 m ) ? N o g l o b a l v a r i a b l e l e a k s d e t e c t e d ( \u001b \[ 0 m ) ? \n \n $ / ) ;
687
687
} ) ;
688
688
689
689
it ( 'generates a report with verbose progress' , async ( ) => {
@@ -695,7 +695,7 @@ describe('Reporter', () => {
695
695
} ) ;
696
696
697
697
const { output } = await Lab . report ( script , { reporter : 'console' , progress : 2 , output : false , assert : false } ) ;
698
- expect ( output ) . to . match ( / ^ t e s t \n \u001b \[ 3 2 m [ ✔ √ ] \u001b \[ 0 m \u001b \[ 9 0 m 1 \) w o r k s \( \d + m s \) \u001b \[ 0 m \n \n \n \u001b \[ 3 2 m 1 t e s t s c o m p l e t e \u001b \[ 0 m \n T e s t d u r a t i o n : \d + m s \n \u001b \[ 3 2 m N o g l o b a l v a r i a b l e l e a k s d e t e c t e d \u001b \[ 0 m \n \n $ / ) ;
698
+ expect ( output ) . to . match ( / ^ t e s t \n ( \u001b \[ 3 2 m ) ? [ ✔ √ ] ( \u001b \[ 0 m ) ? ( \u001b \[ 9 0 m ) ? 1 \) w o r k s \( \d + m s \) ( \u001b \[ 0 m ) ? \n \n \n ( \u001b \[ 3 2 m ) ? 1 t e s t s c o m p l e t e ( \u001b \[ 0 m ) ? \n T e s t d u r a t i o n : \d + m s \n ( \u001b \[ 3 2 m ) ? N o g l o b a l v a r i a b l e l e a k s d e t e c t e d ( \u001b \[ 0 m ) ? \n \n $ / ) ;
699
699
} ) ;
700
700
701
701
it ( 'generates a report with verbose progress with experiments with same named tests' , async ( ) => {
@@ -763,7 +763,7 @@ describe('Reporter', () => {
763
763
} ) ;
764
764
765
765
const { output } = await Lab . report ( script , { reporter : 'console' , progress : 2 , assert : Code , output : false } ) ;
766
- expect ( output ) . to . match ( / ^ t e s t \n \u001b \[ 3 2 m [ ✔ √ ] \u001b \[ 0 m \u001b \[ 9 0 m 1 \) w o r k s \( \d + m s a n d \d + a s s e r t i o n s \) \u001b \[ 0 m \n \n \n \u001b \[ 3 2 m 1 t e s t s c o m p l e t e \u001b \[ 0 m \n T e s t d u r a t i o n : \d + m s \n A s s e r t i o n s c o u n t \: \d + \( v e r b o s i t y \: \d + \. \d + \) \n \u001b \[ 3 2 m N o g l o b a l v a r i a b l e l e a k s d e t e c t e d \u001b \[ 0 m \n \n $ / ) ;
766
+ expect ( output ) . to . match ( / ^ t e s t \n ( \u001b \[ 3 2 m ) ? [ ✔ √ ] ( \u001b \[ 0 m ) ? ( \u001b \[ 9 0 m ) ? 1 \) w o r k s \( \d + m s a n d \d + a s s e r t i o n s \) ( \u001b \[ 0 m ) ? \n \n \n ( \u001b \[ 3 2 m ) ? 1 t e s t s c o m p l e t e ( \u001b \[ 0 m ) ? \n T e s t d u r a t i o n : \d + m s \n A s s e r t i o n s c o u n t \: \d + \( v e r b o s i t y \: \d + \. \d + \) \n ( \u001b \[ 3 2 m ) ? N o g l o b a l v a r i a b l e l e a k s d e t e c t e d ( \u001b \[ 0 m ) ? \n \n $ / ) ;
767
767
} ) ;
768
768
769
769
it ( 'generates a report with verbose progress that displays well on windows' , async ( ) => {
@@ -999,6 +999,39 @@ describe('Reporter', () => {
999
999
expect ( output ) . to . match ( / ^ \n \n \. \n \n 1 t e s t s c o m p l e t e \n T e s t d u r a t i o n : \d + m s \n N o g l o b a l v a r i a b l e l e a k s d e t e c t e d \n \n $ / ) ;
1000
1000
} ) ;
1001
1001
1002
+ it ( 'includes colors when terminal supports' , async ( ) => {
1003
+
1004
+ delete require . cache [ require . resolve ( 'supports-color' ) ] ;
1005
+ const orig = {
1006
+ isTTY : process . stdout . isTTY ,
1007
+ env : process . env
1008
+ } ;
1009
+ process . stdout . isTTY = true ;
1010
+ process . env = {
1011
+ FORCE_COLOR : true
1012
+ } ;
1013
+
1014
+ const script = Lab . script ( ) ;
1015
+ script . experiment ( 'test' , ( ) => {
1016
+
1017
+ script . test ( 'works' , ( ) => {
1018
+
1019
+ expect ( true ) . to . equal ( true ) ;
1020
+ } ) ;
1021
+ script . test ( 'does not work' , ( ) => {
1022
+
1023
+ expect ( true ) . to . equal ( false ) ;
1024
+ } ) ;
1025
+ } ) ;
1026
+
1027
+ const { code, output } = await Lab . report ( script , { reporter : 'console' , output : false , assert : false } ) ;
1028
+
1029
+ process . stdout . isTTY = orig . isTTY ;
1030
+ process . env = orig . env ;
1031
+ expect ( code ) . to . equal ( 1 ) ;
1032
+ expect ( output ) . to . match ( / ^ \n \n \. \u001b \[ 3 1 m x \u001b \[ 0 m \n \n F a i l e d t e s t s : \n \n 2 \) t e s t d o e s n o t w o r k : \n \n \u001b \[ 3 7 ; 4 1 m a c t u a l \u001b \[ 0 m \u001b \[ 3 0 ; 4 2 m e x p e c t e d \u001b \[ 0 m \n \n \u001b \[ 3 7 ; 4 1 m t r u e \u001b \[ 0 m \u001b \[ 3 0 ; 4 2 m f a l s e \u001b \[ 0 m \n \n \u001b \[ 3 3 m E x p e c t e d t r u e t o e q u a l s p e c i f i e d v a l u e : f a l s e \u001b \[ 0 m \n \n .* ?\u001b \[ 0 m \n \n \n \u001b \[ 3 1 m 1 o f 2 t e s t s f a i l e d \u001b \[ 0 m \n T e s t d u r a t i o n : \d + m s \n \u001b \[ 3 2 m N o g l o b a l v a r i a b l e l e a k s d e t e c t e d \u001b \[ 0 m \n \n $ / ) ;
1033
+ } ) ;
1034
+
1002
1035
it ( 'displays custom error messages in expect' , async ( ) => {
1003
1036
1004
1037
const script = Lab . script ( ) ;
0 commit comments