Skip to content

Commit 9f84384

Browse files
committed
fix: reporter writes current measured values via temp files instead of baselines
1 parent 6890c86 commit 9f84384

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 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)
82-
const {file: snapshotFilePath} = SnapshotManager.getSnapshotPath(
81+
// Load the CURRENT measured values written by toMatchPerfSnapshot
82+
// to a temp file (not the baselines — those are for comparison only)
83+
const snapshots = SnapshotManager.loadCurrentRun(
8384
suite.testFilePath,
8485
);
85-
const snapshots = SnapshotManager.load(snapshotFilePath);
8686

8787
const passed = suite.testResults.filter(
8888
t => t.status === 'passed',
@@ -136,6 +136,11 @@ export class PerfJsonReporter {
136136
);
137137

138138
console.log(`\n📊 Perf results written to: ${this.outputFile}`);
139+
140+
// Clean up temp files written by test workers
141+
for (const suite of results.testResults) {
142+
SnapshotManager.cleanCurrentRun(suite.testFilePath);
143+
}
139144
}
140145
}
141146

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,50 @@ export class SnapshotManager {
7272
static buildKey(testName: string): string {
7373
return `${testName} 1`;
7474
}
75+
76+
/**
77+
* Path to the temp file where the current run's measured values are stored.
78+
* Written by toMatchPerfSnapshot (worker), read by PerfJsonReporter (main).
79+
*/
80+
static getCurrentRunPath(testFilePath: string): string {
81+
const testDir = path.dirname(testFilePath);
82+
const snapshotDir = path.join(testDir, '__perf_snapshots__');
83+
return path.join(
84+
snapshotDir,
85+
`${path.basename(testFilePath)}.perf-current.json`,
86+
);
87+
}
88+
89+
/**
90+
* Record a single test's measured values to the current-run temp file.
91+
* Called from the test worker process by toMatchPerfSnapshot.
92+
*/
93+
static recordCurrentRun(
94+
testFilePath: string,
95+
key: string,
96+
entry: SnapshotEntry,
97+
): void {
98+
const currentPath = this.getCurrentRunPath(testFilePath);
99+
const existing = this.load(currentPath);
100+
existing[key] = entry;
101+
this.save(currentPath, existing);
102+
}
103+
104+
/**
105+
* Load the current run's measured values from the temp file.
106+
* Called from the main process by PerfJsonReporter.
107+
*/
108+
static loadCurrentRun(testFilePath: string): SnapshotFile {
109+
return this.load(this.getCurrentRunPath(testFilePath));
110+
}
111+
112+
/**
113+
* Remove the current-run temp file (cleanup after reporting).
114+
*/
115+
static cleanCurrentRun(testFilePath: string): void {
116+
const p = this.getCurrentRunPath(testFilePath);
117+
if (fs.existsSync(p)) {
118+
fs.unlinkSync(p);
119+
}
120+
}
75121
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ expect.extend({
192192
};
193193
}
194194

195+
// Record current measured values for the CI reporter
196+
SnapshotManager.recordCurrentRun(testPath, snapshotKey, {
197+
metrics: received,
198+
threshold,
199+
capturedAt: new Date().toISOString(),
200+
});
201+
195202
// COMPARE MODE
196203
const {errors, warnings} = compareAgainstBaseline(
197204
received,

0 commit comments

Comments
 (0)