Skip to content

Commit 616a43b

Browse files
authored
Merge pull request #1236 from dnum-mi/1235-tech-use-vitest-addon
chore: 📝 utilise le addon vitest pour storybook
2 parents 1eacc5a + d2022c0 commit 616a43b

28 files changed

+811
-395
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
run: pnpm lint --quiet
3535
- name: Check exports
3636
run: pnpm check-exports-ci
37+
- name: Install Playwright browsers
38+
run: pnpm exec playwright install --with-deps chromium
3739
- name: Test
3840
run: pnpm test
3941
# - name: Build Storybook

.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: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import VIcon from '../src/components/VIcon/VIcon.vue'
99

1010
import VueDsfrTheme from './vue-dsfr-theme.js'
1111
import '../src/assets/variables-fdr.css'
12+
import '../src/main.css'
1213
import '@gouvfr/dsfr/dist/core/core.main.min.css'
1314
import '@gouvfr/dsfr/dist/scheme/scheme.min.css'
1415
import '@gouvfr/dsfr/dist/component/component.main.min.css'
1516
import '@gouvfr/dsfr/dist/utility/utility.main.min.css'
1617
import '@gouvfr/dsfr/dist/utility/icons/icons.main.min.css'
17-
18-
import '../src/main.css'
19-
2018
import './theme.css'
2119
// import '@gouvfr/dsfr/dist/core/core.min.css'
2220

@@ -25,15 +23,18 @@ const preview: Preview = {
2523
backgrounds: {
2624
disabled: true,
2725
},
26+
2827
docs: {
2928
theme: { ...themes.normal, ...VueDsfrTheme },
3029
},
30+
3131
controls: {
3232
matchers: {
3333
color: /(background|color)$/i,
3434
date: /Date$/i,
3535
},
3636
},
37+
3738
viewport: {
3839
options: {
3940
DSFR_XS: {
@@ -73,17 +74,20 @@ const preview: Preview = {
7374
},
7475
},
7576
},
77+
7678
options: {
7779
storySort: {
7880
method: 'alphabetical',
79-
order: [
80-
'Docs',
81-
'Fondamentaux',
82-
'Composables',
83-
'Composants',
84-
],
81+
order: ['Docs', 'Fondamentaux', 'Composables', 'Composants'],
8582
},
8683
},
84+
85+
a11y: {
86+
// 'todo' - show a11y violations in the test UI only
87+
// 'error' - fail CI on a11y violations
88+
// 'off' - skip a11y checks entirely
89+
test: 'todo',
90+
},
8791
},
8892

8993
tags: ['autodocs'],
@@ -108,7 +112,9 @@ const preview: Preview = {
108112
},
109113
decorators: [
110114
(story, context) => {
111-
const selectedTheme = context.globals.theme.includes('clair') ? 'light' : 'dark'
115+
const selectedTheme = context.globals.theme.includes('clair')
116+
? 'light'
117+
: 'dark'
112118
document.documentElement.setAttribute('data-fr-theme', selectedTheme)
113119
return story()
114120
},
@@ -125,7 +131,7 @@ const RouterLink = defineComponent({
125131
`,
126132
})
127133

128-
setup(app => {
134+
setup((app) => {
129135
app.component('RouterLink', RouterLink)
130136
app.component('VIcon', VIcon)
131137
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: ['**/*.md', '**/*.md/**'],
102+
rules: {
103+
'import-x/order': 'off',
104+
},
105+
},
100106
])

package.json

Lines changed: 7 additions & 2 deletions
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,11 +156,11 @@
151156
"storybook": "^10.1.0",
152157
"typescript": "~5.9.3",
153158
"unplugin-lightningcss": "^0.3.3",
154-
"vite": "^6.4.1",
159+
"vite": "npm:[email protected]",
155160
"vite-node": "^3.2.4",
156161
"vite-plugin-full-reload": "^1.2.0",
157162
"vitepress": "^1.6.4",
158-
"vitest": "^4.0.14",
163+
"vitest": "^4.0.15",
159164
"vue-demi": "^0.14.10",
160165
"vue-tsc": "^2.2.12"
161166
},

0 commit comments

Comments
 (0)