Skip to content

Commit 0c491d9

Browse files
authored
test: add scenario name to e2e performance metrics (#1872)
1 parent 0d4daf6 commit 0c491d9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/e2e-tests/src/hooks/scenarioTagRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import { Logger } from '../support/logger';
1111
const monitor = PidMonitor.getInstance();
1212

1313
// eslint-disable-next-line no-unused-vars
14-
Before(async () => {
14+
Before(async (scenario) => {
1515
if (String(process.env.SERVICE_WORKER_LOGS) === 'true') {
1616
await consoleManager.startLogsCollection();
1717
}
1818
if (browser.isChromium) {
1919
const pidMonitorInitialized = await monitor.init();
2020
if (pidMonitorInitialized) {
21+
monitor.setScenarioName(scenario.pickle.name);
2122
monitor.start();
2223
} else {
2324
Logger.warn('PID monitor not initialized. Skipping start.');

packages/e2e-tests/src/support/PidMonitor.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ interface UsageData {
1414
memory: number;
1515
}
1616

17+
interface OutputData {
18+
scenarioName: string | undefined;
19+
data: UsageData[];
20+
}
21+
1722
class PidMonitor {
1823
private static _instance: PidMonitor;
1924

2025
private pid?: number;
2126
private readonly intervalMs: number;
2227
private _data: UsageData[] = [];
2328
private timer?: ReturnType<typeof setInterval>;
29+
private scenarioName: string | undefined = undefined;
2430

2531
private constructor(intervalMs = 1000) {
2632
this.intervalMs = intervalMs;
@@ -33,6 +39,10 @@ class PidMonitor {
3339
return PidMonitor._instance;
3440
}
3541

42+
public setScenarioName(name: string): void {
43+
this.scenarioName = name;
44+
}
45+
3646
public get data(): UsageData[] {
3747
return this._data;
3848
}
@@ -91,6 +101,7 @@ class PidMonitor {
91101

92102
public clear(): void {
93103
this._data = [];
104+
this.scenarioName = undefined;
94105
}
95106

96107
public saveToFile(filePath: string): void {
@@ -99,7 +110,13 @@ class PidMonitor {
99110
if (!fs.existsSync(dir)) {
100111
fs.mkdirSync(dir, { recursive: true });
101112
}
102-
fs.writeFileSync(filePath, JSON.stringify(this._data, undefined, 2), 'utf-8');
113+
114+
const output: OutputData = {
115+
scenarioName: this.scenarioName,
116+
data: this._data
117+
};
118+
119+
fs.writeFileSync(filePath, JSON.stringify(output, undefined, 2), 'utf-8');
103120
} catch (error) {
104121
Logger.error(`Failed to save data to file: ${error}`);
105122
}

0 commit comments

Comments
 (0)