Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed May 2, 2024
1 parent 0b88b64 commit ca8ea55
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe('composeStory', () => {
const cleanupSpy = vi.fn();
const beforeEachSpy = vi.fn(() => {
return () => {
cleanupSpy('cleanup from story');
cleanupSpy();
};
});

Expand Down Expand Up @@ -292,7 +292,7 @@ describe('composeStory', () => {
`
"Some stories were not cleaned up before rendering 'Unnamed Story (firstArg, secondArg)'.
You should load the story with \`await Story.load()\` before rendering it.
See XYZ for more information."
See https://storybook.js.org/docs/api/portable-stories-vitest#3-load for more information."
`
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ test('calls play', async ({ mount }) => {
const component = await mount(<stories.CSF3InputFieldFilled />);
await expect(component.getByTestId('input')).toHaveValue('Hello world!');
});

test.only('does not warn in playwright1', async ({ mount }) => {
await mount(<stories.WarnTester1 />);
});
test.only('does not warn in playwright2', async ({ mount }) => {
await mount(<stories.WarnTester2 />);
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,21 @@ export const Modal: CSF3Story = {
await expect(screen.getByRole('dialog')).toBeInTheDocument();
},
};

export const WarnTester1: CSF3Story = {
beforeEach: () => {
console.log('beforeEach1');
return () => {
console.log('cleanup1');
}
},
};

export const WarnTester2: CSF3Story = {
beforeEach: () => {
console.log('beforeEach2');
return () => {
console.log('cleanup2');
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ import { setProjectAnnotations, composeStories, composeStory } from '@storybook/
import * as stories from './Button.stories';

// example with composeStories, returns an object with all stories composed with args/decorators
const { CSF3Primary } = composeStories(stories);
const { CSF3Primary, WarnTester1, WarnTester2 } = composeStories(stories);

describe.only('cleanup warnings', () => {
it('should warn about missing cleanup', async () => {
await WarnTester1.load();
render(<WarnTester1 />);
render(<WarnTester2 />);
console.log(process.env)
});
it('should NOT warn about missing cleanup', async () => {
await WarnTester1.load();
render(<WarnTester1 />);
await WarnTester2.load();
render(<WarnTester2 />);
});
});

// // example with composeStory, returns a single story composed with args/decorators
const Secondary = composeStory(stories.CSF2Secondary, stories.default);
Expand Down
40 changes: 22 additions & 18 deletions test-storybooks/portable-stories-kitchen-sink/react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2583,10 +2583,6 @@ __metadata:
resolution: "@storybook/addon-controls@portal:../../../code/addons/controls::locator=portable-stories-react%40workspace%3A."
dependencies:
"@storybook/blocks": "workspace:*"
"@storybook/core-common": "workspace:*"
cjs-module-lexer: "npm:^1.2.3"
es-module-lexer: "npm:^1.5.0"
globby: "npm:^14.0.1"
lodash: "npm:^4.17.21"
ts-dedent: "npm:^2.0.0"
languageName: node
Expand Down Expand Up @@ -2701,7 +2697,7 @@ __metadata:
"@storybook/client-logger": "workspace:*"
"@storybook/components": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/docs-tools": "workspace:*"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
Expand Down Expand Up @@ -2862,7 +2858,7 @@ __metadata:
"@babel/core": "npm:^7.23.2"
"@babel/preset-env": "npm:^7.23.2"
"@babel/types": "npm:^7.23.0"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/csf-tools": "workspace:*"
"@storybook/node-logger": "workspace:*"
"@storybook/types": "workspace:*"
Expand All @@ -2883,7 +2879,7 @@ __metadata:
dependencies:
"@radix-ui/react-slot": "npm:^1.0.2"
"@storybook/client-logger": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
"@storybook/theming": "workspace:*"
Expand Down Expand Up @@ -2921,13 +2917,19 @@ __metadata:
node-fetch: "npm:^2.0.0"
picomatch: "npm:^2.3.0"
pkg-dir: "npm:^5.0.0"
prettier-fallback: "npm:prettier@^3"
pretty-hrtime: "npm:^1.0.3"
resolve-from: "npm:^5.0.0"
semver: "npm:^7.3.7"
tempy: "npm:^1.0.1"
tiny-invariant: "npm:^1.3.1"
ts-dedent: "npm:^2.0.0"
util: "npm:^0.12.4"
peerDependencies:
prettier: ^2 || ^3
peerDependenciesMeta:
prettier:
optional: true
languageName: node
linkType: soft

Expand All @@ -2950,7 +2952,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/csf-tools": "workspace:*"
"@storybook/docs-mdx": "npm:3.0.0"
"@storybook/global": "npm:^5.0.0"
Expand All @@ -2966,9 +2968,11 @@ __metadata:
"@types/semver": "npm:^7.3.4"
better-opn: "npm:^3.0.2"
chalk: "npm:^4.1.0"
cjs-module-lexer: "npm:^1.2.3"
cli-table3: "npm:^0.6.1"
compression: "npm:^1.7.4"
detect-port: "npm:^1.3.0"
es-module-lexer: "npm:^1.5.0"
express: "npm:^4.17.3"
fs-extra: "npm:^11.1.0"
globby: "npm:^14.0.1"
Expand Down Expand Up @@ -3006,7 +3010,7 @@ __metadata:
"@babel/parser": "npm:^7.23.0"
"@babel/traverse": "npm:^7.23.2"
"@babel/types": "npm:^7.23.0"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/types": "workspace:*"
fs-extra: "npm:^11.1.0"
recast: "npm:^0.23.5"
Expand All @@ -3023,12 +3027,12 @@ __metadata:
languageName: node
linkType: hard

"@storybook/csf@npm:^0.1.2":
version: 0.1.2
resolution: "@storybook/csf@npm:0.1.2"
"@storybook/csf@npm:^0.1.6":
version: 0.1.6
resolution: "@storybook/csf@npm:0.1.6"
dependencies:
type-fest: "npm:^2.19.0"
checksum: 10/11168df65e7b6bd0e5d31e7e805c8ba80397fc190cb33424e043b72bbd85d8f826dba082503992d7f606b72484337ab9d091eca947550613e241fbef57780d4c
checksum: 10/0e5fa962eaa325e80755f22c28e9b3e37d94b173eb7862323a9b2d0e67041487e7989acc505ada29b8fd72855520720a20d3607184c817bbc7ef0d72a5d92eeb
languageName: node
linkType: hard

Expand All @@ -3044,6 +3048,7 @@ __metadata:
resolution: "@storybook/docs-tools@portal:../../../code/lib/docs-tools::locator=portable-stories-react%40workspace%3A."
dependencies:
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/preview-api": "workspace:*"
"@storybook/types": "workspace:*"
"@types/doctrine": "npm:^0.0.3"
Expand Down Expand Up @@ -3091,7 +3096,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
"@storybook/router": "workspace:*"
Expand Down Expand Up @@ -3125,7 +3130,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:^0.1.6"
"@storybook/global": "npm:^5.0.0"
"@storybook/types": "workspace:*"
"@types/qs": "npm:^6.9.5"
Expand Down Expand Up @@ -3248,7 +3253,6 @@ __metadata:
"@testing-library/user-event": "npm:^14.5.2"
"@vitest/expect": "npm:1.3.1"
"@vitest/spy": "npm:^1.3.1"
chai: "npm:^4.4.1"
util: "npm:^0.12.4"
languageName: node
linkType: soft
Expand Down Expand Up @@ -5003,7 +5007,7 @@ __metadata:
languageName: node
linkType: hard

"chai@npm:^4.3.10, chai@npm:^4.4.1":
"chai@npm:^4.3.10":
version: 4.4.1
resolution: "chai@npm:4.4.1"
dependencies:
Expand Down Expand Up @@ -10056,7 +10060,7 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^3.1.1":
"prettier-fallback@npm:prettier@^3, prettier@npm:^3.1.1":
version: 3.2.5
resolution: "prettier@npm:3.2.5"
bin:
Expand Down

0 comments on commit ca8ea55

Please sign in to comment.