Skip to content
Open
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 .changeset/fiery-facts-pick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ladle/react": patch
---

Ladle now prints a warning when it encounters a story file that contains no exported stories.
3 changes: 3 additions & 0 deletions packages/ladle/lib/cli/vite-plugin/parse/get-entry-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@ export const getSingleEntry = async (entry) => {
return 0;
});
debug(result);
if (result.stories.length === 0) {
console.warn(`Warning: Found no exported stories at ${entry}`);
}
return result;
};
10 changes: 10 additions & 0 deletions packages/ladle/tests/fixtures/no-export.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from "react";
import type { Story } from "@ladle/react";

const Cat: Story = () => {
return <h1>Cat</h1>;
};

const Dog: Story = () => {
return <h1>Dog</h1>;
};
11 changes: 10 additions & 1 deletion packages/ladle/tests/parse/get-entry-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from "vitest";
import { test, expect, vi } from "vitest";
import { getSingleEntry } from "../../lib/cli/vite-plugin/parse/get-entry-data.js";

test("Single file with two stories", async () => {
Expand Down Expand Up @@ -54,3 +54,12 @@ test("Extract and merge story meta", async () => {
);
expect(entryData).toMatchSnapshot();
});

test("Warns when a stories file has no exported stories", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
await getSingleEntry("tests/fixtures/no-export.stories.tsx");
expect(warn).toHaveBeenCalledWith(
expect.stringContaining("Warning: Found no exported stories"),
);
warn.mockRestore();
});
Loading