@@ -9,6 +9,22 @@ const serialization = process.versions.node >= '12.16.0' ? 'advanced' : 'json';
99
1010const normalizePath = ( root , file ) => path . posix . normalize ( path . relative ( root , file ) ) ;
1111
12+ const compareStatObjects = ( a , b ) => {
13+ if ( a . file < b . file ) {
14+ return - 1 ;
15+ }
16+
17+ if ( a . file > b . file ) {
18+ return 1 ;
19+ }
20+
21+ if ( a . title < b . title ) {
22+ return - 1 ;
23+ }
24+
25+ return 1 ;
26+ } ;
27+
1228exports . fixture = async ( ...args ) => {
1329 const cwd = path . join ( path . dirname ( test . meta . file ) , 'fixtures' ) ;
1430 const running = execa . node ( cliPath , args , {
@@ -19,52 +35,65 @@ exports.fixture = async (...args) => {
1935 serialization
2036 } ) ;
2137
38+ // Besides buffering stderr, if this environment variable is set, also pipe
39+ // to stderr. This can be useful when debugging the tests.
40+ if ( process . env . DEBUG_TEST_AVA ) {
41+ running . stderr . pipe ( process . stderr ) ;
42+ }
43+
2244 const errors = new WeakMap ( ) ;
2345 const stats = {
2446 failed : [ ] ,
47+ passed : [ ] ,
2548 skipped : [ ] ,
49+ uncaughtExceptions : [ ] ,
2650 unsavedSnapshots : [ ] ,
27- passed : [ ] ,
2851 getError ( statObject ) {
2952 return errors . get ( statObject ) ;
3053 }
3154 } ;
3255
33- running . on ( 'message' , message => {
56+ running . on ( 'message' , statusEvent => {
3457 if ( serialization === 'json' ) {
35- message = v8 . deserialize ( Uint8Array . from ( message ) ) ;
58+ statusEvent = v8 . deserialize ( Uint8Array . from ( statusEvent ) ) ;
3659 }
3760
38- switch ( message . type ) {
61+ switch ( statusEvent . type ) {
3962 case 'selected-test' : {
40- if ( message . skip ) {
41- const { title, testFile} = message ;
63+ if ( statusEvent . skip ) {
64+ const { title, testFile} = statusEvent ;
4265 stats . skipped . push ( { title, file : normalizePath ( cwd , testFile ) } ) ;
4366 }
4467
4568 break ;
4669 }
4770
4871 case 'snapshot-error' : {
49- const { testFile} = message ;
72+ const { testFile} = statusEvent ;
5073 stats . unsavedSnapshots . push ( { file : normalizePath ( cwd , testFile ) } ) ;
5174 break ;
5275 }
5376
5477 case 'test-passed' : {
55- const { title, testFile} = message ;
78+ const { title, testFile} = statusEvent ;
5679 stats . passed . push ( { title, file : normalizePath ( cwd , testFile ) } ) ;
5780 break ;
5881 }
5982
6083 case 'test-failed' : {
61- const { title, testFile} = message ;
84+ const { title, testFile} = statusEvent ;
6285 const statObject = { title, file : normalizePath ( cwd , testFile ) } ;
63- errors . set ( statObject , message . err ) ;
86+ errors . set ( statObject , statusEvent . err ) ;
6487 stats . failed . push ( statObject ) ;
6588 break ;
6689 }
6790
91+ case 'uncaught-exception' : {
92+ const { message, name, stack} = statusEvent . err ;
93+ stats . uncaughtExceptions . push ( { message, name, stack} ) ;
94+ break ;
95+ }
96+
6897 default :
6998 break ;
7099 }
@@ -78,20 +107,9 @@ exports.fixture = async (...args) => {
78107 } catch ( error ) {
79108 throw Object . assign ( error , { stats} ) ;
80109 } finally {
81- stats . passed . sort ( ( a , b ) => {
82- if ( a . file < b . file ) {
83- return - 1 ;
84- }
85-
86- if ( a . file > b . file ) {
87- return 1 ;
88- }
89-
90- if ( a . title < b . title ) {
91- return - 1 ;
92- }
93-
94- return 1 ;
95- } ) ;
110+ stats . failed . sort ( compareStatObjects ) ;
111+ stats . passed . sort ( compareStatObjects ) ;
112+ stats . skipped . sort ( compareStatObjects ) ;
113+ stats . unsavedSnapshots . sort ( compareStatObjects ) ;
96114 }
97115} ;
0 commit comments