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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 9.1.5

- CSF: Support `satisfies x as y` syntax - [#32169](https://github.com/storybookjs/storybook/pull/32169), thanks @diagramatics!
- Vitest addon: Handle Playwright installation errors gracefully - [#32329](https://github.com/storybookjs/storybook/pull/32329), thanks @ndelangen!

## 9.1.4

- Angular: Properly merge builder options and browserTarget options - [#32272](https://github.com/storybookjs/storybook/pull/32272), thanks @kroeder!
Expand Down
12 changes: 8 additions & 4 deletions code/addons/vitest/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,14 @@ export default async function postInstall(options: PostinstallOptions) {
} else {
logger.plain(`${step} Configuring Playwright with Chromium (this might take some time):`);
logger.plain(' npx playwright install chromium --with-deps');
await packageManager.executeCommand({
command: 'npx',
args: ['playwright', 'install', 'chromium', '--with-deps'],
});
try {
await packageManager.executeCommand({
command: 'npx',
args: ['playwright', 'install', 'chromium', '--with-deps'],
});
} catch (e) {
console.error('Failed to install Playwright. Please install it manually');
}
}

const fileExtension =
Expand Down
197 changes: 189 additions & 8 deletions code/core/src/csf-tools/CsfFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,57 @@ describe('CsfFile', () => {
`);
});

it('typescript satisfies as', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
type PropTypes = {};
export default { title: 'foo/bar' } satisfies Meta<PropTypes> as Meta<PropTypes>;
export const A = { name: 'AA' } satisfies StoryObj<PropTypes>;
export const B = ((args) => {}) satisfies StoryFn<PropTypes>;
`,
true
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar
stories:
- id: foo-bar--a
name: AA
parameters:
__isArgsStory: true
__id: foo-bar--a
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: false
mount: false
moduleMock: false
- id: foo-bar--b
name: B
parameters:
__isArgsStory: true
__id: foo-bar--b
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: false
mount: false
moduleMock: false
`);
});

it('typescript meta var', () => {
expect(
parse(
Expand Down Expand Up @@ -605,6 +656,136 @@ describe('CsfFile', () => {
`);
});

it('typescript satisfies as meta', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn } from '@storybook/react';
type PropTypes = {};
const meta = { title: 'foo/bar/baz' } satisfies Meta<PropTypes> as Meta<PropTypes>;
export default meta;
export const A: StoryFn<PropTypes> = () => <>A</>;
export const B: StoryFn<PropTypes> = () => <>B</>;
`
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar/baz
stories:
- id: foo-bar-baz--a
name: A
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: true
mount: false
moduleMock: false
- id: foo-bar-baz--b
name: B
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: true
mount: false
moduleMock: false
`);
});

it('typescript satisfies as stories', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
type PropTypes = {};
export default { title: 'foo/bar' } as Meta<PropTypes>;
export const A = { name: 'AA' } satisfies StoryObj<PropTypes> as StoryObj<PropTypes>;
export const B = ((args) => {}) satisfies StoryFn<PropTypes> as StoryFn<PropTypes>;
`,
true
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar
stories:
- id: foo-bar--a
name: AA
parameters:
__isArgsStory: true
__id: foo-bar--a
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: false
mount: false
moduleMock: false
- id: foo-bar--b
name: B
parameters:
__isArgsStory: true
__id: foo-bar--b
__stats:
factory: false
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: false
mount: false
moduleMock: false
`);
});

it('typescript satisfies as export specifier', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn } from '@storybook/react';
type PropTypes = {};
const meta = { title: 'foo/bar/baz' } satisfies Meta<PropTypes> as Meta<PropTypes>;
const story = { name: 'Story A' };
export { meta as default, story as A };
`,
true
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar/baz
stories:
- id: foo-bar-baz--a
name: A
localName: story
parameters:
__id: foo-bar-baz--a
__stats:
play: false
render: false
loaders: false
beforeEach: false
globals: false
tags: false
storyFn: false
mount: false
moduleMock: false
`);
});

it('component object', () => {
expect(
parse(
Expand Down Expand Up @@ -1995,7 +2176,7 @@ describe('CsfFile', () => {
const { indexInputs } = loadCsf(
dedent`
const Component = (props) => <div>hello</div>;

export default {
title: 'custom foo title',
component: Component,
Expand Down Expand Up @@ -2513,7 +2694,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[MultipleMetaError: CSF: multiple meta objects (line 4, col 24)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2531,7 +2712,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[MultipleMetaError: CSF: multiple meta objects (line 3, col 25)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2549,7 +2730,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[MultipleMetaError: CSF: multiple meta objects

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2565,7 +2746,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[BadMetaError: CSF: meta() factory must be imported from .storybook/preview configuration (line 1, col 0)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2582,7 +2763,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[BadMetaError: CSF: meta() factory must be imported from .storybook/preview configuration (line 4, col 28)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2599,7 +2780,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[MixedFactoryError: CSF: expected factory story (line 4, col 17)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});

Expand All @@ -2616,7 +2797,7 @@ describe('CsfFile', () => {
).toThrowErrorMatchingInlineSnapshot(`
[MixedFactoryError: CSF: expected non-factory story (line 4, col 28)

More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export]
`);
});
});
Expand Down
Loading