test: add jest

This commit is contained in:
LeoKu 2021-10-17 20:31:36 +08:00
parent 024f9afd5c
commit 01c4307174
9 changed files with 2494 additions and 38 deletions

View File

@ -2,6 +2,7 @@ module.exports = {
root: true, root: true,
env: { env: {
node: true, node: true,
jest: true,
}, },
globals: { globals: {
defineProps: 'readonly', defineProps: 'readonly',

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ dist-ssr
*.local *.local
yarn-error.log yarn-error.log
stats.html stats.html
coverage

6
babel.config.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
}

18
jest.config.js Normal file
View File

@ -0,0 +1,18 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
testEnvironment: 'jsdom',
}

View File

@ -5,7 +5,7 @@
"license": "MIT", "license": "MIT",
"author": "LeoKu<czc12580520@gmail.com> (https://leoku.top)", "author": "LeoKu<czc12580520@gmail.com> (https://leoku.top)",
"scripts": { "scripts": {
"build": "vite build", "build": "npm run test && vite build",
"build:prerelease": "vite build --mode prerelease", "build:prerelease": "vite build --mode prerelease",
"deps": "yarn upgrade-interactive --latest", "deps": "yarn upgrade-interactive --latest",
"dev": "vite", "dev": "vite",
@ -15,7 +15,8 @@
"lint:style": "stylelint \"src/**/*.{css,scss,vue}\"", "lint:style": "stylelint \"src/**/*.{css,scss,vue}\"",
"lint:ts": "tsc --noEmit --skipLibCheck", "lint:ts": "tsc --noEmit --skipLibCheck",
"prepare": "husky install", "prepare": "husky install",
"preview": "vite preview" "preview": "vite preview",
"test": "jest"
}, },
"dependencies": { "dependencies": {
"canvas-confetti": "^1.4.0", "canvas-confetti": "^1.4.0",
@ -27,11 +28,16 @@
"vuex": "^4.0.2" "vuex": "^4.0.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@types/canvas-confetti": "^1.4.2", "@types/canvas-confetti": "^1.4.2",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.32.0", "@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0", "@typescript-eslint/parser": "^4.32.0",
"@vitejs/plugin-vue": "^1.9.2", "@vitejs/plugin-vue": "^1.9.2",
"@vue/compiler-sfc": "^3.2.19", "@vue/compiler-sfc": "^3.2.19",
"babel-jest": "^27.2.5",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2", "eslint-plugin-import": "^2.24.2",
@ -40,6 +46,7 @@
"eslint-plugin-tailwindcss": "^1.16.0", "eslint-plugin-tailwindcss": "^1.16.0",
"eslint-plugin-vue": "^7.18.0", "eslint-plugin-vue": "^7.18.0",
"husky": "^7.0.2", "husky": "^7.0.2",
"jest": "^27.2.5",
"lint-staged": "^11.1.2", "lint-staged": "^11.1.2",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"rollup-plugin-visualizer": "^5.5.2", "rollup-plugin-visualizer": "^5.5.2",

View File

@ -0,0 +1,16 @@
import localeEN from '../i18n/locales/en'
import localeZH from '../i18n/locales/zh'
import { highlightJSON } from '../utils'
test('highlightJSON', () => {
const str = JSON.stringify({ a: 1, b: '2' })
expect(highlightJSON(str)).toMatch('key')
expect(highlightJSON(str)).toMatch('number')
expect(highlightJSON(str)).toMatch('string')
})
test('check locales completeness', () => {
const zh = Reflect.ownKeys(localeZH).sort()
const en = Reflect.ownKeys(localeEN).sort()
expect(zh).toEqual(en)
})

View File

@ -97,7 +97,7 @@ export const NONE = 'none'
export const TRIGGER_PROBABILITY = 0.1 export const TRIGGER_PROBABILITY = 0.1
export const SPECIAL_AVATARS: Readonly<AvatarOption>[] = [ export const SPECIAL_AVATARS: Readonly<AvatarOption[]> = [
{ {
wrapperShape: 'squircle', wrapperShape: 'squircle',
background: { background: {

View File

@ -102,7 +102,7 @@ export function getRandomAvatarOption(
return avatarOption return avatarOption
} }
export function getSpecialAvatarOption() { export function getSpecialAvatarOption(): AvatarOption {
return SPECIAL_AVATARS[Math.floor(Math.random() * SPECIAL_AVATARS.length)] return SPECIAL_AVATARS[Math.floor(Math.random() * SPECIAL_AVATARS.length)]
} }

2475
yarn.lock

File diff suppressed because it is too large Load Diff