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

Test: Add mount property to the story context #28383

Merged
merged 38 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3eb587f
Add a mount property to the context, so that the user can do stuff be…
kasperpeulen Jun 28, 2024
6da574a
Merge branch 'refs/heads/kasper/canvas' into kasper/mount
kasperpeulen Jun 28, 2024
ea68fe9
Merge branch 'kasper/canvas' into kasper/mount
kasperpeulen Jun 28, 2024
5ba7b39
Fix snapshots
kasperpeulen Jun 28, 2024
15e354e
Merge remote-tracking branch 'origin/kasper/mount' into kasper/mount
kasperpeulen Jun 28, 2024
85b91bb
Cleanup
kasperpeulen Jun 28, 2024
fa74a4f
Resolve some comments
kasperpeulen Jun 28, 2024
5bb7da9
Fix angular types in test
kasperpeulen Jun 28, 2024
540083c
Merge branch 'refs/heads/kasper/canvas' into kasper/mount
kasperpeulen Jun 28, 2024
5506e78
Add comment
kasperpeulen Jun 28, 2024
c38596b
Merge branch 'kasper/canvas' into kasper/mount
kasperpeulen Jul 1, 2024
835621d
Add a commented out test
kasperpeulen Jul 1, 2024
7a3bbff
Always create a fresh context when playing or loading a story
kasperpeulen Jul 1, 2024
d6f047b
add tests for legacy format of portable stories
yannbf Jul 1, 2024
362ec4d
Add long definition test
kasperpeulen Jul 1, 2024
254102f
Use utility
kasperpeulen Jul 1, 2024
b6c4c8c
Address feedback
kasperpeulen Jul 1, 2024
a5b50d9
Rename errors
kasperpeulen Jul 1, 2024
a32c0cd
Make portable stories play backwards compatible
kasperpeulen Jul 1, 2024
e8479d3
Call prepare context at the right time
kasperpeulen Jul 1, 2024
7db654a
Fix all unit tests
kasperpeulen Jul 2, 2024
fa7aa1f
Fix all unit tests
kasperpeulen Jul 2, 2024
8b23c6c
Merge remote-tracking branch 'origin/kasper/mount' into kasper/mount
kasperpeulen Jul 2, 2024
6193e85
Merge branch 'kasper/canvas' into kasper/mount
kasperpeulen Jul 2, 2024
ab925e8
Merge branch 'kasper/canvas' into kasper/mount
kasperpeulen Jul 2, 2024
8870451
Fix CPC imports
kasperpeulen Jul 2, 2024
9b0ec09
Use @storybook/csf 0.1.11
kasperpeulen Jul 2, 2024
840eef5
Refactor tests slightly
tmeasday Jul 2, 2024
771af17
Add tests for `storyRender`
tmeasday Jul 2, 2024
41b39be
Fix storybook/core reference
kasperpeulen Jul 2, 2024
e557116
Fix CPC imports
kasperpeulen Jul 2, 2024
2945163
Fix type errors
kasperpeulen Jul 2, 2024
db487f6
Add a test that we force remount destructuring stories on args change
tmeasday Jul 2, 2024
c7284bf
Put back portable story playwright implementation
kasperpeulen Jul 2, 2024
fb3f6cd
keepNames to false to restore previous compiling behavior
kasperpeulen Jul 2, 2024
d2b58e0
Fix last issues 🤞
kasperpeulen Jul 2, 2024
c0084fb
Fix portable stories test
kasperpeulen Jul 2, 2024
9678d6f
Put phase back to playing after rendering in a mount story
kasperpeulen Jul 2, 2024
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
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts"
},
"dependencies": {
"@storybook/csf": "0.1.10",
"@storybook/csf": "0.1.11",
"@storybook/global": "^5.0.0",
"ts-dedent": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"prep": "bun ./scripts/prep.ts"
},
"dependencies": {
"@storybook/csf": "0.1.10",
"@storybook/csf": "0.1.11",
"@types/express": "^4.17.21",
"@types/node": "^18.0.0",
"browser-assert": "^1.2.1",
Expand Down
7 changes: 6 additions & 1 deletion code/core/src/preview-api/modules/preview-web/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { StoryStore } from '../../store';
import { StoryRender } from './render/StoryRender';
import type { CsfDocsRender } from './render/CsfDocsRender';
import type { MdxDocsRender } from './render/MdxDocsRender';
import { mountDestructured } from './render/mount-utils';
import type { Args, Globals, Renderer, StoryId } from '@storybook/core/types';
import type {
ModuleImportFn,
Expand Down Expand Up @@ -291,7 +292,11 @@ export class Preview<TRenderer extends Renderer> {
await Promise.all(
this.storyRenders
.filter((r) => r.id === storyId && !r.renderOptions.forceInitialArgs)
.map((r) => r.rerender())
.map((r) =>
// We only run the play function, with in a force remount.
// But when mount is destructured, the rendering happens inside of the play function.
r.story && mountDestructured(r.story.playFunction) ? r.remount() : r.rerender()
)
);

this.channel.emit(STORY_ARGS_UPDATED, {
Expand Down
39 changes: 39 additions & 0 deletions code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,41 @@ describe('PreviewWeb', () => {
expect(mockChannel.emit).toHaveBeenCalledWith(STORY_RENDERED, 'component-one--a');
});

describe('if play function destructures mount', () => {
it('passes forceRemount to renderToCanvas', async () => {
document.location.search = '?id=component-one--a';
const newImportFn = vi.fn(async (path) => {
if (path === './src/ComponentOne.stories.js') {
return {
...componentOneExports,
a: { ...componentOneExports.a, play: ({ mount }: any) => mount() },
};
}
return importFn(path);
});
await createAndRenderPreview({ importFn: newImportFn });

mockChannel.emit.mockClear();
projectAnnotations.renderToCanvas.mockClear();
emitter.emit(UPDATE_STORY_ARGS, {
storyId: 'component-one--a',
updatedArgs: { new: 'arg' },
});
await waitForRender();

expect(projectAnnotations.renderToCanvas).toHaveBeenCalledWith(
expect.objectContaining({
forceRemount: true,
storyContext: expect.objectContaining({
initialArgs: { foo: 'a', one: 1 },
args: { foo: 'a', new: 'arg', one: 'mapped-1' },
}),
}),
'story-element'
);
});
});

describe('while story is still rendering', () => {
it('runs loaders again after renderToCanvas is done', async () => {
// Arrange - set up a gate to control when the loaders run
Expand Down Expand Up @@ -3626,6 +3661,7 @@ describe('PreviewWeb', () => {
"dev",
"test",
],
"testingLibraryRender": undefined,
"title": "Component One",
},
"component-one--b": {
Expand Down Expand Up @@ -3674,6 +3710,7 @@ describe('PreviewWeb', () => {
"dev",
"test",
],
"testingLibraryRender": undefined,
"title": "Component One",
},
"component-one--e": {
Expand All @@ -3700,6 +3737,7 @@ describe('PreviewWeb', () => {
"dev",
"test",
],
"testingLibraryRender": undefined,
"title": "Component One",
},
"component-two--c": {
Expand Down Expand Up @@ -3736,6 +3774,7 @@ describe('PreviewWeb', () => {
"dev",
"test",
],
"testingLibraryRender": undefined,
"title": "Component Two",
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,9 @@ export class PreviewWithSelection<TRenderer extends Renderer> extends Preview<TR
this.channel.emit(STORY_THREW_EXCEPTION, { name, message, stack });
this.channel.emit(STORY_RENDER_PHASE_CHANGED, { newPhase: 'errored', storyId });

// Ignored exceptions exist for control flow purposes, and are typically handled elsewhere.
//
// FIXME: Should be '=== IGNORED_EXCEPTION', but currently the object
// is coming from two different bundles (index.js vs index.mjs)
//
// https://github.com/storybookjs/storybook/issues/19321
if (!error.message?.startsWith('ignoredException')) {
this.view.showErrorDisplay(error);
logger.error(`Error rendering story '${storyId}':`);
logger.error(error);
}
this.view.showErrorDisplay(error);
logger.error(`Error rendering story '${storyId}':`);
logger.error(error);
}

// renderError is used by the various app layers to inform the user they have done something
Expand Down
Loading