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

Make sure mocked actions can be identified in production build #482

Merged
merged 3 commits into from
Aug 23, 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
6 changes: 4 additions & 2 deletions examples/vue/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { mergeConfig } = require('vite');
export default {
framework: '@storybook/vue3',
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions'],
core: {
builder: '@storybook/builder-vite',
// we don't want to muck up the data when we're working on the builder
Expand All @@ -16,7 +16,9 @@ export default {
async viteFinal(config, { configType }) {
// Demonstrates use of mergeConfig and resolve.alias as an array
return mergeConfig(config, {
resolve: { alias: [{ find: '@assets', replacement: resolve(__dirname, '..', 'stories', 'assets') }] },
resolve: {
alias: [{ find: '@assets', replacement: resolve(__dirname, '..', 'stories', 'assets') }],
},
});
},
};
3 changes: 3 additions & 0 deletions examples/vue/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
window.global = window;
</script>
7 changes: 5 additions & 2 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
"devDependencies": {
"@storybook/addon-a11y": "^6.5.9",
"@storybook/addon-essentials": "^6.5.9",
"@storybook/addon-interactions": "6.5.9",
"@storybook/builder-vite": "workspace:*",
"@storybook/jest": "^0.0.10",
"@storybook/mdx2-csf": "^0.0.3",
"@storybook/test-runner": "0.1.0",
"@storybook/vue3": "^6.5.9",
"@storybook/test-runner": "^0.5.0",
"@storybook/testing-library": "^0.0.13",
"@storybook/vue3": "6.5.9",
"@vitejs/plugin-vue": "^3.0.0-beta.1",
"http-server": "^14.1.0",
"jest": "^27.5.1",
Expand Down
8 changes: 8 additions & 0 deletions examples/vue/stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import MyButton from './Button.vue';
import { userEvent, within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';

export default {
title: 'Example/Button',
Expand Down Expand Up @@ -28,6 +30,12 @@ Primary.args = {
primary: true,
label: 'Button',
};
Primary.play = async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole('button');
await userEvent.click(button);
await expect(args.onClick).toHaveBeenCalled();
};

export const Secondary = Template.bind({});
Secondary.args = {
Expand Down
5 changes: 5 additions & 0 deletions packages/builder-vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export async function build(options: ExtendedOptions) {
emptyOutDir: false, // do not clean before running Vite build - Storybook has already added assets in there!
sourcemap: true,
},
esbuild: {
// Workaround for #206: https://github.com/storybookjs/builder-vite/issues/206#issuecomment-1122347230
// Makes sure that mocked actions can be recognized in the production build.
keepNames: true,
},
};

const finalConfig = await presets.apply('viteFinal', config, options);
Expand Down
Loading