From a5c975d1dd46b28dab96f3e235d629331f94f457 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Wed, 2 Dec 2026 10:50:44 +0100 Subject: [PATCH 1/2] feat: don't report scenarios from skipped test files as removed Co-Authored-By: Claude Opus 5.5 --- .changeset/skip-unselected-scenarios.md | 6 +++ docusaurus/docs/methodology.md | 2 +- packages/compare/src/compare.ts | 12 +++++- packages/compare/src/test/compare.test.ts | 51 ++++++++++++++++++++++- packages/compare/src/type-schemas.ts | 3 ++ packages/measure/src/output.ts | 11 ++++- 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 .changeset/skip-unselected-scenarios.md diff --git a/.changeset/skip-unselected-scenarios.md b/.changeset/skip-unselected-scenarios.md new file mode 100644 index 000000000..4d419e71a --- /dev/null +++ b/.changeset/skip-unselected-scenarios.md @@ -0,0 +1,6 @@ +--- +"@callstack/reassure-compare": minor +"@callstack/reassure-measure": minor +--- + +feat: don't report scenarios from test files the current run skipped as removed. `reassure-measure` records each scenario's test file (`testPath`), and `reassure-compare` reports a baseline scenario as removed only when the current run ran its test file or the file no longer exists. diff --git a/docusaurus/docs/methodology.md b/docusaurus/docs/methodology.md index a5f62b20a..81c605e1d 100644 --- a/docusaurus/docs/methodology.md +++ b/docusaurus/docs/methodology.md @@ -40,7 +40,7 @@ Looking at the example you can notice that test scenarios can be assigned to cer - **Meaningless Changes To Duration** shows test scenarios where the performance change is not statistically significant - **Changes To Count** shows test scenarios where the render or execution count did change - **Added Scenarios** shows test scenarios which do not exist in the baseline measurements -- **Removed Scenarios** shows test scenarios which do not exist in the current measurements +- **Removed Scenarios** shows test scenarios which do not exist in the current measurements. A scenario is not listed when the current run skipped its test file and the file still exists, e.g. when you pass Jest a subset of test files ### Render issues (experimental) diff --git a/packages/compare/src/compare.ts b/packages/compare/src/compare.ts index 2b70a2ee8..1b5a01e1d 100644 --- a/packages/compare/src/compare.ts +++ b/packages/compare/src/compare.ts @@ -127,12 +127,13 @@ export function loadFile(path: string): MeasureResults { /** * Compare results between baseline and current entries and categorize. */ -function compareResults(current: MeasureResults, baseline: MeasureResults | null): CompareResult { +export function compareResults(current: MeasureResults, baseline: MeasureResults | null): CompareResult { // Unique test scenario names const names = [...new Set([...Object.keys(current.entries), ...Object.keys(baseline?.entries || {})])]; const compared: CompareEntry[] = []; const added: AddedEntry[] = []; const removed: RemovedEntry[] = []; + const currentTestPaths = new Set(Object.values(current.entries).map((entry) => entry.testPath)); names.forEach((name) => { const currentEntry = current.entries[name]; @@ -148,6 +149,15 @@ function compareResults(current: MeasureResults, baseline: MeasureResults | null stability: calculateEntryStability(currentEntry), }); } else if (baselineEntry) { + // The current run didn't run this scenario's test file, which still exists, so the scenario wasn't removed. + if ( + baselineEntry.testPath && + !currentTestPaths.has(baselineEntry.testPath) && + fsSync.existsSync(baselineEntry.testPath) + ) { + return; + } + removed.push({ name, type: baselineEntry.type, diff --git a/packages/compare/src/test/compare.test.ts b/packages/compare/src/test/compare.test.ts index c05d312a4..3f20cf652 100644 --- a/packages/compare/src/test/compare.test.ts +++ b/packages/compare/src/test/compare.test.ts @@ -1,4 +1,5 @@ -import { loadFile } from '../compare'; +import { compareResults, loadFile } from '../compare'; +import type { MeasureEntry } from '../types'; describe('loadFile', () => { it('should load results file with header', () => { @@ -53,3 +54,51 @@ describe('loadFile', () => { expect(types).toEqual(['render', 'render', 'function']); }); }); + +describe('compareResults', () => { + const entry = (name: string, testPath?: string): MeasureEntry => ({ + name, + testPath, + type: 'render', + runs: 1, + meanDuration: 10, + stdevDuration: 0, + durations: [10], + meanCount: 1, + stdevCount: 0, + counts: [1], + }); + + it('should list only scenarios whose test file ran or no longer exists as removed', () => { + // Given a baseline with scenarios from this (existing) test file, from a deleted test file and without testPath, + // and a current run that only ran a different test file + const existingFile = __filename; + const deletedFile = `${__dirname}/deleted.perf-test.tsx`; + const baseline = { + entries: { + 'skipped file': entry('skipped file', existingFile), + 'deleted file': entry('deleted file', deletedFile), + 'legacy entry': entry('legacy entry'), + }, + }; + const current = { entries: { 'other file': entry('other file', 'other.perf-test.tsx') } }; + + // When comparing the results + const result = compareResults(current, baseline); + + // Then the scenario from the existing but skipped file is not reported as removed + expect(result.removed.map((item) => item.name)).toEqual(['deleted file', 'legacy entry']); + }); + + it('should list a scenario as removed when the current run ran its test file', () => { + // Given a baseline scenario whose test file the current run also ran + const baseline = { entries: { 'old scenario': entry('old scenario', __filename) } }; + const current = { entries: { 'new scenario': entry('new scenario', __filename) } }; + + // When comparing the results + const result = compareResults(current, baseline); + + // Then the scenario is reported as removed, because its file ran without it + expect(result.removed.map((item) => item.name)).toEqual(['old scenario']); + }); +}); diff --git a/packages/compare/src/type-schemas.ts b/packages/compare/src/type-schemas.ts index d93f84a51..91332201f 100644 --- a/packages/compare/src/type-schemas.ts +++ b/packages/compare/src/type-schemas.ts @@ -22,6 +22,9 @@ export const MeasureEntryScheme = z.object({ /** Name of the test scenario. */ name: z.string(), + /** Test file the scenario is in, relative to the working directory. */ + testPath: z.string().optional(), + /** Type of the measured characteristic (render, function execution, async function execution). */ type: z.enum(['render', 'function', 'async function']).default('render'), diff --git a/packages/measure/src/output.ts b/packages/measure/src/output.ts index 5e748ad6a..67be9e457 100644 --- a/packages/measure/src/output.ts +++ b/packages/measure/src/output.ts @@ -1,4 +1,5 @@ import * as fs from 'fs/promises'; +import * as path from 'path'; import * as logger from '@callstack/reassure-logger'; import { config } from './config'; import type { MeasureResults, MeasureType } from './types'; @@ -8,8 +9,14 @@ export async function writeTestStats( type: MeasureType, outputFilePath: string = config.outputFile ): Promise { - const name = expect.getState().currentTestName; - const line = JSON.stringify({ name, type, ...stats }) + '\n'; + const { currentTestName: name, testPath } = expect.getState(); + const line = + JSON.stringify({ + name, + type, + testPath: testPath ? path.relative(process.cwd(), testPath) : undefined, + ...stats, + }) + '\n'; try { await fs.appendFile(outputFilePath, line); From 9b1577fc06150bc284e46b3ab8296c4d8e768e8c Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Wed, 2 Dec 2026 10:55:40 +0100 Subject: [PATCH 2/2] test: cover all removed-scenario cases in one compareResults test Co-Authored-By: Claude Opus 5.5 --- packages/compare/src/test/compare.test.ts | 29 +++++------------------ 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/packages/compare/src/test/compare.test.ts b/packages/compare/src/test/compare.test.ts index 3f20cf652..2bcc11446 100644 --- a/packages/compare/src/test/compare.test.ts +++ b/packages/compare/src/test/compare.test.ts @@ -69,36 +69,19 @@ describe('compareResults', () => { counts: [1], }); - it('should list only scenarios whose test file ran or no longer exists as removed', () => { - // Given a baseline with scenarios from this (existing) test file, from a deleted test file and without testPath, - // and a current run that only ran a different test file - const existingFile = __filename; - const deletedFile = `${__dirname}/deleted.perf-test.tsx`; + it('should not list scenarios from existing test files the current run skipped as removed', () => { const baseline = { entries: { - 'skipped file': entry('skipped file', existingFile), - 'deleted file': entry('deleted file', deletedFile), - 'legacy entry': entry('legacy entry'), + 'skipped file': entry('skipped file', `${__dirname}/../compare.ts`), + 'deleted file': entry('deleted file', `${__dirname}/deleted.perf-test.tsx`), + 'ran file': entry('ran file', __filename), + 'no test path': entry('no test path'), }, }; - const current = { entries: { 'other file': entry('other file', 'other.perf-test.tsx') } }; - - // When comparing the results - const result = compareResults(current, baseline); - - // Then the scenario from the existing but skipped file is not reported as removed - expect(result.removed.map((item) => item.name)).toEqual(['deleted file', 'legacy entry']); - }); - - it('should list a scenario as removed when the current run ran its test file', () => { - // Given a baseline scenario whose test file the current run also ran - const baseline = { entries: { 'old scenario': entry('old scenario', __filename) } }; const current = { entries: { 'new scenario': entry('new scenario', __filename) } }; - // When comparing the results const result = compareResults(current, baseline); - // Then the scenario is reported as removed, because its file ran without it - expect(result.removed.map((item) => item.name)).toEqual(['old scenario']); + expect(result.removed.map((item) => item.name)).toEqual(['deleted file', 'no test path', 'ran file']); }); });