Skip to content

Commit 2038a79

Browse files
authored
Merge pull request #280 from dnum-mi/tech/migrate-to-vitest
refacto: ♻️ Use Vitest instead of Jest
2 parents b807b9d + e5c3622 commit 2038a79

36 files changed

+16763
-24499
lines changed

package-lock.json

Lines changed: 16580 additions & 24430 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"README.md"
99
],
1010
"engines": {
11-
"node": "16.x.x",
11+
"node": "17.x.x",
1212
"npm": "8.x.x"
1313
},
1414
"types": "./types",
@@ -32,8 +32,10 @@
3232
"build:css": "node build-css.mjs",
3333
"build:js": "cross-env NODE_ENV=production rollup --config rollup.config.js",
3434
"demo-app": "vite",
35+
"vitest": "vitest",
36+
"coverage": "vitest run --coverage",
3537
"test": "run-s test:unit test:ct-ci",
36-
"test:unit": "jest",
38+
"test:unit": "vitest run",
3739
"test:ct": "cypress open-ct",
3840
"test:ct-ci": "cypress run-ct",
3941
"format": "npm run lint -- --fix",
@@ -96,11 +98,11 @@
9698
"@vue/eslint-config-typescript": "^10.0.0",
9799
"@vue/test-utils": "^2.0.0-rc.18",
98100
"@vue/tsconfig": "^0.1.3",
99-
"@vue/vue3-jest": "^27.0.0-alpha.4",
100101
"autoprefixer": "^10.4.4",
101102
"babel-loader": "^8.2.3",
102103
"babel-plugin-transform-import-meta": "^2.1.1",
103104
"chalk": "^5.0.1",
105+
"c8": "^7.11.0",
104106
"copyfiles": "^2.4.1",
105107
"core-js": "^3.21.1",
106108
"cross-env": "^7.0.3",
@@ -115,9 +117,6 @@
115117
"eslint-plugin-vue": "^8.5.0",
116118
"globby": "^13.1.1",
117119
"inquirer": "^8.2.1",
118-
"jest": "^27.5.1",
119-
"jest-svg-transformer": "^1.0.0",
120-
"jest-transform-stub": "^2.0.0",
121120
"jsdom": "^19.0.0",
122121
"lint-staged": "^12.3.6",
123122
"mkdirp": "^1.0.4",
@@ -139,7 +138,6 @@
139138
"semantic-release": "^19.0.2",
140139
"start-server-and-test": "^1.14.0",
141140
"storybook-builder-vite": "^0.1.20",
142-
"ts-jest": "^27.1.3",
143141
"tsd-jsdoc": "^2.5.0",
144142
"typescript": "^4.6.2",
145143
"vite": "^2.8.6",
@@ -154,6 +152,9 @@
154152
"peerDependencies": {
155153
"vue-router": "^4.0.14"
156154
},
155+
"optionalDependencies": {
156+
"esbuild-linux-64": "^0.14.27"
157+
},
157158
"gitHooks": {
158159
"pre-commit": "lint-staged",
159160
"pre-push": "npm test"

src/components/DsfrAccordion/DsfrAccordion.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fireEvent, render } from '@testing-library/vue'
22

3-
import '@gouvfr/dsfr/dist/core/core.module.js'
3+
// import '@gouvfr/dsfr/dist/core/core.module.js'
44

55
import DsfrAccordion from './DsfrAccordion.vue'
66

