mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
strip out junit logic (for now)
This commit is contained in:
parent
81c6a13ca2
commit
f90d77cfea
@ -64,10 +64,6 @@ const config: StorybookConfig = {
|
||||
directory: '../addons/viewport/template/stories',
|
||||
titlePrefix: 'addons/viewport',
|
||||
},
|
||||
{
|
||||
directory: '../addons/vitest/src',
|
||||
titlePrefix: 'addons/vitest',
|
||||
},
|
||||
{
|
||||
directory: '../addons/toolbars/template/stories',
|
||||
titlePrefix: 'addons/toolbars',
|
||||
@ -92,7 +88,6 @@ const config: StorybookConfig = {
|
||||
'@storybook/addon-storysource',
|
||||
'@storybook/addon-designs',
|
||||
'@storybook/addon-a11y',
|
||||
'@storybook/experimental-addon-vitest',
|
||||
'@chromatic-com/storybook',
|
||||
],
|
||||
previewAnnotations: [
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Storybook Addon Vitest
|
||||
# Storybook Addon Vitest (Experimental)
|
||||
|
||||
Addon to integrate Vitest test results with Storybook.
|
||||
|
@ -1,8 +0,0 @@
|
||||
export default { render: () => null };
|
||||
|
||||
export const Default = {};
|
||||
export const Success = {};
|
||||
export const Pending = {};
|
||||
export const Warn = {};
|
||||
export const Error = {};
|
||||
export const Unknown = {};
|
@ -1,82 +1,5 @@
|
||||
import { global } from '@storybook/global';
|
||||
import type { IndexEntry, StoryId, StoryIndex } from '@storybook/types';
|
||||
import { addons, type API } from 'storybook/internal/manager-api';
|
||||
|
||||
import { ADDON_ID } from './constants';
|
||||
|
||||
const lastStoryIds = new Set<StoryId>();
|
||||
|
||||
const loadReport = async (api: API) => {
|
||||
const indexPromise: Promise<StoryIndex> = fetch('index.json').then((res) => res.json());
|
||||
const reportPromise = fetch('vitest-report.xml').then((res) => res.text());
|
||||
|
||||
// Clear old statuses to avoid stale data
|
||||
api.experimental_updateStatus(
|
||||
ADDON_ID,
|
||||
Object.fromEntries(Array.from(lastStoryIds).map((id) => [id, null]))
|
||||
);
|
||||
lastStoryIds.clear();
|
||||
|
||||
const [index, report] = await Promise.all([indexPromise, reportPromise]).catch(() => []);
|
||||
if (!index || !report) return;
|
||||
|
||||
const openInteractionsPanel = () => {
|
||||
api.setSelectedPanel('storybook/interactions/panel');
|
||||
api.togglePanel(true);
|
||||
};
|
||||
|
||||
const storiesByPath = Object.values(index.entries).reduce(
|
||||
(acc, story) => {
|
||||
acc[story.importPath] = acc[story.importPath] || {};
|
||||
acc[story.importPath][story.name] = story;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<IndexEntry['importPath'], Record<IndexEntry['name'], IndexEntry>>
|
||||
);
|
||||
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(report, 'text/xml');
|
||||
|
||||
await api.experimental_updateStatus(
|
||||
ADDON_ID,
|
||||
Object.fromEntries(
|
||||
Array.from(xmlDoc.getElementsByTagName('testcase')).map((testcase) => {
|
||||
const storyFile = testcase.getAttribute('classname');
|
||||
const storyName = testcase.getAttribute('name')?.replace(/ /g, '');
|
||||
if (!storyFile || !storyName) return [];
|
||||
|
||||
const stories = storiesByPath[storyFile] || storiesByPath[`./${storyFile}`];
|
||||
const story = stories?.[storyName];
|
||||
if (!story?.id) return [];
|
||||
|
||||
lastStoryIds.add(story.id);
|
||||
|
||||
const result = testcase.querySelector('error, failure, skipped');
|
||||
return [
|
||||
story.id,
|
||||
result
|
||||
? {
|
||||
status: { error: 'error', failure: 'warn', skipped: 'unknown' }[result.tagName],
|
||||
title: `Vitest: ${result.getAttribute('type') || `Test ${result.tagName}`}`,
|
||||
description: '',
|
||||
onClick: openInteractionsPanel,
|
||||
}
|
||||
: {
|
||||
status: 'success',
|
||||
title: 'Vitest: Tests passed',
|
||||
description: '',
|
||||
onClick: openInteractionsPanel,
|
||||
},
|
||||
];
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const enablePolling = global.CONFIG_TYPE === 'DEVELOPMENT';
|
||||
const pollingInterval = 10000; // 10 seconds
|
||||
|
||||
addons.register(
|
||||
ADDON_ID,
|
||||
enablePolling ? (api) => setInterval(loadReport, pollingInterval, api) : loadReport
|
||||
);
|
||||
addons.register(ADDON_ID, () => {});
|
||||
|
@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="addons/vitest/src/addon.stories.ts" time="153" timestamp="2024-07-29T18:09:36.900Z" tests="5" failures="1" errors="1" skipped="1">
|
||||
<testcase classname="addons/vitest/src/addon.stories.ts" name="Success"></testcase>
|
||||
<testcase classname="addons/vitest/src/addon.stories.ts" name="Warn">
|
||||
<failure message="
|
||||
[34mClick to debug the error directly in Storybook: undefined/?path=/story/example-button--responsive-desktop&addonPanel=storybook/interactions/panel[39m
|
||||
|
||||
Unable to find an element with the text: 2560 x 1280. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
|
||||
|
||||
Ignored nodes: comments, script, style
|
||||
[36m<body>[39m
|
||||
[36m<div>[39m
|
||||
[36m<p>[39m
|
||||
[0mThe current viewport is:[0m
|
||||
[36m</p>[39m
|
||||
[36m<strong>[39m
|
||||
[0mDesktop[0m
|
||||
[36m</strong>[39m
|
||||
[36m<p>[39m
|
||||
[0mThe current dimensions are:[0m
|
||||
[36m</p>[39m
|
||||
[36m<strong>[39m
|
||||
[0m1024[0m
|
||||
[0m x [0m
|
||||
[0m768[0m
|
||||
[36m</strong>[39m
|
||||
[36m</div>[39m
|
||||
[36m</body>[39m" type="TestingLibraryElementError">
|
||||
TestingLibraryElementError:
|
||||
Click to debug the error directly in Storybook: undefined/?path=/story/example-button--responsive-desktop&addonPanel=storybook/interactions/panel
|
||||
|
||||
Unable to find an element with the text: 2560 x 1280. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
|
||||
|
||||
Ignored nodes: comments, script, style
|
||||
<body>
|
||||
<div>
|
||||
<p>
|
||||
The current viewport is:
|
||||
</p>
|
||||
<strong>
|
||||
Desktop
|
||||
</strong>
|
||||
<p>
|
||||
The current dimensions are:
|
||||
</p>
|
||||
<strong>
|
||||
1024
|
||||
x
|
||||
768
|
||||
</strong>
|
||||
</div>
|
||||
</body>
|
||||
❯ Object.getElementError ../node_modules/.pnpm/@storybook+test@8.3.0-alpha.2_storybook@8.3.0-alpha.2_@babel+preset-env@7.24.6_@babel+core@7._khsvqtlkubcq5hp6mmokoxkcx4/node_modules/@storybook/test/dist/index.mjs:132:360
|
||||
❯ ../node_modules/.pnpm/@storybook+test@8.3.0-alpha.2_storybook@8.3.0-alpha.2_@babel+preset-env@7.24.6_@babel+core@7._khsvqtlkubcq5hp6mmokoxkcx4/node_modules/@storybook/test/dist/index.mjs:154:286
|
||||
❯ ../node_modules/.pnpm/@storybook+test@8.3.0-alpha.2_storybook@8.3.0-alpha.2_@babel+preset-env@7.24.6_@babel+core@7._khsvqtlkubcq5hp6mmokoxkcx4/node_modules/@storybook/test/dist/index.mjs:146:6814
|
||||
❯ ../node_modules/.pnpm/@storybook+test@8.3.0-alpha.2_storybook@8.3.0-alpha.2_@babel+preset-env@7.24.6_@babel+core@7._khsvqtlkubcq5hp6mmokoxkcx4/node_modules/@storybook/test/dist/index.mjs:154:743
|
||||
❯ play src/Button.stories.tsx:107:31
|
||||
❯ playStory ../node_modules/.pnpm/@storybook+core@8.3.0-alpha.2/node_modules/@storybook/core/dist/preview-api/index.cjs:5732:7
|
||||
❯ ../packages/vitest-plugin-storybook/dist/test-utils.js:305:5
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase classname="addons/vitest/src/addon.stories.ts" name="Error">
|
||||
<error message="TypeError: Cannot read properties of undefined (reading 'map')"></error>
|
||||
</testcase>
|
||||
<testcase classname="addons/vitest/src/addon.stories.ts" name="Unknown">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
Loading…
x
Reference in New Issue
Block a user