Skip to content

Commit

Permalink
Merge pull request #29475 from storybookjs/version-non-patch-from-8.4…
Browse files Browse the repository at this point in the history
….0-beta.2

Release: Prerelease 8.4.0-beta.3
  • Loading branch information
kasperpeulen authored Oct 29, 2024
2 parents 88c7787 + 59ca5a0 commit 3863635
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 96 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.4.0-beta.3

- Addon Test: Only register testing module in Vite projects - [#29472](https://github.com/storybookjs/storybook/pull/29472), thanks @yannbf!

## 8.4.0-beta.2

- Addon Test: Adjust file exports to be ESM/CJS compatible - [#29471](https://github.com/storybookjs/storybook/pull/29471), thanks @valentinpalkovic!
Expand Down
190 changes: 96 additions & 94 deletions code/addons/test/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,104 +80,106 @@ const RelativeTime = ({ timestamp, testCount }: { timestamp: Date; testCount: nu
};

addons.register(ADDON_ID, (api) => {
const openAddonPanel = () => {
api.setSelectedPanel(PANEL_ID);
api.togglePanel(true);
};

addons.add(TEST_PROVIDER_ID, {
type: Addon_TypesEnum.experimental_TEST_PROVIDER,
runnable: true,
watchable: true,

name: 'Component tests',
title: ({ crashed, failed }) =>
crashed || failed ? 'Component tests failed' : 'Component tests',
description: ({ failed, running, watching, progress, crashed, details }) => {
const [isModalOpen, setIsModalOpen] = useState(false);

const errorMessage = details?.error?.message;

let message: string | React.ReactNode = 'Not run';

if (running) {
message = progress
? `Testing... ${progress.numPassedTests}/${progress.numTotalTests}`
: 'Starting...';
} else if (failed && !errorMessage) {
message = 'Component tests failed';
} else if (crashed || (failed && errorMessage)) {
message = (
if (globalThis.STORYBOOK_BUILDER?.includes('vite')) {
const openAddonPanel = () => {
api.setSelectedPanel(PANEL_ID);
api.togglePanel(true);
};

addons.add(TEST_PROVIDER_ID, {
type: Addon_TypesEnum.experimental_TEST_PROVIDER,
runnable: true,
watchable: true,

name: 'Component tests',
title: ({ crashed, failed }) =>
crashed || failed ? 'Component tests failed' : 'Component tests',
description: ({ failed, running, watching, progress, crashed, details }) => {
const [isModalOpen, setIsModalOpen] = useState(false);

const errorMessage = details?.error?.message;

let message: string | React.ReactNode = 'Not run';

if (running) {
message = progress
? `Testing... ${progress.numPassedTests}/${progress.numTotalTests}`
: 'Starting...';
} else if (failed && !errorMessage) {
message = 'Component tests failed';
} else if (crashed || (failed && errorMessage)) {
message = (
<>
<LinkComponent
isButton
onClick={() => {
setIsModalOpen(true);
}}
>
{details?.error?.name || 'View full error'}
</LinkComponent>
</>
);
} else if (progress?.finishedAt) {
message = (
<RelativeTime
timestamp={new Date(progress.finishedAt)}
testCount={progress.numTotalTests}
/>
);
} else if (watching) {
message = 'Watching for file changes';
}

return (
<>
<LinkComponent
isButton
onClick={() => {
setIsModalOpen(true);
{message}
<GlobalErrorModal
error={errorMessage}
open={isModalOpen}
onClose={() => {
setIsModalOpen(false);
}}
>
{details?.error?.name || 'View full error'}
</LinkComponent>
onRerun={() => {
setIsModalOpen(false);
api
.getChannel()
.emit(TESTING_MODULE_RUN_ALL_REQUEST, { providerId: TEST_PROVIDER_ID });
}}
/>
</>
);
} else if (progress?.finishedAt) {
message = (
<RelativeTime
timestamp={new Date(progress.finishedAt)}
testCount={progress.numTotalTests}
/>
);
} else if (watching) {
message = 'Watching for file changes';
}

return (
<>
{message}
<GlobalErrorModal
error={errorMessage}
open={isModalOpen}
onClose={() => {
setIsModalOpen(false);
}}
onRerun={() => {
setIsModalOpen(false);
api
.getChannel()
.emit(TESTING_MODULE_RUN_ALL_REQUEST, { providerId: TEST_PROVIDER_ID });
}}
/>
</>
);
},

mapStatusUpdate: (state) =>
Object.fromEntries(
(state.details.testResults || []).flatMap((testResult) =>
testResult.results
.map(({ storyId, status, testRunId, ...rest }) => {
if (storyId) {
const statusObject: API_StatusObject = {
title: 'Component tests',
status: statusMap[status],
description:
'failureMessages' in rest && rest.failureMessages?.length
? rest.failureMessages.join('\n')
: '',
data: {
testRunId,
},
onClick: openAddonPanel,
};
return [storyId, statusObject];
}
})
.filter(Boolean)
)
),
} as Addon_TestProviderType<{
testResults: TestResult[];
error?: { message: string; name: string };
}>);
},

mapStatusUpdate: (state) =>
Object.fromEntries(
(state.details.testResults || []).flatMap((testResult) =>
testResult.results
.map(({ storyId, status, testRunId, ...rest }) => {
if (storyId) {
const statusObject: API_StatusObject = {
title: 'Component tests',
status: statusMap[status],
description:
'failureMessages' in rest && rest.failureMessages?.length
? rest.failureMessages.join('\n')
: '',
data: {
testRunId,
},
onClick: openAddonPanel,
};
return [storyId, statusObject];
}
})
.filter(Boolean)
)
),
} as Addon_TestProviderType<{
testResults: TestResult[];
error?: { message: string; name: string };
}>);
}

addons.add(PANEL_ID, {
type: types.PANEL,
Expand Down
3 changes: 2 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,6 @@
"Dependency Upgrades"
]
]
}
},
"deferredNextVersion": "8.4.0-beta.3"
}
2 changes: 1 addition & 1 deletion docs/versions/next.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"8.4.0-beta.2","info":{"plain":"- Addon Test: Adjust file exports to be ESM/CJS compatible - [#29471](https://github.com/storybookjs/storybook/pull/29471), thanks @valentinpalkovic!\n- Core: Show tooltip on filter toggles to clarify their purpose - [#29447](https://github.com/storybookjs/storybook/pull/29447), thanks @ghengeveld!\n- Webpack: Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack - [#29235](https://github.com/storybookjs/storybook/pull/29235), thanks @kasperpeulen!"}}
{"version":"8.4.0-beta.3","info":{"plain":"- Addon Test: Only register testing module in Vite projects - [#29472](https://github.com/storybookjs/storybook/pull/29472), thanks @yannbf!"}}

0 comments on commit 3863635

Please sign in to comment.