@@ -19,8 +19,8 @@ describe('DsfrAccordion', () => {
1919
},
2020
props: {
2121
title,
22-
id: 1,
23-
expandedId: 1,
22+
id: '1',
23+
expandedId: '1',
2424
},
2525
slots: {
2626
default: content,

src/components/DsfrAlert/DsfrAlert.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { fireEvent, render } from '@testing-library/vue'
22

33
import DsfrAlert from './DsfrAlert.vue'
44

5+
const VIcon = { props: ['name'], template: '<i :class="name"></i>' }
6+
57
describe('DsfrAlert', () => {
68
it('should mount DsfrAlert with right content', () => {
79
// Given
@@ -10,6 +12,11 @@ describe('DsfrAlert', () => {
1012

1113
// When
1214
const { getByText } = render(DsfrAlert, {
15+
global: {
16+
components: {
17+
VIcon,
18+
},
19+
},
1320
props: {
1421
title: alertTitle,
1522
description: alertDescription,
@@ -35,6 +42,11 @@ describe('DsfrAlert', () => {
3542

3643
// When
3744
const { emitted, getByTitle } = render(DsfrAlert, {
45+
global: {
46+
components: {
47+
VIcon,
48+
},
49+
},
3850
props: {
3951
title: alertTitle,
4052
description: alertDescription,

src/components/DsfrBreadcrumb/DsfrBreadcrumb.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render } from '@testing-library/vue'
22
import { createRouter, createWebHistory } from 'vue-router'
33

4-
import '@gouvfr/dsfr/dist/core/core.module.js'
4+
// import '@gouvfr/dsfr/dist/core/core.module.js'
55

66
import DsfrBreadcrumb from './DsfrBreadcrumb.vue'
77

src/components/DsfrButton/DsfrButton.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/vue'
2-
import '@gouvfr/dsfr/dist/core/core.module.js'
2+
// import '@gouvfr/dsfr/dist/core/core.module.js'
33

44
import DsfrButton from './DsfrButton.vue'
55

src/components/DsfrButton/DsfrButtonGroup.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { fireEvent } from '@testing-library/dom'
22
import { render } from '@testing-library/vue'
33

4-
import '@gouvfr/dsfr/dist/core/core.module.js'
4+
// import '@gouvfr/dsfr/dist/core/core.module.js'
5+
import { spy } from '@/../tests/unit/test-utils.js'
56

67
import DsfrButtonGroup from './DsfrButtonGroup.vue'
78

@@ -12,8 +13,8 @@ describe('DsfrButtonGroup', () => {
1213
// Given
1314
const labelPrimary = 'Button primary'
1415
const labelSecondary = 'Button secondary'
15-
const onClickFirst = jest.fn()
16-
const onClickSecond = jest.fn()
16+
const onClickFirst = spy()
17+
const onClickSecond = spy()
1718
const buttonsProps = [
1819
{
1920
label: labelPrimary,
@@ -52,8 +53,8 @@ describe('DsfrButtonGroup', () => {
5253
expect(wrapper).toHaveClass('extra-class')
5354
expect(wrapper).not.toHaveClass('fr-btns-group--right')
5455
expect(wrapper).not.toHaveClass('fr-btns-group--inline-sm')
55-
expect(onClickFirst).toHaveBeenCalled()
56-
expect(onClickSecond).toHaveBeenCalled()
56+
expect(onClickFirst.callCount).toBe(1)
57+
expect(onClickSecond.callCount).toBe(1)
5758
})
5859

5960
it('should mount small DsfrButtonGroup right-aligned content', async () => {

src/components/DsfrCallout/DsfrCallout.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { fireEvent, render } from '@testing-library/vue'
22

3-
import '@gouvfr/dsfr/dist/core/core.module.js'
3+
import { spy } from '@/../tests/unit/test-utils.js'
4+
5+
// import '@gouvfr/dsfr/dist/core/core.module.js'
46

57
import DsfrCallout from './DsfrCallout.vue'
68

@@ -31,7 +33,7 @@ describe('DsfrCallout', () => {
3133
})
3234

3335
it('should display a callout with button and icon', async () => {
34-
const onClick = jest.fn()
36+
const onClick = spy()
3537
const label = 'Label bouton'
3638
const title = 'Titre de la mise en avant'
3739
const icon = 'ri-information-line'

src/components/DsfrHeader/DsfrHeader.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fireEvent } from '@testing-library/dom'
22
import { render } from '@testing-library/vue'
33
import { createRouter, createWebHistory } from 'vue-router'
44

5-
import '@gouvfr/dsfr/dist/core/core.module.js'
5+
// import '@gouvfr/dsfr/dist/core/core.module.js'
66

77
import DsfrHeader from './DsfrHeader.vue'
88

src/components/DsfrHeader/DsfrHeader.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export default defineComponent({
104104
data-testid="header-logo"
105105
/>
106106
</div>
107+
<div class="fr-header__operator">
108+
<slot name="operator" />
109+
</div>
107110
<div
108111
v-if="isWithSlotOperator"
109112
class="fr-header__operator"

0 commit comments

Comments
 (0)