diff --git a/.gitignore b/.gitignore index 887ce1ed..78a752d8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ yarn-debug.log* yarn-error.log* **/*.log -test/unit/coverage -test/e2e/reports +tests/**/coverage/ +tests/e2e/reports selenium-debug.log # Editor directories and files diff --git a/babel.config.js b/babel.config.js index 6f812f61..ba179669 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,14 +1,5 @@ module.exports = { presets: [ - ['@vue/app', { modules: 'commonjs' }] - ], - plugins: [], - env: { - test: { - presets: [ - ['@vue/app', { modules: 'commonjs' }] - ], - plugins: ['istanbul'] - } - } + '@vue/app' + ] } diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..5a8aa6bb --- /dev/null +++ b/jest.config.js @@ -0,0 +1,24 @@ +module.exports = { + verbose: true, + moduleFileExtensions: ['js', 'jsx', 'json', 'vue'], + transform: { + '^.+\\.vue$': 'vue-jest', + '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', + '^.+\\.jsx?$': 'babel-jest' + }, + moduleNameMapper: { + '^@/(.*)$': '/src/$1' + }, + snapshotSerializers: ['jest-serializer-vue'], + testMatch: [ + '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)' + ], + collectCoverageFrom: ['src/utils/**/*.{js,vue}', '!src/utils/auth.js', '!src/utils/request.js', 'src/components/**/*.{js,vue}'], + coverageDirectory: '/tests/unit/coverage', + // 'collectCoverage': true, + 'coverageReporters': [ + 'lcov', + 'text-summary' + ], + testURL: 'http://localhost/' +} diff --git a/package.json b/package.json index 2a11617a..90812d59 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "build:sit": "vue-cli-service build --mode text", "lint": "eslint --ext .js,.vue src", "test": "npm run lint", + "test:unit": "vue-cli-service test:unit", "precommit": "lint-staged", "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml" }, diff --git a/src/components/Hamburger/index.vue b/src/components/Hamburger/index.vue index 26472e23..04c5881a 100644 --- a/src/components/Hamburger/index.vue +++ b/src/components/Hamburger/index.vue @@ -33,10 +33,11 @@ export default { isActive: { type: Boolean, default: false - }, - toggleClick: { - type: Function, - default: null + } + }, + methods: { + toggleClick() { + this.$emit('toggleClick') } } } diff --git a/src/utils/index.js b/src/utils/index.js index 0445827b..766906a2 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -36,7 +36,11 @@ export function parseTime(time, cFormat) { } export function formatTime(time, option) { - time = +time * 1000 + if (('' + time).length === 10) { + time = parseInt(time) * 1000 + } else { + time = +time + } const d = new Date(time) const now = Date.now() diff --git a/src/utils/validate.js b/src/utils/validate.js index ada0e7e2..b4800be3 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -2,7 +2,7 @@ * Created by jiachenpan on 16/11/18. */ -export function isvalidUsername(str) { +export function validUsername(str) { const valid_map = ['admin', 'editor'] return valid_map.indexOf(str.trim()) >= 0 } diff --git a/src/views/layout/components/Navbar.vue b/src/views/layout/components/Navbar.vue index 7bae38e0..6899f399 100644 --- a/src/views/layout/components/Navbar.vue +++ b/src/views/layout/components/Navbar.vue @@ -1,6 +1,6 @@