Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Fix ordering of entries in Stories block #19907

Merged
merged 4 commits into from
Nov 21, 2022
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
13 changes: 13 additions & 0 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ test.describe('addon-docs', () => {
const noAutoplayPre = root.locator('#story--addons-docs-docspage-autoplay--no-autoplay pre');
await expect(noAutoplayPre).toHaveText('Play has not run');
});

test('should order entries correctly', async ({ page }) => {
const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/basic', 'docs');

// The `<Primary>` block should render the "Basic" story, and the `<Stories/>` block should
// render the "Another" story
const root = sbPage.previewRoot();
const stories = root.locator('.sbdocs-h3');

await expect(await stories.count()).toBe(1);
await expect(stories.first()).toHaveText('Another');
});
});
11 changes: 6 additions & 5 deletions code/lib/preview-web/src/docs-context/DocsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ export class DocsContext<TRenderer extends Renderer> implements DocsContextProps
Object.values(csfFile.stories).forEach((annotation) => {
this.storyIdToCSFFile.set(annotation.id, csfFile);
this.exportToStoryId.set(annotation.moduleExport, annotation.id);
});

if (addToComponentStories) {
this.nameToStoryId.set(annotation.name, annotation.id);
const story = this.storyById(annotation.id);
if (addToComponentStories) {
this.store.componentStoriesFromCSFFile({ csfFile }).forEach((story) => {
this.nameToStoryId.set(story.name, story.id);
this.componentStoriesValue.push(story);
if (!this.primaryStory) this.primaryStory = story;
}
});
});
}
}

setMeta(metaExports: Store_ModuleExports) {
Expand Down
6 changes: 4 additions & 2 deletions scripts/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import detectFreePort from 'detect-port';
import type { Task } from '../task';
import { exec } from '../utils/exec';

export const PORT = 8001;
export const PORT = process.env.STORYBOOK_SERVE_PORT
? parseInt(process.env.STORYBOOK_SERVE_PORT, 10)
: 8001;
export const serve: Task = {
description: 'Serve the build storybook for a sandbox',
service: true,
Expand All @@ -22,7 +24,7 @@ export const serve: Task = {
// If aborted, we want to make sure the rejection is handled.
if (!err.killed) throw err;
});
await exec('yarn wait-on http://localhost:8001', { cwd: codeDir }, { dryRun, debug });
await exec(`yarn wait-on http://localhost:${PORT}`, { cwd: codeDir }, { dryRun, debug });

return controller;
},
Expand Down