Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ const config = defineMain({
directory: '../addons/vitest/template/stories',
titlePrefix: 'addons/vitest',
},
{
directory: '../addons/vitest/src',
titlePrefix: 'addons/vitest',
files: 'stories.tsx',
},
],
addons: [
'@storybook/addon-themes',
Expand Down
20 changes: 20 additions & 0 deletions code/addons/vitest/src/stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

import type { Meta, StoryObj } from '@storybook/react-vite';

import { expect } from 'storybook/test';

const meta = {
title: 'StoriesTsx',
render: () => <div>This is a story coming from a /stories.tsx file detected via custom glob</div>,
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
play: async () => {
expect(true).toBe(true);
},
};
33 changes: 11 additions & 22 deletions code/core/src/csf-tools/vitest-plugin/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ const transform = async ({
};

describe('transformer', () => {
describe('no-op', () => {
it('should return original code if the file is not a story file', async () => {
const code = `console.log('Not a story file');`;
const fileName = 'src/components/Button.js';

const result = await transform({ code, fileName });

expect(result.code).toMatchInlineSnapshot(`console.log('Not a story file');`);
});
});

describe('CSF v1/v2/v3', () => {
describe('default exports (meta)', () => {
it('should add title to inline default export if not present', async () => {
Expand Down Expand Up @@ -124,7 +113,7 @@ describe('transformer', () => {
component: Button,
};
export default meta;

export const Story = {};
`;

Expand Down Expand Up @@ -153,9 +142,9 @@ describe('transformer', () => {
const meta = {
title: 'Button',
component: Button,
};
};
export default meta;

export const Story = {};
`;

Expand Down Expand Up @@ -272,7 +261,7 @@ describe('transformer', () => {
label: 'Primary Button',
},
};

export { Primary };
`;

Expand Down Expand Up @@ -306,7 +295,7 @@ describe('transformer', () => {
label: 'Primary Button',
},
};

export { Primary as PrimaryStory };
`;

Expand Down Expand Up @@ -340,9 +329,9 @@ describe('transformer', () => {
label: 'Primary Button',
},
};

export const Secondary = {}

export { Primary };
`;

Expand Down Expand Up @@ -430,7 +419,7 @@ describe('transformer', () => {
const code = `
export default {};
export const Included = { tags: ['include-me'] };

export const NotIncluded = {}
`;

Expand Down Expand Up @@ -461,7 +450,7 @@ describe('transformer', () => {
const code = `
export default {};
export const Included = {};

export const NotIncluded = { tags: ['exclude-me'] }
`;

Expand Down Expand Up @@ -636,7 +625,7 @@ describe('transformer', () => {
const code = `
import { config } from '#.storybook/preview';
const meta = config.meta({ component: Button });
const Primary = meta.story({
const Primary = meta.story({
args: {
label: 'Primary Button',
}
Expand Down Expand Up @@ -672,7 +661,7 @@ describe('transformer', () => {
const code = `
import { config } from '#.storybook/preview';
const meta = config.meta({ component: Button });
const Primary = meta.story({
const Primary = meta.story({
args: {
label: 'Primary Button',
}
Expand Down
5 changes: 0 additions & 5 deletions code/core/src/csf-tools/vitest-plugin/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ export async function vitestTransform({
stories: StoriesEntry[];
previewLevelTags: Tag[];
}): Promise<ReturnType<typeof formatCsf>> {
const isStoryFile = /\.stor(y|ies)\./.test(fileName);
if (!isStoryFile) {
return code;
}

const parsed = loadCsf(code, {
fileName,
transformInlineMeta: true,
Expand Down
Loading