mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): add jest init file
This commit is contained in:
parent
24202028e5
commit
9155a7a491
@ -8,7 +8,7 @@ Vue.mixin({
|
|||||||
computed: {
|
computed: {
|
||||||
$t() {
|
$t() {
|
||||||
const { name } = this.$options;
|
const { name } = this.$options;
|
||||||
const { lang } = this.$route.meta || {};
|
const { lang = 'zh-CN' } = (this.$route && this.$route.meta) || {};
|
||||||
const prefix = name ? camelize(name) + '.' : '';
|
const prefix = name ? camelize(name) + '.' : '';
|
||||||
const messages = this.$vantMessages[lang];
|
const messages = this.$vantMessages[lang];
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ Vue.mixin({
|
|||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
const { i18n, name } = this.$options;
|
const { i18n, name } = this.$options;
|
||||||
|
|
||||||
if (i18n) {
|
if (i18n && name) {
|
||||||
const locales = {};
|
const locales = {};
|
||||||
const camelizedName = camelize(name);
|
const camelizedName = camelize(name);
|
||||||
|
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
import { runCLI } from 'jest';
|
import { runCLI } from 'jest';
|
||||||
import { setNodeEnv } from '../common';
|
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) {
|
export function test(command: any) {
|
||||||
setNodeEnv('test');
|
setNodeEnv('test');
|
||||||
|
|
||||||
|
genPackageEntry({
|
||||||
|
outputPath: PACKAGE_ENTRY_FILE
|
||||||
|
});
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
rootDir: CWD,
|
rootDir: CWD,
|
||||||
watch: command.watch,
|
watch: command.watch,
|
||||||
|
@ -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 JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||||
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.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 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_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js');
|
||||||
export const JEST_FILE_MOCK_FILE = join(CONFIG_DIR, 'jest.file-mock.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');
|
export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js');
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
JEST_INIT_FILE,
|
||||||
JEST_FILE_MOCK_FILE,
|
JEST_FILE_MOCK_FILE,
|
||||||
JEST_STYLE_MOCK_FILE
|
JEST_STYLE_MOCK_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
@ -8,6 +9,7 @@ module.exports = {
|
|||||||
'\\.(css|less|scss)$': JEST_STYLE_MOCK_FILE,
|
'\\.(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
|
'\\.(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'],
|
moduleFileExtensions: ['js', 'jsx', 'vue', 'ts', 'tsx'],
|
||||||
transform: {
|
transform: {
|
||||||
'\\.(vue)$': 'vue-jest',
|
'\\.(vue)$': 'vue-jest',
|
||||||
@ -18,9 +20,7 @@ module.exports = {
|
|||||||
collectCoverageFrom: [
|
collectCoverageFrom: [
|
||||||
'src/**/*.{js,jsx,ts,tsx,vue}',
|
'src/**/*.{js,jsx,ts,tsx,vue}',
|
||||||
'!**/style/**',
|
'!**/style/**',
|
||||||
'!**/demo/**',
|
'!**/demo/**'
|
||||||
'!**/locale/lang/**',
|
|
||||||
'!**/sku/**'
|
|
||||||
],
|
],
|
||||||
collectCoverage: true,
|
collectCoverage: true,
|
||||||
coverageReporters: ['html', 'lcov', 'text-summary'],
|
coverageReporters: ['html', 'lcov', 'text-summary'],
|
||||||
|
5
packages/vant-cli/src/config/jest.init.ts
Normal file
5
packages/vant-cli/src/config/jest.init.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
// @ts-ignore
|
||||||
|
import Package from '../../dist/package-entry';
|
||||||
|
|
||||||
|
Vue.use(Package);
|
@ -1,5 +1,5 @@
|
|||||||
import Vue, { CreateElement } from 'vue';
|
import Vue, { CreateElement } from 'vue';
|
||||||
import '../docs/site/mobile/demo-common';
|
import '../docs/site/mobile';
|
||||||
import Locale from '../src/locale';
|
import Locale from '../src/locale';
|
||||||
import { mount, later } from '.';
|
import { mount, later } from '.';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user