diff --git a/docs/site/mobile.js b/docs/site/mobile.js index 4b745f262..154453851 100644 --- a/docs/site/mobile.js +++ b/docs/site/mobile.js @@ -8,7 +8,7 @@ Vue.mixin({ computed: { $t() { const { name } = this.$options; - const { lang } = this.$route.meta || {}; + const { lang = 'zh-CN' } = (this.$route && this.$route.meta) || {}; const prefix = name ? camelize(name) + '.' : ''; const messages = this.$vantMessages[lang]; @@ -22,7 +22,7 @@ Vue.mixin({ beforeCreate() { const { i18n, name } = this.$options; - if (i18n) { + if (i18n && name) { const locales = {}; const camelizedName = camelize(name); diff --git a/packages/vant-cli/src/commands/jest.ts b/packages/vant-cli/src/commands/jest.ts index 3924ebc61..30d3da468 100644 --- a/packages/vant-cli/src/commands/jest.ts +++ b/packages/vant-cli/src/commands/jest.ts @@ -1,10 +1,15 @@ import { runCLI } from 'jest'; import { setNodeEnv } from '../common'; -import { CWD, JEST_CONFIG_FILE } from '../common/constant'; +import { genPackageEntry } from '../compiler/gen-package-entry'; +import { CWD, JEST_CONFIG_FILE, PACKAGE_ENTRY_FILE } from '../common/constant'; export function test(command: any) { setNodeEnv('test'); + genPackageEntry({ + outputPath: PACKAGE_ENTRY_FILE + }); + const config = { rootDir: CWD, watch: command.watch, diff --git a/packages/vant-cli/src/common/constant.ts b/packages/vant-cli/src/common/constant.ts index a674dc985..97c384b2f 100644 --- a/packages/vant-cli/src/common/constant.ts +++ b/packages/vant-cli/src/common/constant.ts @@ -22,6 +22,7 @@ export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json'); export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js'); export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js'); export const POSTCSS_CONFIG_FILE = join(CONFIG_DIR, 'postcss.config.js'); +export const JEST_INIT_FILE = join(CONFIG_DIR, 'jest.init.js'); export const JEST_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js'); export const JEST_FILE_MOCK_FILE = join(CONFIG_DIR, 'jest.file-mock.js'); export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js'); diff --git a/packages/vant-cli/src/config/jest.config.ts b/packages/vant-cli/src/config/jest.config.ts index 8c7e072e2..3acc2cdc1 100644 --- a/packages/vant-cli/src/config/jest.config.ts +++ b/packages/vant-cli/src/config/jest.config.ts @@ -1,4 +1,5 @@ import { + JEST_INIT_FILE, JEST_FILE_MOCK_FILE, JEST_STYLE_MOCK_FILE } from '../common/constant'; @@ -8,6 +9,7 @@ module.exports = { '\\.(css|less|scss)$': JEST_STYLE_MOCK_FILE, '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': JEST_FILE_MOCK_FILE }, + setupFiles: [JEST_INIT_FILE], moduleFileExtensions: ['js', 'jsx', 'vue', 'ts', 'tsx'], transform: { '\\.(vue)$': 'vue-jest', @@ -18,9 +20,7 @@ module.exports = { collectCoverageFrom: [ 'src/**/*.{js,jsx,ts,tsx,vue}', '!**/style/**', - '!**/demo/**', - '!**/locale/lang/**', - '!**/sku/**' + '!**/demo/**' ], collectCoverage: true, coverageReporters: ['html', 'lcov', 'text-summary'], diff --git a/packages/vant-cli/src/config/jest.init.ts b/packages/vant-cli/src/config/jest.init.ts new file mode 100644 index 000000000..a11b37b59 --- /dev/null +++ b/packages/vant-cli/src/config/jest.init.ts @@ -0,0 +1,5 @@ +import Vue from 'vue'; +// @ts-ignore +import Package from '../../dist/package-entry'; + +Vue.use(Package); diff --git a/test/demo.ts b/test/demo.ts index 0ef71b2e6..ebcdb5b05 100644 --- a/test/demo.ts +++ b/test/demo.ts @@ -1,5 +1,5 @@ import Vue, { CreateElement } from 'vue'; -import '../docs/site/mobile/demo-common'; +import '../docs/site/mobile'; import Locale from '../src/locale'; import { mount, later } from '.';