feat:添加自动化测试

This commit is contained in:
zhangyu
2022-04-15 13:42:54 +08:00
parent 4f5e25bfb6
commit 923b8679e8
9 changed files with 3491 additions and 4 deletions

View File

@@ -8,7 +8,7 @@
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"],
"plugins": ["transform-vue-jsx", "transform-runtime", "transform-es2015-modules-commonjs"],
"env": {
"utils": {
"presets": [
@@ -32,8 +32,9 @@
}]
]
},
"test": {
"plugins": ["istanbul"]
"jest": {
"presets": ["env"],
// "plugins": ["transform-es2015-modules-commonjs"]
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,8 @@
"dev": "node --max-old-space-size=10240 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js",
"lint": "eslint --fix --ext .js,.vue src"
"lint": "eslint --fix --ext .js,.vue src",
"unit": "jest --config test/unit/jest.conf.js --coverage"
},
"dependencies": {
"@johmun/vue-tags-input": "^2.1.0",
@@ -56,11 +57,15 @@
"xterm": "^3.1.0"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.17.9",
"@vue/test-utils": "^1.0.0-beta.13",
"autoprefixer": "^7.1.2",
"babel-core": "^6.26.0",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-jest": "^23.6.0",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"babel-preset-env": "^1.7.0",
@@ -81,6 +86,9 @@
"generate-asset-webpack-plugin": "^0.3.0",
"git-revision-webpack-plugin": "^3.0.6",
"html-webpack-plugin": "^2.30.1",
"jest": "^24.0.0",
"jest-serializer-vue": "^0.3.0",
"jest-transform-stub": "^2.0.0",
"lodash": "^4.17.21",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
@@ -97,6 +105,7 @@
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-jest": "^1.0.2",
"vue-loader": "^13.3.0",
"vue-resource": "^1.5.1",
"vue-style-loader": "^3.0.1",

View File

@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}

View File

@@ -0,0 +1,3 @@
module.exports = {
get: jest.fn(() => Promise.resolve({ status: 200 }))
}

View File

@@ -0,0 +1 @@
module.exports = 'test-file-stub';

View File

@@ -0,0 +1 @@
module.exports = {}

View File

@@ -0,0 +1,40 @@
const path = require('path')
module.exports = {
verbose: true,
// testURL: 'http://localhost/',
rootDir: path.resolve(__dirname, '../../'),
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
},
// moduleFileExtensions: [
// 'js',
// 'json',
// 'vue'
// ],
moduleNameMapper: {
'^@\/(.*?\.?(js|vue)?|)$': '<rootDir>/src/$1', // @路径转换,例如:@/components/Main.vue -> rootDir/src/components/Main.vue
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/test/unit/__mocks__/fileMock.js', // 模拟加载静态文件
'\\.(css|less|scss|sass)$': '<rootDir>/test/unit/__mocks__/styleMock.js'  // 模拟加载样式文件
},
testMatch: [ // 匹配测试用例的文件
'<rootDir>/test/unit/specs/*.spec.js'
],
moduleDirectories: [
'node_modules'
],
// testPathIgnorePatterns: [
// '<rootDir>/test/e2e'
// ],
// setupFiles: ['<rootDir>/test/unit/setup'],
// snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
coverageDirectory: '<rootDir>/test/unit/coverage', // 覆盖率报告的目录
collectCoverageFrom: [ // 测试报告想要覆盖那些文件,目录,前面加!是避开这些文件
// 'test/unit/specs/*.(js)',
'src/components/common/js/tool.js'
// '!src/main.js',
// '!src/router/index.js',
// '!**/node_modules/**'
]
}

View File

@@ -0,0 +1,17 @@
import { dealLegendAlias } from '@/components/common/js/tools'
describe('别名替换函数', () => {
// 测试代码可读性最好
// 分组
it('正常替换一个', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{a}}')).toBe('1')
})
it('正常替换多个个', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{a}}{{b}}')).toBe('12')
})
it('匹配不到', () => {
expect(dealLegendAlias('{a:1,b:2}', '{{c}}')).toBe('')
})
it('没有legend', () => {
expect(dealLegendAlias('{a:1,b:2}', '')).toBe('{a:1,b:2}')
})
})