Skip to content

Commit

Permalink
Merge d6dae69 into 20f5746
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski authored Oct 22, 2024
2 parents 20f5746 + d6dae69 commit 0713374
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/compare/src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function compareResults(current: MeasureResults, baseline: MeasureResults | null
const compared: CompareEntry[] = [];
const added: AddedEntry[] = [];
const removed: RemovedEntry[] = [];
const currentWarnings: string[] = [];

names.forEach((name) => {
const currentEntry = current.entries[name];
Expand All @@ -149,6 +150,10 @@ function compareResults(current: MeasureResults, baseline: MeasureResults | null
} else if (baselineEntry) {
removed.push({ name, type: baselineEntry.type, baseline: baselineEntry });
}

if (currentEntry?.warnings) {
currentWarnings.push(...currentEntry.warnings.map((warning) => `${currentEntry.name}: ${warning}`));
}
});

const withCurrent = [...compared, ...added];
Expand All @@ -171,7 +176,7 @@ function compareResults(current: MeasureResults, baseline: MeasureResults | null
return {
metadata: { current: current.metadata, baseline: baseline?.metadata },
errors,
warnings,
warnings: [...warnings, ...currentWarnings],
significant,
meaningless,
countChanged,
Expand Down
2 changes: 2 additions & 0 deletions packages/compare/src/type-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ export const MeasureEntryScheme = z.object({
counts: z.array(z.number()),

issues: z.optional(RenderIssuesScheme),

warnings: z.optional(z.array(z.string())),
});
7 changes: 6 additions & 1 deletion packages/measure/src/measure-renders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async function measureRendersInternal(
applyRenderPolyfills();

const runResults: RunResult[] = [];
const warnings: string[] = [];
let hasTooLateRender = false;

const renderJsonTrees: ElementJsonTree[] = [];
Expand Down Expand Up @@ -121,8 +122,11 @@ async function measureRendersInternal(

if (hasTooLateRender) {
const testName = expect.getState().currentTestName;
warnings.push(
'Test still re-renders after test scenario finished. Update your code to wait for all renders to finish.'
);
logger.warn(
`test "${testName}" still re-renders after test scenario finished.\n\nPlease update your code to wait for all renders to finish.`
`test "${testName}" still re-renders after test scenario finished.\n\nUpdate your code to wait for all renders to finish.`
);
}

Expand All @@ -134,6 +138,7 @@ async function measureRendersInternal(
initialUpdateCount: initialRenderCount - 1,
redundantUpdates: detectRedundantUpdates(renderJsonTrees, initialRenderCount),
},
warnings: warnings.length > 0 ? warnings : undefined,
};
}

Expand Down
6 changes: 6 additions & 0 deletions packages/measure/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export interface MeasureResults {

/** Array of measured render/execution count for each run */
counts: number[];

/** Errors that occurred during the test */
errors?: string[];

/** Warnings that occurred during the test */
warnings?: string[];
}

export interface MeasureRendersResults extends MeasureResults {
Expand Down
15 changes: 13 additions & 2 deletions test-apps/native/src/OtherTest.perf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const AsyncComponent = () => {
};

jest.setTimeout(600_000);
test('Other Component', async () => {
test('AsyncComponent', async () => {
const scenario = async () => {
const button = screen.getByText('Action');

Expand All @@ -38,7 +38,7 @@ test('Other Component', async () => {
await measureRenders(<AsyncComponent />, { scenario, runs: 10 });
});

test('Other Component 20 run', async () => {
test('AsyncComponent 20 runs', async () => {
const scenario = async () => {
const button = screen.getByText('Action');

Expand All @@ -49,3 +49,14 @@ test('Other Component 20 run', async () => {

await measureRenders(<AsyncComponent />, { scenario, runs: 20 });
});

test('AsyncComponent - no wait', async () => {
const scenario = async () => {
const button = screen.getByText('Action');

fireEvent.press(button);
fireEvent.press(button);
};

await measureRenders(<AsyncComponent />, { scenario });
});

0 comments on commit 0713374

Please sign in to comment.