Skip to content

Commit 5695cab

Browse files
committed
fix: capture live run metrics in PerfJsonReporter instead of re-reading baselines
1 parent c7ac99c commit 5695cab

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

packages/@react-native-windows/perf-testing/src/ci/PerfJsonReporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class PerfJsonReporter {
7878
const suites: SuiteResult[] = [];
7979

8080
for (const suite of results.testResults) {
81-
// Load the snapshot file for this test suite (written by toMatchPerfSnapshot)
81+
// Use live run metrics captured during the test run
8282
const {file: snapshotFilePath} = SnapshotManager.getSnapshotPath(
8383
suite.testFilePath,
8484
);
85-
const snapshots = SnapshotManager.load(snapshotFilePath);
85+
const snapshots = SnapshotManager.getRunMetrics(snapshotFilePath) ?? {};
8686

8787
const passed = suite.testResults.filter(
8888
t => t.status === 'passed',

packages/@react-native-windows/perf-testing/src/matchers/snapshotManager.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,27 @@ export type SnapshotFile = Record<string, SnapshotEntry>;
2626

2727
/**
2828
* Manages reading and writing of perf snapshot files.
29+
* Also maintains an in-memory registry of current-run metrics
30+
* so the CI reporter can access live results
2931
*/
3032
export class SnapshotManager {
33+
/** In-memory store of metrics captured during the current test run. */
34+
private static readonly _runMetrics: Map<string, SnapshotFile> = new Map();
35+
static recordRunMetric(
36+
snapshotFilePath: string,
37+
key: string,
38+
entry: SnapshotEntry,
39+
): void {
40+
if (!SnapshotManager._runMetrics.has(snapshotFilePath)) {
41+
SnapshotManager._runMetrics.set(snapshotFilePath, {});
42+
}
43+
SnapshotManager._runMetrics.get(snapshotFilePath)![key] = entry;
44+
}
45+
46+
static getRunMetrics(snapshotFilePath: string): SnapshotFile | null {
47+
return SnapshotManager._runMetrics.get(snapshotFilePath) ?? null;
48+
}
49+
3150
static getSnapshotPath(testFilePath: string): {
3251
dir: string;
3352
file: string;

packages/@react-native-windows/perf-testing/src/matchers/toMatchPerfSnapshot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ expect.extend({
168168

169169
const threshold: PerfThreshold = {...DEFAULT_THRESHOLD, ...customThreshold};
170170

171+
// Always record the live metrics for the CI reporter
172+
SnapshotManager.recordRunMetric(snapshotFile, snapshotKey, {
173+
metrics: received,
174+
threshold,
175+
capturedAt: new Date().toISOString(),
176+
});
177+
171178
// UPDATE MODE or FIRST RUN: write new baseline
172179
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
173180
if (isUpdateMode || !baseline) {

0 commit comments

Comments
 (0)