-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reporter.ts
49 lines (41 loc) · 1.27 KB
/
Reporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { defaultEnvironment } from "../defaults.js";
import { Command, Environment, Project } from "../types.js";
export interface CollectResult {
projectName: Project["name"];
commandName: Command["name"];
totalsInMs: number[];
}
export interface ReportResult extends CollectResult {
environment: Environment;
}
export abstract class Reporter {
private readonly environment: Environment;
constructor(environment: Partial<Environment>) {
this.environment = { ...defaultEnvironment };
Object.entries(environment).forEach(([key, value]) => {
if (value !== undefined) this.environment[key] = value;
});
}
getEnvironment() {
return this.environment;
}
/**
* Called after each command, for each registered reporters
*/
async reportResult(collectResult: CollectResult): Promise<void> {
await this.processResult?.({
...collectResult,
environment: this.getEnvironment(),
});
}
/**
* Called after each command, for each registered reporters
*/
processResult?(reportResult: ReportResult): void | Promise<void>;
/**
* Called after all projects are benchmarked, for each registered reporters
*
* Will not be called when benchmarking with `--run-indefinitely` flag
*/
afterAll?(): void | Promise<void>;
}