strip out junit logic (for now)

This commit is contained in:
Yann Braga 2024-08-02 16:44:04 +02:00
parent 81c6a13ca2
commit f90d77cfea
6 changed files with 2 additions and 162 deletions

View File

@ -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: [

View File

@ -1,3 +1,3 @@
# Storybook Addon Vitest
# Storybook Addon Vitest (Experimental)
Addon to integrate Vitest test results with Storybook.

View File

@ -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 = {};

View File

@ -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, () => {});

View File

@ -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&amp;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&lt;body&gt;[39m
[36m&lt;div&gt;[39m
[36m&lt;p&gt;[39m
[0mThe current viewport is:[0m
[36m&lt;/p&gt;[39m
[36m&lt;strong&gt;[39m
[0mDesktop[0m
[36m&lt;/strong&gt;[39m
[36m&lt;p&gt;[39m
[0mThe current dimensions are:[0m
[36m&lt;/p&gt;[39m
[36m&lt;strong&gt;[39m
[0m1024[0m
[0m x [0m
[0m768[0m
[36m&lt;/strong&gt;[39m
[36m&lt;/div&gt;[39m
[36m&lt;/body&gt;[39m" type="TestingLibraryElementError">
TestingLibraryElementError:
Click to debug the error directly in Storybook: undefined/?path=/story/example-button--responsive-desktop&amp;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
&lt;body&gt;
&lt;div&gt;
&lt;p&gt;
The current viewport is:
&lt;/p&gt;
&lt;strong&gt;
Desktop
&lt;/strong&gt;
&lt;p&gt;
The current dimensions are:
&lt;/p&gt;
&lt;strong&gt;
1024
x
768
&lt;/strong&gt;
&lt;/div&gt;
&lt;/body&gt;
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>