Skip to content

Commit

Permalink
build(infra): use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
EAGzzyCSL committed Mar 23, 2024
1 parent e696a9c commit 77608d1
Show file tree
Hide file tree
Showing 29 changed files with 550 additions and 1,849 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
'packages/**/*.test.ts',
'packages/**/*.test.tsx',
],
extends: ['@mine/eslint-config/jest'],
extends: ['@mine/eslint-config/vitest'],
rules: {
'import/no-extraneous-dependencies': [
'error',
Expand Down
44 changes: 0 additions & 44 deletions jest.config.mjs

This file was deleted.

17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"site:route": "yarn workspace @mine/site run route",
"site:serve": "yarn workspace @mine/site run serve",
"site:storybook": "yarn workspace @mine/site run storybook",
"test": "jest",
"test:ci": "jest --coverage",
"test": "vitest run",
"test:ci": "vitest run --coverage",
"ts:check": "lerna run ts:check",
"verify": "npm-run-all prettier lint:md lint:style lint:es test ts:check lint:commit"
},
Expand All @@ -45,21 +45,17 @@
"@mine/commitlint-config": "^0.0.0",
"@mine/eslint-config": "^0.0.0",
"@mine/prettier-config": "^0.0.0",
"@mine/simple-jest-transform-yaml": "^0.0.0",
"@mine/stylelint-config": "^0.0.0",
"@swc/core": "^1.4.1",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.1",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.11.5",
"cloc": "^2.9.0",
"commitizen": "^4.3.0",
"cz-customizable": "^7.0.0",
"eslint": "^8.56.0",
"husky": "^9.0.10",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-config": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"js-yaml": "^4.1.0",
"jsdom": "^24.0.0",
"lerna": "^8.1.2",
"markdownlint": "^0.33.0",
"markdownlint-cli": "^0.39.0",
Expand All @@ -68,6 +64,7 @@
"postcss-scss": "^4.0.2",
"prettier": "^3.2.5",
"stylelint": "^15.10.0",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.4.0"
}
}
8 changes: 0 additions & 8 deletions packages/eslint/jest.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-css-modules": "^2.12.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0"
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-vitest": "^0.3.26"
},
"peerDependencies": {
"eslint": "^8.2.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint/vitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['plugin:vitest/recommended'],
plugins: ['vitest'],
env: {
node: true,
},
}
3 changes: 2 additions & 1 deletion packages/markdown-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"gray-matter": "^4.0.3",
"markdown-toc": "^1.2.0"
"markdown-toc": "^1.2.0",
"vitest": "^1.4.0"
}
}
2 changes: 2 additions & 0 deletions packages/markdown-loader/src/article.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from 'vitest'

import { articleProcessor } from './article'

test('处理结构完整的markdown', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/markdown-loader/src/utils/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from 'vitest'

import { createLoader } from './index'

test('loader工作情况', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/markdown-loader/src/utils/toc.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { extractToc } from './toc'

describe('从markdown content解析目录', () => {
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions packages/simple-jest-transform-yaml/index.mjs

This file was deleted.

7 changes: 0 additions & 7 deletions packages/simple-jest-transform-yaml/index.test.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/simple-jest-transform-yaml/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions packages/site/apps/Calculator/panels/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { getBMIString, calBMIValue, calDPI, ceilFixed } from './functions'

test('DPI计算', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/site/apps/Calculator/utils/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { isNumberString } from './validate'

describe('isNumber', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/site/apps/Launcher/NotFound.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'

import * as renderer from 'react-test-renderer'
import { test, expect } from 'vitest'

import NotFound from './NotFound'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`render NotFound 1`] = `
<section
className="notFound"
className="_notFound_e679f1"
>
<svg
aria-hidden={true}
Expand Down
2 changes: 2 additions & 0 deletions packages/site/apps/Launcher/utils/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from 'vitest'

import { jointGoogleSearchUrl } from './index'

test('jointGoogleSearchUrl', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/site/apps/MetroConstellation/parts/MetroMap.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { IMetroStation } from '../type'

import { calcLineProps, calcBackground } from './MetroMap'
Expand Down
2 changes: 2 additions & 0 deletions packages/site/apps/WinterNine/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import {
smoothPoints,
getNineDescription,
Expand Down
1 change: 1 addition & 0 deletions packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"three": "^0.161.0",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vitest": "^1.4.0",
"webpack": "^5.89.0",
"yaml-loader": "^0.8.0"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/site/router/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { getParentAppPath, getAppName } from './index'

describe('使用getParentAppPath获取路由父级页面', () => {
Expand All @@ -10,6 +12,7 @@ describe('使用getParentAppPath获取路由父级页面', () => {
expect(getParentAppPath(route)).toBe(parent)
})
})

describe('使用getAppName获取页面的 appName', () => {
test.each([
['launch首页', '/', 'Launcher'],
Expand Down
2 changes: 2 additions & 0 deletions packages/site/utils/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import { getRestrictValue } from './index'

describe('getRestrictValue', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/site/utils/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from 'vitest'

import {
camel2snake,
camel2kebab,
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions packages/site/utils/yaml/yaml.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from 'vitest'

import yamlDemo from './yaml-demo.yaml'

test('transform-yaml', () => {
expect(yamlDemo).toMatchInlineSnapshot(`
{
"fruits": [
"apple",
"banana",
"cherry",
],
}
`)
})
27 changes: 27 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineConfig } from 'vitest/config'
import * as path from 'path'
import * as jsYaml from 'js-yaml'

export default defineConfig({
test: {
include: ['**/*.test.{ts,tsx,js}'],
exclude: ['node_modules', 'packages/site/.next/**'],
coverage: {
reporter: ['text', 'text-summary'],
},
alias: {
'@': path.resolve(__dirname, './packages/site'),
},
environment: 'jsdom',
},
plugins: [
{
name: '',
transform(code, id) {
if (id.endsWith('.yaml')) {
return `export default ${JSON.stringify(jsYaml.load(code))};`
}
},
},
],
})
Loading

0 comments on commit 77608d1

Please sign in to comment.