diff --git a/.changeset/skip-unselected-scenarios.md b/.changeset/skip-unselected-scenarios.md new file mode 100644 index 00000000..4d419e71 --- /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 a5f62b20..81c605e1 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 2b70a2ee..1b5a01e1 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 c05d312a..2bcc1144 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,34 @@ 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 not list scenarios from existing test files the current run skipped as removed', () => { + const baseline = { + entries: { + '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: { 'new scenario': entry('new scenario', __filename) } }; + + const result = compareResults(current, baseline); + + expect(result.removed.map((item) => item.name)).toEqual(['deleted file', 'no test path', 'ran file']); + }); +}); diff --git a/packages/compare/src/type-schemas.ts b/packages/compare/src/type-schemas.ts index d93f84a5..91332201 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 5e748ad6..67be9e45 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);