Skip to content

Commit

Permalink
Merge pull request #30072 from storybookjs/clear-coverage-on-start
Browse files Browse the repository at this point in the history
Addon Test: Clear coverage data when starting or watching
  • Loading branch information
ghengeveld authored Dec 17, 2024
2 parents 438393a + fc703e2 commit 91d1b03
Showing 1 changed file with 64 additions and 53 deletions.
117 changes: 64 additions & 53 deletions code/addons/test/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,64 +73,75 @@ addons.register(ADDON_ID, (api) => {
},

stateUpdater: (state, update) => {
if (!update.details?.testResults) {
return;
const updated = {
...state,
...update,
details: { ...state.details, ...update.details },
};

if ((!state.running && update.running) || (!state.watching && update.watching)) {
// Clear coverage data when starting test run or enabling watch mode
delete updated.details.coverageSummary;
}

(async () => {
await api.experimental_updateStatus(
TEST_PROVIDER_ID,
Object.fromEntries(
update.details.testResults.flatMap((testResult) =>
testResult.results
.filter(({ storyId }) => storyId)
.map(({ storyId, status, testRunId, ...rest }) => [
storyId,
{
title: 'Component tests',
status: statusMap[status],
description:
'failureMessages' in rest && rest.failureMessages
? rest.failureMessages.join('\n')
: '',
data: { testRunId },
onClick: openTestsPanel,
sidebarContextMenu: false,
} satisfies API_StatusObject,
])
if (update.details?.testResults) {
(async () => {
await api.experimental_updateStatus(
TEST_PROVIDER_ID,
Object.fromEntries(
update.details.testResults.flatMap((testResult) =>
testResult.results
.filter(({ storyId }) => storyId)
.map(({ storyId, status, testRunId, ...rest }) => [
storyId,
{
title: 'Component tests',
status: statusMap[status],
description:
'failureMessages' in rest && rest.failureMessages
? rest.failureMessages.join('\n')
: '',
data: { testRunId },
onClick: openTestsPanel,
sidebarContextMenu: false,
} satisfies API_StatusObject,
])
)
)
)
);
);

await api.experimental_updateStatus(
'storybook/addon-a11y/test-provider',
Object.fromEntries(
update.details.testResults.flatMap((testResult) =>
testResult.results
.filter(({ storyId }) => storyId)
.map(({ storyId, testRunId, reports }) => {
const a11yReport = reports.find((r: any) => r.type === 'a11y');
return [
storyId,
a11yReport
? ({
title: 'Accessibility tests',
description: '',
status: statusMap[a11yReport.status],
data: { testRunId },
onClick: () => {
api.setSelectedPanel('storybook/a11y/panel');
api.togglePanel(true);
},
sidebarContextMenu: false,
} satisfies API_StatusObject)
: null,
];
})
await api.experimental_updateStatus(
'storybook/addon-a11y/test-provider',
Object.fromEntries(
update.details.testResults.flatMap((testResult) =>
testResult.results
.filter(({ storyId }) => storyId)
.map(({ storyId, testRunId, reports }) => {
const a11yReport = reports.find((r: any) => r.type === 'a11y');
return [
storyId,
a11yReport
? ({
title: 'Accessibility tests',
description: '',
status: statusMap[a11yReport.status],
data: { testRunId },
onClick: () => {
api.setSelectedPanel('storybook/a11y/panel');
api.togglePanel(true);
},
sidebarContextMenu: false,
} satisfies API_StatusObject)
: null,
];
})
)
)
)
);
})();
);
})();
}

return updated;
},
} as Addon_TestProviderType<Details, Config>);
}
Expand Down

0 comments on commit 91d1b03

Please sign in to comment.