Skip to content

Commit 4f28403

Browse files
committed
fix: update profile reporter
1 parent 1ac5d5a commit 4f28403

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/reporters/profile.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1+
import chalk from 'chalk';
2+
3+
import { colorize } from '../utils/cli';
14
import Profiler from '../profiler';
25

36
export default class ProfileReporter {
4-
constructor() {
5-
this.profiler = new Profiler();
7+
progress(context) {
8+
if (!context.profiler) {
9+
context.profiler = new Profiler();
10+
}
11+
12+
context.profiler.onRequest(context.state.request);
613
}
714

8-
allDone() {
9-
const formattedStats = this.profiler.getFormattedStats();
10-
process.stderr.write(`\n${formattedStats}\n`);
15+
done(context) {
16+
if (context.profiler) {
17+
context.state.profile = context.profiler.getFormattedStats();
18+
delete context.profiler;
19+
}
1120
}
1221

13-
progress(context) {
14-
this.profiler.onRequest(context.state.request);
22+
allDone(context) {
23+
let str = '';
24+
25+
for (const state of context.statesArray) {
26+
const color = colorize(state.color);
27+
28+
if (state.profile) {
29+
str +=
30+
color(`\nProfile results for ${chalk.bold(state.name)}\n`) +
31+
`\n${state.profile}\n`;
32+
delete state.profile;
33+
}
34+
}
35+
36+
process.stderr.write(str);
1537
}
1638
}

0 commit comments

Comments
 (0)