@@ -7,7 +7,7 @@ const os = require("os");
7
7
const failingHookRegExp = / ^ ( .* ) " ( b e f o r e | a f t e r ) ( a l l | e a c h ) " h o o k $ / ;
8
8
9
9
/**
10
- * .failed-tests.json reporter
10
+ * .failed-tests reporter
11
11
*
12
12
* @typedef {Object } ReporterOptions
13
13
* @property {string } [file]
@@ -25,7 +25,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
25
25
if ( ! runner ) return ;
26
26
27
27
const reporterOptions = this . reporterOptions = options . reporterOptions || { } ;
28
- if ( reporterOptions . file === undefined ) reporterOptions . file = ".failed-tests.json " ;
28
+ if ( reporterOptions . file === undefined ) reporterOptions . file = ".failed-tests" ;
29
29
if ( reporterOptions . keepFailed === undefined ) reporterOptions . keepFailed = false ;
30
30
if ( reporterOptions . reporter ) {
31
31
/** @type {Mocha.ReporterConstructor } */
@@ -70,7 +70,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
70
70
* @param {(err?: NodeJS.ErrnoException) => void } done
71
71
*/
72
72
static writeFailures ( file , passes , failures , keepFailed , done ) {
73
- const failingTests = new Set ( readTests ( ) ) ;
73
+ const failingTests = new Set ( fs . existsSync ( file ) ? readTests ( ) : undefined ) ;
74
74
const possiblyPassingSuites = /**@type {Set<string> }*/ ( new Set ( ) ) ;
75
75
76
76
// Remove tests that are now passing and track suites that are now
@@ -104,8 +104,9 @@ class FailedTestsReporter extends Mocha.reporters.Base {
104
104
if ( failingTests . size > 0 ) {
105
105
const failed = Array
106
106
. from ( failingTests )
107
- . sort ( ) ;
108
- fs . writeFile ( file , JSON . stringify ( { grep : failed } , undefined , " " ) , "utf8" , done ) ;
107
+ . sort ( )
108
+ . join ( os . EOL ) ;
109
+ fs . writeFile ( file , failed , "utf8" , done ) ;
109
110
}
110
111
else if ( ! keepFailed && fs . existsSync ( file ) ) {
111
112
fs . unlink ( file , done ) ;
@@ -115,12 +116,10 @@ class FailedTestsReporter extends Mocha.reporters.Base {
115
116
}
116
117
117
118
function readTests ( ) {
118
- try {
119
- return JSON . parse ( fs . readFileSync ( file , "utf8" ) ) . grep ;
120
- }
121
- catch {
122
- return undefined ;
123
- }
119
+ return fs . readFileSync ( file , "utf8" )
120
+ . split ( / \r ? \n / g)
121
+ . map ( line => line . trim ( ) )
122
+ . filter ( line => line . length > 0 ) ;
124
123
}
125
124
}
126
125
0 commit comments