1
1
/* eslint-disable no-console -- Logging is sort of the whole point here */
2
- import * as fs from "fs" ;
2
+ import * as fs from "fs/promises " ;
3
3
import type {
4
4
FullConfig ,
5
5
Suite ,
@@ -66,11 +66,15 @@ class CoderReporter implements Reporter {
66
66
this . timedOutTests . push ( test ) ;
67
67
}
68
68
69
+ const outputFile = `test-results/debug-pprof-goroutine-${ test . title } .txt` ;
70
+ await exportDebugPprof ( outputFile ) ;
71
+
69
72
const preserve = this . config ?. preserveOutput ;
70
73
const logOutput =
71
74
preserve === "always" ||
72
75
( result . status !== "passed" && preserve !== "never" ) ;
73
76
if ( logOutput ) {
77
+ console . log ( `Data from pprof has been saved to ${ outputFile } ` ) ;
74
78
console . log ( "==> Output" ) ;
75
79
const output = this . testOutput . get ( test . id ) ! ;
76
80
for ( const [ target , chunk ] of output ) {
@@ -92,8 +96,6 @@ class CoderReporter implements Reporter {
92
96
}
93
97
}
94
98
this . testOutput . delete ( test . id ) ;
95
-
96
- await exportDebugPprof ( test . title ) ;
97
99
}
98
100
99
101
onEnd ( result : FullResult ) {
@@ -114,28 +116,15 @@ class CoderReporter implements Reporter {
114
116
}
115
117
}
116
118
117
- const exportDebugPprof = async ( testName : string ) => {
118
- const url = "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1" ;
119
- const outputFile = `test-results/debug-pprof-goroutine-${ testName } .txt` ;
120
-
121
- await axios
122
- . get ( url )
123
- . then ( ( response ) => {
124
- if ( response . status !== 200 ) {
125
- throw new Error ( `Error: Received status code ${ response . status } ` ) ;
126
- }
119
+ const exportDebugPprof = async ( outputFile : string ) => {
120
+ const response = await axios . get (
121
+ "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1" ,
122
+ ) ;
123
+ if ( response . status !== 200 ) {
124
+ throw new Error ( `Error: Received status code ${ response . status } ` ) ;
125
+ }
127
126
128
- fs . writeFile ( outputFile , response . data , ( err ) => {
129
- if ( err ) {
130
- throw new Error ( `Error writing to ${ outputFile } : ${ err . message } ` ) ;
131
- } else {
132
- console . log ( `Data from ${ url } has been saved to ${ outputFile } ` ) ;
133
- }
134
- } ) ;
135
- } )
136
- . catch ( ( error ) => {
137
- throw new Error ( `Error: ${ error . message } ` ) ;
138
- } ) ;
127
+ await fs . writeFile ( outputFile , response . data ) ;
139
128
} ;
140
129
141
130
const reportError = ( error : TestError ) => {
0 commit comments