Skip to content

Commit

Permalink
chore: migrate jest to vitest (#2009)
Browse files Browse the repository at this point in the history
* chore: jest migrate vitest

* chore: remove double config

* chore: update test config

* chore: update test config

* chore: add typecheck

* chore: move dep

* chore: rename ts

* chore: typecheck move to lint

* test(formatDecimal): add test case
  • Loading branch information
liweijie0812 authored Jan 3, 2025
1 parent 6d5e0a0 commit 248efda
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 86 deletions.
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"description": "TDesign UI 样式库以及组件库公共函数(js)",
"main": "",
"scripts": {
"lint": "npm run lint:css && npm run lint:js",
"lint": "npm run lint:css && npm run lint:js && npm run typecheck",
"lint:css": "stylelint **/*.{css,wxss,less} --allow-empty-input --cache",
"lint:js": "eslint . --ext .vue,.js,.ts,.jsx,.tsx --max-warnings 0 --cache",
"lint:fix": "npm run lint:css -- --fix && npm run lint:js -- --fix",
"test": "npm run test:unit",
"test:unit": "jest --config test/script/jest.unit.conf.js --coverage",
"test:watch": "jest --config test/script/jest.unit.conf.js --watch",
"test:unit": "vitest run --coverage",
"test:watch": "vitest",
"typecheck": "tsc --noEmit",
"prepare": "husky install"
},
"repository": {
Expand All @@ -37,13 +38,13 @@
"@babel/preset-flow": "^7.12.1",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.0.3",
"@types/jest": "^27.4.1",
"@types/lodash": "4.17.13",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/experimental-utils": "^2.24.0",
"@typescript-eslint/parser": "^4.29.0",
"@typescript-eslint/typescript-estree": "^8.8.0",
"babel-jest": "^27.5.1",
"@vitest/coverage-v8": "2.1.8",
"commitizen": "^4.2.2",
"commitlint": "^17.0.3",
"conventional-changelog-cli": "^2.1.1",
Expand All @@ -53,16 +54,13 @@
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
"husky": "^8.0.1",
"jest": "^27.5.1",
"jest-html-reporter": "^3.1.3",
"jest-watch-typeahead": "^2.2.0",
"lint-staged": "~13.2.0",
"min-indent": "^1.0.1",
"postcss-less": "^5.0.0",
"stylelint": "~14.16.1",
"stylelint-config-standard": "^24.0.0",
"ts-jest": "^27.1.3",
"typescript": "^4.5.5"
"typescript": "^4.5.5",
"vitest": "^2.1.8"
},
"browserslist": [
"> 3%",
Expand Down
40 changes: 0 additions & 40 deletions test/script/jest.base.conf.js

This file was deleted.

34 changes: 0 additions & 34 deletions test/script/jest.unit.conf.js

This file was deleted.

1 change: 1 addition & 0 deletions test/unit/date-picker/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { extractTimeFormat } from '../../../js/date-picker/utils';

describe('utils', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/input-number/compareLargeNumber.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { compareNumber, compareLargeNumber, isInputNumber, formatENumber } from '../../../js/input-number/large-number';

describe('compareNumber', () => {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/input-number/formatDecimal.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { formatDecimal, decimalPlacesToFixedNum } from '../../../js/input-number/large-number';

describe('formatDecimal', () => {
Expand All @@ -9,6 +10,22 @@ describe('formatDecimal', () => {
expect(formatDecimal(1, 0, false)).toBe('1');
});

it('1, 1, true', () => {
expect(formatDecimal(1, 1, true)).toBe('1.0');
});

it('1.0, 1, true', () => {
expect(formatDecimal(1.0, 1, true)).toBe('1.0');
});

it('1.0, 1, false', () => {
expect(formatDecimal(1.0, 1, false)).toBe('1.0');
});

it('1.0, 2, true', () => {
expect(formatDecimal(1.0, 2, true)).toBe('1.00');
});

it('1.5, 0, true', () => {
expect(formatDecimal(1.5, 0, true)).toBe('2');
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/input-number/largeIntNumberAdd.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { largeIntNumberAdd } from '../../../js/input-number/large-number';

describe('largeIntNumberAdd', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/input-number/largeNumberAdd.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { largeNumberAdd } from '../../../js/input-number/large-number';

/**
Expand Down
1 change: 1 addition & 0 deletions test/unit/input-number/largeNumberSubtract.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { largeNumberSubtract } from '../../../js/input-number/large-number';

describe('largeNumberSubtract', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/input-number/largeNumberToFixed.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { largeNumberToFixed } from '../../../js/input-number/large-number';

/**
Expand Down
3 changes: 2 additions & 1 deletion test/unit/input-number/number.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { add, subtract, formatThousandths, canInputNumber, canSetValue, formatUnCompleteNumber } from '../../../js/input-number/number';

describe('add', () => {
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('canInputNumber', () => {
});
});

describe('canSetValue', () => {
it('canSetValue', () => {
expect(canSetValue('2', 1)).toBe(true);
expect(canSetValue('2', 1)).toBe(true);
expect(canSetValue('2.0', 2)).toBe(false);
Expand Down
1 change: 1 addition & 0 deletions test/unit/time-picker/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { getPickerCols } from '../../../js/time-picker/utils';

describe('utils', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/activable.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/append.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/checkable.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/disabled.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';

// 禁用状态
Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/event.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/expand.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';

// 节点展开状态
Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/filter.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/get-node.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/init.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import TreeNode from '../../../js/tree/tree-node';
import { delay } from './kit';
Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/lazy.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/tree/model.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import TreeStore from '../../../js/tree/tree-store';
import { delay } from './kit';

Expand Down
1 change: 1 addition & 0 deletions test/unit/upload/returnFileSize.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { returnFileSize } from '../../../js/upload/utils';

describe('returnFileSize', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/upload/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { validateFileType } from '../../../js/upload/utils';

describe('validateFileType', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
},
"include": ["js"],
"exclude": ["node_modules"],
"types": ["jest"],
"types": ["vitest/global"],
"compileOnSave": false
}
13 changes: 13 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['test/unit/**/*test.{ts,js}'],
coverage: {
reportsDirectory: './test/coverage',
include: ['js/**/*.ts'],
exclude: ['js/global-config'],
reporter: ['text', 'json', 'html'],
},
},
});

0 comments on commit 248efda

Please sign in to comment.