Skip to content

[Bug] Can't seem to use *.stories.svelte with composeStories #333

@zumoshi

Description

@zumoshi

Describe the bug

I was following this tutorial:
https://storybook.js.org/docs/writing-tests/snapshot-testing

But the part where I should import the stories gives me undefined:

import * as Button  from './Button.stories.svelte';
const {Primary} = composeStories(Button);

The IDE is showing errors on Button and Primary, and debugger shows Button to not have any properties for the stories.

I then tried cloning this repo separately and following:
https://github.com/storybookjs/addon-svelte-csf/blob/main/examples/StoryImporter.mdx

Just to see if I can get any reference to the stories but didn't seem able to.

Steps to reproduce the behavior

  1. git clone [email protected]:storybookjs/addon-svelte-csf.git
  2. run pnpm i and pnpm build
  3. Create ./examples/x.spec.ts
import { expect, test } from 'vitest';
import * as ExportNameStories from './ExportName.stories.svelte';
test("x", ()=>{
  console.log(ExportNameStories);
  console.log(ExportNameStories.SimpleName);
  console.log(ExportNameStories.NameFromExportName);
})
  1. Edit vitest.workspace.ts file to see the x.spec.ts file
Subject: [PATCH] x
---
/vitest.workspace.ts	(date 1762011442650)
@@ -12,6 +12,15 @@
     },
   },
   {
+    extends: './vite.config.ts',
+    test: {
+      name: 'asdasdasd',
+      dir: './examples/',
+      environment: 'happy-dom',
+      globals: true,
+    },
+  },
+  {
     extends: './vite.config.ts',
     plugins: [
       storybookTest({
  1. Run the test.

I expected to see references to the Stories, but I got undefined.

Screenshots and/or logs

Image

Environment

  • OS: Linux
  • Node.js version: v24.11.0
  • NPM version: 11.6.1 (pnpm: 10.18.0)
  • Browser (if applicable): N/A
  • Browser version (if applicable): N/A
  • Device (if applicable): N/A

Additional context

Cloned the repo (main branch) at e73febc

Have I misunderstood how this works, or is this a bug? How should I use stories made with this library for vitest snapshot tests?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions