Skip to content

Commit 48deea9

Browse files
committed
chore: migrate to vitest
1 parent 2492a60 commit 48deea9

33 files changed

+2960
-4938
lines changed

.circleci/config.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# See: https://circleci.com/docs/2.0/configuration-reference
33
version: 2.1
44

5-
orbs:
6-
# The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize
7-
# Orbs reduce the amount of configuration required for common tasks.
8-
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
9-
node: circleci/[email protected]
10-
115
jobs:
126
# Below is the definition of your job to build and test your app, you can rename and customize it as you want.
137
test:
@@ -38,7 +32,7 @@ jobs:
3832
command: pnpm build
3933
- run:
4034
name: Generate Coverage
41-
command: pnpm cover:ci
35+
command: pnpm cover
4236
- run:
4337
name: Upload Coverage
4438
command: bash <(curl -s https://codecov.io/bash)

.eslintrc.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
"env": {
44
"browser": true,
55
"commonjs": true,
6-
"es6": true,
7-
"jest/globals": true
6+
"es6": true
87
},
9-
"extends": [
10-
"standard",
11-
"plugin:jest/recommended",
12-
"plugin:@typescript-eslint/recommended",
13-
"plugin:prettier/recommended"
14-
],
15-
"plugins": ["jest", "prettier", "@typescript-eslint"],
8+
"extends": ["standard", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
9+
"plugins": ["prettier", "@typescript-eslint"],
1610
"rules": {
1711
"@typescript-eslint/camelcase": "off",
1812
"@typescript-eslint/explicit-function-return-type": "off",

jest.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

jest.setup.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
"homepage": "https://vee-validate.logaretm.com",
88
"repository": "https://github.com/logaretm/vee-validate",
99
"scripts": {
10-
"test": "jest",
11-
"test:ci": "jest --ci --detectOpenHandles --runInBand",
10+
"test": "vitest",
1211
"lint": "eslint . '**/*.{js,jsx,ts,tsx}' --fix",
1312
"format": "prettier \"./**/*.ts\" --write",
1413
"build": "node scripts/build.mjs",
15-
"cover": "jest --coverage",
16-
"cover:ci": "jest --coverage --ci --runInBand --detectOpenHandles",
14+
"cover": "vitest run --coverage",
1715
"postversion": "npm run build",
1816
"docs:dev": "cd ./docs && npm run dev && cd -",
1917
"postinstall": "husky install"
@@ -23,16 +21,15 @@
2321
"@commitlint/config-conventional": "^17.4.4",
2422
"@rollup/plugin-replace": "^5.0.2",
2523
"@rollup/plugin-typescript": "^11.0.0",
26-
"@types/jest": "^29.4.0",
27-
"@typescript-eslint/eslint-plugin": "^5.54.1",
28-
"@typescript-eslint/parser": "^5.54.1",
24+
"@typescript-eslint/eslint-plugin": "^5.56.0",
25+
"@typescript-eslint/parser": "^5.56.0",
26+
"@vitest/coverage-c8": "^0.29.7",
2927
"@vue/devtools-api": "^6.5.0",
3028
"chalk": "^5.2.0",
31-
"eslint": "^8.35.0",
32-
"eslint-config-prettier": "^8.7.0",
29+
"eslint": "^8.36.0",
30+
"eslint-config-prettier": "^8.8.0",
3331
"eslint-config-standard": "^17.0.0",
3432
"eslint-plugin-import": "^2.27.5",
35-
"eslint-plugin-jest": "^27.2.1",
3633
"eslint-plugin-n": "^15.6.1",
3734
"eslint-plugin-prettier": "^4.0.0",
3835
"eslint-plugin-promise": "^6.1.1",
@@ -42,25 +39,24 @@
4239
"fs-extra": "^11.1.0",
4340
"gzip-size": "^7.0.0",
4441
"husky": "^8.0.3",
45-
"jest": "^29.5.0",
46-
"jest-environment-jsdom": "^29.5.0",
42+
"jsdom": "^21.1.1",
4743
"klona": "^2.0.6",
4844
"lerna": "^6.5.1",
49-
"lint-staged": "^13.1.2",
45+
"lint-staged": "^13.2.0",
5046
"prettier": "^2.8.4",
5147
"prettier-plugin-astro": "^0.8.0",
5248
"raf-stub": "^3.0.0",
53-
"rollup": "^3.19.0",
49+
"rollup": "^3.20.0",
5450
"rollup-plugin-commonjs": "^10.1.0",
55-
"rollup-plugin-dts": "^5.2.0",
51+
"rollup-plugin-dts": "^5.3.0",
5652
"rollup-plugin-json": "^4.0.0",
5753
"rollup-plugin-node-resolve": "^5.2.0",
5854
"terser": "^5.16.6",
59-
"ts-jest": "^29.0.5",
6055
"tslint-config-prettier": "^1.18.0",
6156
"tslint-config-standard": "^9.0.0",
6257
"type-fest": "^3.6.1",
6358
"typescript": "4.9.5",
59+
"vitest": "^0.29.7",
6460
"vue": "^3.2.47",
6561
"yup": "^1.0.2"
6662
},
@@ -71,11 +67,11 @@
7167
"*.ts": [
7268
"eslint --fix",
7369
"prettier --write",
74-
"jest --maxWorkers=1 --bail --findRelatedTests"
70+
"vitest run related"
7571
],
7672
"*.js": [
7773
"eslint --fix",
78-
"jest --maxWorkers=1 --bail --findRelatedTests"
74+
"vitest run related"
7975
]
8076
}
8177
}

packages/rules/tests/dimensions.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import helpers from './helpers';
44
let fails = false;
55

66
beforeEach(() => {
7-
(globalThis as any).window.URL = {
8-
createObjectURL() {
9-
return 'data:image/png;base64,AAAAAAA';
10-
},
7+
window.URL.createObjectURL = () => {
8+
return 'data:image/png;base64,AAAAAAA';
119
};
1210

13-
(globalThis as any).window.webkitURL = {
11+
(window as any).webkitURL = {
1412
createObjectURL() {
1513
return 'data:image/png;base64,AAAAAAA';
1614
},
1715
};
1816

19-
(globalThis as any).Image = class Image {
17+
(window as any).Image = class Image {
2018
get src() {
2119
return 'test';
2220
}
@@ -49,7 +47,7 @@ test('validates image dimensions', async () => {
4947
result = await validate([helpers.file('file.jpg', 'image/jpeg', 10)], { width: 15, height: 10 });
5048
expect(result).toBe(false);
5149

52-
(globalThis as any).URL = undefined; // test webkit fallback.
50+
(window as any).URL = undefined; // test webkit fallback.
5351
result = await validate([helpers.file('file.jpg', 'image/jpeg', 10)], { width: 150, height: 100 });
5452
expect(result).toBe(true);
5553
});

packages/vee-validate/tests/Field.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mountWithHoc, setValue, dispatchEvent, setChecked, flushPromises, dispa
33
import * as yup from 'yup';
44
import { computed, reactive, ref, Ref } from 'vue';
55

6-
jest.useFakeTimers();
6+
vi.useFakeTimers();
77

88
beforeEach(() => {
99
configure({
@@ -117,7 +117,7 @@ describe('<Field />', () => {
117117
<input v-bind="field" type="text">
118118
<span id="fieldError">{{ errors[0] }}</span>
119119
</Field>
120-
120+
121121
<Field name="other" rules="required" v-slot="{ errors, field }">
122122
<input v-bind="field" type="text">
123123
<span>{{ errors[0] }}</span>
@@ -368,7 +368,7 @@ describe('<Field />', () => {
368368
});
369369

370370
test('file values are normalized depending', async () => {
371-
const onSubmit = jest.fn();
371+
const onSubmit = vi.fn();
372372

373373
const wrapper = mountWithHoc({
374374
template: `
@@ -487,7 +487,7 @@ describe('<Field />', () => {
487487
setValue(input, '123');
488488
setValue(input, '12');
489489
setValue(input, '');
490-
jest.advanceTimersByTime(100);
490+
vi.advanceTimersByTime(100);
491491
await flushPromises();
492492
// LAST message should be the required one.
493493
expect(error.textContent).toBe(REQUIRED_MESSAGE);
@@ -820,7 +820,7 @@ describe('<Field />', () => {
820820

821821
// #3048
822822
test('proxies native listeners', async () => {
823-
const onBlur = jest.fn();
823+
const onBlur = vi.fn();
824824
mountWithHoc({
825825
setup() {
826826
return {
@@ -839,7 +839,7 @@ describe('<Field />', () => {
839839
});
840840

841841
test('can customize checkboxes unchecked value', async () => {
842-
const spy = jest.fn();
842+
const spy = vi.fn();
843843
const wrapper = mountWithHoc({
844844
setup() {
845845
return { onSubmit: spy };
@@ -1167,10 +1167,10 @@ describe('<Field />', () => {
11671167
});
11681168

11691169
test('should have correct field object binding properties based on file type', async () => {
1170-
const textualType = jest.fn();
1171-
const fileType = jest.fn();
1172-
const checkboxType = jest.fn();
1173-
const radioType = jest.fn();
1170+
const textualType = vi.fn();
1171+
const fileType = vi.fn();
1172+
const checkboxType = vi.fn();
1173+
const radioType = vi.fn();
11741174

11751175
mountWithHoc({
11761176
template: `
@@ -1200,7 +1200,7 @@ describe('<Field />', () => {
12001200
});
12011201

12021202
await flushPromises();
1203-
const lastCallOf = (fn: ReturnType<typeof jest.fn>) => fn.mock.calls[fn.mock.calls.length - 1][0];
1203+
const lastCallOf = (fn: ReturnType<typeof vi.fn>) => fn.mock.calls[fn.mock.calls.length - 1][0];
12041204
expect(lastCallOf(textualType)).toHaveProperty('value');
12051205
expect(lastCallOf(fileType)).not.toHaveProperty('value');
12061206
expect(lastCallOf(checkboxType)).toHaveProperty('checked');

packages/vee-validate/tests/FieldArray.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { mountWithHoc, setValue, getValue, dispatchEvent, flushPromises } from '
66
const REQUIRED_MESSAGE = 'REQUIRED';
77

88
test('warns if no form is detected', async () => {
9-
const spy = jest.spyOn(console, 'warn').mockImplementation();
9+
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {
10+
// NOOP
11+
});
1012

1113
mountWithHoc({
1214
template: `
@@ -20,7 +22,9 @@ test('warns if no form is detected', async () => {
2022
});
2123

2224
test('warns if no name path is provided', async () => {
23-
const spy = jest.spyOn(console, 'warn').mockImplementation();
25+
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {
26+
// NOOP
27+
});
2428

2529
mountWithHoc({
2630
template: `
@@ -36,7 +40,7 @@ test('warns if no name path is provided', async () => {
3640
});
3741

3842
test('adds items to the end of the array with push()', async () => {
39-
const onSubmit = jest.fn();
43+
const onSubmit = vi.fn();
4044
mountWithHoc({
4145
setup() {
4246
const initialValues = {
@@ -151,7 +155,7 @@ test('array fields should update their values when swapped', async () => {
151155
});
152156

153157
test('can swap array fields with swap helper', async () => {
154-
const onSubmit = jest.fn();
158+
const onSubmit = vi.fn();
155159
mountWithHoc({
156160
setup() {
157161
const schema = yup.object({
@@ -470,7 +474,7 @@ test('can update an item value at a given array index', async () => {
470474
});
471475

472476
test('can update an item value directly with .value setter', async () => {
473-
const onSubmit = jest.fn();
477+
const onSubmit = vi.fn();
474478
mountWithHoc({
475479
setup() {
476480
const initial = {
@@ -522,7 +526,7 @@ test('can update an item value directly with .value setter', async () => {
522526
});
523527

524528
test('adds items to the start of the array with prepend()', async () => {
525-
const onSubmit = jest.fn();
529+
const onSubmit = vi.fn();
526530
mountWithHoc({
527531
setup() {
528532
const initialValues = {
@@ -577,7 +581,7 @@ test('adds items to the start of the array with prepend()', async () => {
577581

578582
// #3664
579583
test('clears old errors path when item is removed when no form schema is present', async () => {
580-
const onSubmit = jest.fn();
584+
const onSubmit = vi.fn();
581585
mountWithHoc({
582586
setup() {
583587
const initialValues = {
@@ -631,7 +635,7 @@ test('clears old errors path when item is removed when no form schema is present
631635

632636
// #3748
633637
test('clears old errors path when last item is removed and value update validation is on', async () => {
634-
const onSubmit = jest.fn();
638+
const onSubmit = vi.fn();
635639
defineRule('required', (v: any) => (v ? true : REQUIRED_MESSAGE));
636640
const InputField = defineComponent({
637641
props: {
@@ -719,7 +723,7 @@ test('clears old errors path when last item is removed and value update validati
719723
});
720724

721725
test('moves items around the array with move()', async () => {
722-
const onSubmit = jest.fn();
726+
const onSubmit = vi.fn();
723727
mountWithHoc({
724728
setup() {
725729
const initialValues = {
@@ -776,7 +780,7 @@ test('moves items around the array with move()', async () => {
776780

777781
// #3782
778782
test('removing an item marks the form as dirty', async () => {
779-
const onSubmit = jest.fn();
783+
const onSubmit = vi.fn();
780784
mountWithHoc({
781785
setup() {
782786
const initialValues = {

0 commit comments

Comments
 (0)