Skip to content

Commit 73a69b5

Browse files
committed
chore: 📝 utilise le addon vitest pour storybook
closes #1235
1 parent 1eacc5a commit 73a69b5

27 files changed

+797
-343
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
run: pnpm check-exports-ci
3737
- name: Test
3838
run: pnpm test
39+
- name: Tests storybook
40+
run: pnpm test:storybook
3941
# - name: Build Storybook
4042
# run: pnpm build-storybook --quiet
4143
# - name: Install Playwright browsers (ensuring compatibility)

.storybook/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { StorybookConfig } from '@storybook/vue3-vite'
22

3+
import vue from '@vitejs/plugin-vue'
4+
35
const config: StorybookConfig = {
46
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
57
addons: [
@@ -8,6 +10,7 @@ const config: StorybookConfig = {
810
'@storybook/addon-a11y',
911
'@chromatic-com/storybook',
1012
'@storybook/addon-docs',
13+
'@storybook/addon-vitest',
1114
],
1215
framework: {
1316
name: '@storybook/vue3-vite',
@@ -17,5 +20,15 @@ const config: StorybookConfig = {
1720
},
1821
docs: {},
1922
staticDirs: ['../public'],
23+
async viteFinal (config) {
24+
// Remplacer le plugin Vue pour désactiver decodeEntities en mode non-navigateur
25+
const vuePluginIndex = config.plugins?.findIndex(
26+
(p: any) => p?.name === 'vite:vue',
27+
)
28+
if (vuePluginIndex !== undefined && vuePluginIndex >= 0) {
29+
config.plugins![vuePluginIndex] = vue({})
30+
}
31+
return config
32+
},
2033
}
2134
export default config

.storybook/preview.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ const preview: Preview = {
2525
backgrounds: {
2626
disabled: true,
2727
},
28+
2829
docs: {
2930
theme: { ...themes.normal, ...VueDsfrTheme },
3031
},
32+
3133
controls: {
3234
matchers: {
3335
color: /(background|color)$/i,
3436
date: /Date$/i,
3537
},
3638
},
39+
3740
viewport: {
3841
options: {
3942
DSFR_XS: {
@@ -73,17 +76,20 @@ const preview: Preview = {
7376
},
7477
},
7578
},
79+
7680
options: {
7781
storySort: {
7882
method: 'alphabetical',
79-
order: [
80-
'Docs',
81-
'Fondamentaux',
82-
'Composables',
83-
'Composants',
84-
],
83+
order: ['Docs', 'Fondamentaux', 'Composables', 'Composants'],
8584
},
8685
},
86+
87+
a11y: {
88+
// 'todo' - show a11y violations in the test UI only
89+
// 'error' - fail CI on a11y violations
90+
// 'off' - skip a11y checks entirely
91+
test: 'todo',
92+
},
8793
},
8894

8995
tags: ['autodocs'],
@@ -108,7 +114,9 @@ const preview: Preview = {
108114
},
109115
decorators: [
110116
(story, context) => {
111-
const selectedTheme = context.globals.theme.includes('clair') ? 'light' : 'dark'
117+
const selectedTheme = context.globals.theme.includes('clair')
118+
? 'light'
119+
: 'dark'
112120
document.documentElement.setAttribute('data-fr-theme', selectedTheme)
113121
return story()
114122
},
@@ -125,7 +133,7 @@ const RouterLink = defineComponent({
125133
`,
126134
})
127135

128-
setup(app => {
136+
setup((app) => {
129137
app.component('RouterLink', RouterLink)
130138
app.component('VIcon', VIcon)
131139
app.component('FocusTrap', FocusTrap)

.storybook/vitest.setup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as a11yAddonAnnotations from '@storybook/addon-a11y/preview'
2+
import { setProjectAnnotations } from '@storybook/vue3-vite'
3+
4+
import * as projectAnnotations from './preview'
5+
6+
// This is an important step to apply the right configuration when testing your stories.
7+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
8+
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations])

docs/guide/migrations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ Si vous importiez vous-même `OhVueIcon` de `oh-vue-icons` dans certains composa
9898

9999
```vue
100100
<script lang="ts" setup>
101-
import { VIcon } from '@gouvminint/vue-dsfr' // [!code ++]
102101
import { OhVueIcon as VIcon } from 'oh-vue-icons' // [!code --]
102+
103+
import { VIcon } from '@gouvminint/vue-dsfr' // [!code ++]
103104
</script>
104105
```
105106

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@ export default antfu({
9797
'antfu/no-top-level-await': 'off',
9898
},
9999
},
100+
{
101+
files: ['**/docs/**/*.md'],
102+
rules: {
103+
'import-x/order': 'off',
104+
},
105+
},
100106
])

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"test": "run-s test:unit",
6767
"test:watch": "vitest",
6868
"test:unit": "vitest run",
69+
"test:storybook": "vitest --project=storybook",
6970
"format": "eslint . --fix",
7071
"lint": "eslint .",
7172
"lint:staged": "eslint ",
@@ -108,6 +109,7 @@
108109
"@storybook/addon-docs": "^10.1.0",
109110
"@storybook/addon-links": "^10.1.0",
110111
"@storybook/addon-themes": "^10.1.0",
112+
"@storybook/addon-vitest": "^10.1.4",
111113
"@storybook/test-runner": "^0.24.2",
112114
"@storybook/vue3-vite": "^10.1.0",
113115
"@testing-library/dom": "^10.4.1",
@@ -118,6 +120,8 @@
118120
"@types/node": "^22.19.1",
119121
"@vitejs/plugin-vue": "^5.2.4",
120122
"@vitejs/plugin-vue-jsx": "^4.2.0",
123+
"@vitest/browser-playwright": "^4.0.14",
124+
"@vitest/coverage-v8": "^4.0.14",
121125
"@vue/test-utils": "^2.4.6",
122126
"@vue/tsconfig": "^0.8.1",
123127
"@vueuse/core": "^12.8.2",
@@ -142,6 +146,7 @@
142146
"lint-staged": "^15.5.2",
143147
"npm-run-all": "^4.1.5",
144148
"p-debounce": "^5.1.0",
149+
"playwright": "^1.57.0",
145150
"pnpm": "^10.24.0",
146151
"publint": "^0.3.15",
147152
"regenerator-runtime": "^0.14.1",
@@ -151,7 +156,7 @@
151156
"storybook": "^10.1.0",
152157
"typescript": "~5.9.3",
153158
"unplugin-lightningcss": "^0.3.3",
154-
"vite": "^6.4.1",
159+
"vite": "npm:rolldown-vite@7.2.10",
155160
"vite-node": "^3.2.4",
156161
"vite-plugin-full-reload": "^1.2.0",
157162
"vitepress": "^1.6.4",

0 commit comments

Comments
 (0)