-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate vi and vitest for addons
- Loading branch information
Showing
6 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...utter.__folder_name }}/packages/{{ cookiecutter.frontend_addon_name }}/.storybook/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { StorybookConfig } from '@storybook/react-vite'; | ||
import path from 'path'; | ||
|
||
const addonName = path.basename(process.cwd()); // Get the addon name dynamically | ||
|
||
const config: StorybookConfig = { | ||
stories: ['../**/*.mdx', `../**/*.stories.@(js|jsx|mjs|ts|tsx)`], | ||
addons: [ | ||
'@chromatic-com/storybook', | ||
'@storybook/addon-a11y', | ||
'@storybook/addon-docs', | ||
'@storybook/addon-essentials', | ||
'@storybook/addon-interactions', | ||
'@storybook/addon-links', | ||
'@storybook/addon-onboarding', | ||
'storybook-react-intl', | ||
], | ||
framework: { | ||
name: '@storybook/react-vite', | ||
options: {}, | ||
}, | ||
staticDirs: [`../../../public`], | ||
viteFinal: async (config) => { | ||
// Adjust paths as needed for the dynamically named addon | ||
config.resolve = { | ||
...config.resolve, | ||
alias: { | ||
...config.resolve?.alias, | ||
[`@${addonName}`]: path.resolve( | ||
__dirname, | ||
`../../../packages/${addonName}/src/`, | ||
), | ||
}, | ||
}; | ||
|
||
// Markdown support (if needed) | ||
config.plugins?.push({ | ||
name: 'vite-plugin-markdown', | ||
transform(src, id) { | ||
if (id.endsWith('.md')) { | ||
return `export default ${JSON.stringify(src)}`; | ||
} | ||
}, | ||
}); | ||
return config; | ||
}, | ||
}; | ||
|
||
export default config; |
86 changes: 86 additions & 0 deletions
86
...er.__folder_name }}/packages/{{ cookiecutter.frontend_addon_name }}/.storybook/preview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import path from 'path'; | ||
import '@kitconcept/volto-light-theme/customizations/@root/theme'; | ||
import '../../../core/packages/volto/test-setup-config'; | ||
|
||
import { | ||
Title, | ||
Subtitle, | ||
Description, | ||
Controls, | ||
Stories, | ||
} from '@storybook/blocks'; | ||
import { Decorator, Preview } from '@storybook/react'; | ||
import { deMessages, enMessages, frMessages } from './localesWrapper'; | ||
import Wrapper from '../../../core/packages/volto/src/storybook'; | ||
|
||
// Dynamically resolve the addon’s name and paths | ||
const addonName = path.basename(process.cwd()); | ||
const messagesMap = { | ||
de: deMessages, | ||
en: enMessages, | ||
fr: frMessages, | ||
}; | ||
|
||
const getMessages = (locale: string) => | ||
messagesMap[locale as keyof typeof messagesMap]; | ||
|
||
const decorators: Decorator[] = [ | ||
(Story, context) => { | ||
return ( | ||
<Wrapper | ||
customStore={{ | ||
intl: { | ||
locale: context.globals.locale, | ||
messages: getMessages(context.globals.locale), | ||
}, | ||
}} | ||
> | ||
<Story locale={context.globals.locale} /> | ||
</Wrapper> | ||
); | ||
}, | ||
]; | ||
|
||
const parameters = { | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
docs: { | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<Description /> | ||
<Stories /> | ||
<Controls /> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
const reactIntl = { | ||
defaultLocale: 'de', | ||
locales: ['en', 'de', 'fr'], | ||
}; | ||
|
||
const preview: Preview = { | ||
globals: { | ||
locale: reactIntl.defaultLocale, | ||
locales: { | ||
en: { icon: '🇺🇸', title: 'English', right: 'EN' }, | ||
de: { icon: '🇩🇪', title: 'Deutsch', right: 'DE' }, | ||
fr: { icon: '🇫🇷', title: 'Français', right: 'FR' }, | ||
}, | ||
}, | ||
parameters: { | ||
reactIntl, | ||
...parameters, | ||
}, | ||
decorators, | ||
}; | ||
|
||
export default preview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...okiecutter.__folder_name }}/packages/{{ cookiecutter.frontend_addon_name }}/setupTests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
37 changes: 37 additions & 0 deletions
37
...kiecutter.__folder_name }}/packages/{{ cookiecutter.frontend_addon_name }}/vite.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { defineConfig } from 'vite'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
import react from '@vitejs/plugin-react'; | ||
import path from 'path'; | ||
import fixReactVirtualized from 'esbuild-plugin-react-virtualized'; | ||
|
||
// Dynamically get the name of the generated addon | ||
const addonName = path.basename(process.cwd()); | ||
const projectRootPath = path.resolve('../..'); | ||
|
||
// Vite configuration with dynamic addon name | ||
export default defineConfig({ | ||
plugins: [react(), tsconfigPaths()], | ||
optimizeDeps: { | ||
esbuildOptions: { | ||
plugins: [fixReactVirtualized as any], | ||
}, | ||
include: ['@plone/volto/constants/Languages.cjs'], | ||
}, | ||
resolve: { | ||
alias: [ | ||
{ find: /^~@root/, replacement: projectRootPath }, | ||
{ | ||
find: `@${addonName}`, | ||
replacement: `${projectRootPath}/packages/${addonName}/src/`, | ||
}, | ||
{ find: /^~/, replacement: '' }, | ||
], | ||
}, | ||
logLevel: 'error', | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: './src/setupTests.ts', | ||
include: ['src/**/*.test.ts', 'src/**/*.test.tsx'], | ||
}, | ||
}); |
10 changes: 10 additions & 0 deletions
10
...ecutter.__folder_name }}/packages/{{ cookiecutter.frontend_addon_name }}/vitest.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['**/*.vitest.tsx'], | ||
globals: true, | ||
reporters: 'verbose', | ||
environment: 'jsdom', | ||
}, | ||
}); |