1
- import fs from "fs" ;
1
+ import * as fs from "fs" ;
2
2
import type {
3
3
FullConfig ,
4
4
Suite ,
@@ -8,52 +8,85 @@ import type {
8
8
Reporter ,
9
9
} from "@playwright/test/reporter" ;
10
10
import axios from "axios" ;
11
+ import type { Writable } from "stream" ;
12
+
13
+ const testOutput = new Map < string , Array < [ Writable , string ] > > ( ) ;
11
14
12
15
class CoderReporter implements Reporter {
13
16
onBegin ( config : FullConfig , suite : Suite ) {
14
17
// eslint-disable-next-line no-console -- Helpful for debugging
15
- console . log ( `Starting the run with ${ suite . allTests ( ) . length } tests` ) ;
18
+ console . log ( `==> Running ${ suite . allTests ( ) . length } tests` ) ;
16
19
}
17
20
18
21
onTestBegin ( test : TestCase ) {
22
+ testOutput . set ( test . id , [ ] ) ;
19
23
// eslint-disable-next-line no-console -- Helpful for debugging
20
- console . log ( `Starting test ${ test . title } ` ) ;
24
+ console . log ( `==> Starting test ${ test . title } ` ) ;
21
25
}
22
26
23
- onStdOut ( chunk : string , test : TestCase , _ : TestResult ) : void {
24
- // eslint-disable-next-line no-console -- Helpful for debugging
25
- console . log (
26
- `[stdout] [${ test ? test . title : "unknown" } ]: ${ chunk . replace (
27
- / \n $ / g,
28
- "" ,
29
- ) } `,
30
- ) ;
27
+ onStdOut ( chunk : string , test ?: TestCase , _ ?: TestResult ) : void {
28
+ if ( ! test ) {
29
+ // console.log(`[stdout] [unknown] ${chunk.replace(/\n$/g, "")}`);
30
+ return ;
31
+ }
32
+ testOutput . get ( test . id ) ! . push ( [ process . stdout , chunk ] ) ;
31
33
}
32
34
33
- onStdErr ( chunk : string , test : TestCase , _ : TestResult ) : void {
34
- // eslint-disable-next-line no-console -- Helpful for debugging
35
- console . log (
36
- `[stderr] [${ test ? test . title : "unknown" } ]: ${ chunk . replace (
37
- / \n $ / g,
38
- "" ,
39
- ) } `,
40
- ) ;
35
+ onStdErr ( chunk : string , test ?: TestCase , _ ?: TestResult ) : void {
36
+ if ( ! test ) {
37
+ // console.error(`[stderr] [unknown] ${chunk.replace(/\n$/g, "")}`);
38
+ return ;
39
+ }
40
+ testOutput . get ( test . id ) ! . push ( [ process . stderr , chunk ] ) ;
41
41
}
42
42
43
43
async onTestEnd ( test : TestCase , result : TestResult ) {
44
44
// eslint-disable-next-line no-console -- Helpful for debugging
45
- console . log ( `Finished test ${ test . title } : ${ result . status } ` ) ;
45
+ console . log ( `==> Finished test ${ test . title } : ${ result . status } ` ) ;
46
46
47
47
if ( result . status !== "passed" ) {
48
- // eslint-disable-next-line no-console -- Helpful for debugging
49
- console . log ( "errors" , result . errors , "attachments" , result . attachments ) ;
48
+ // eslint-disable-next-line no-console -- Debugging output
49
+ console . log ( "==> Output" ) ;
50
+ const output = testOutput . get ( test . id ) ! ;
51
+ for ( const [ target , chunk ] of output ) {
52
+ target . write ( `${ chunk . replace ( / \n $ / g, "" ) } \n` ) ;
53
+ }
54
+ testOutput . delete ( test . id ) ;
55
+
56
+ if ( result . errors . length > 0 ) {
57
+ // eslint-disable-next-line no-console -- Debugging output
58
+ console . log ( "==> Errors" ) ;
59
+ for ( const error of result . errors ) {
60
+ if ( error . location ) {
61
+ console . log ( `${ error . location . file } :${ error . location . line } :` ) ;
62
+ }
63
+ if ( error . snippet ) {
64
+ console . log ( error . snippet ) ;
65
+ }
66
+
67
+ if ( error . message ) {
68
+ console . log ( error . message ) ;
69
+ } else {
70
+ console . log ( error ) ;
71
+ }
72
+ }
73
+ }
74
+
75
+ if ( result . attachments . length > 0 ) {
76
+ // eslint-disable-next-line no-console -- Debugging output
77
+ console . log ( "==> Attachments" ) ;
78
+ for ( const attachment of result . attachments ) {
79
+ // eslint-disable-next-line no-console -- Debugging output
80
+ console . log ( attachment ) ;
81
+ }
82
+ }
50
83
}
51
84
await exportDebugPprof ( test . title ) ;
52
85
}
53
86
54
87
onEnd ( result : FullResult ) {
55
88
// eslint-disable-next-line no-console -- Helpful for debugging
56
- console . log ( `Finished the run: ${ result . status } ` ) ;
89
+ console . log ( `==> Tests ${ result . status } ` ) ;
57
90
}
58
91
}
59
92
0 commit comments