mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 08:37:23 +00:00
test: using esbuild instead of babel-jest (#10154)
* test: using esbuild instead of babel-jest * chore: update lock
This commit is contained in:
@@ -17,7 +17,7 @@ const DEFAULT_CONFIG = {
|
||||
moduleFileExtensions: ['js', 'jsx', 'vue', 'ts', 'tsx'],
|
||||
transform: {
|
||||
'\\.(vue)$': 'vue3-jest',
|
||||
'\\.(js|jsx|ts|tsx)$': 'babel-jest',
|
||||
'\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/@vant/cli/cjs/jest.transformer.cjs',
|
||||
},
|
||||
transformIgnorePatterns: ['/node_modules/(?!(@vant/cli))/'],
|
||||
snapshotSerializers: ['jest-serializer-html'],
|
||||
|
||||
32
packages/vant-cli/cjs/jest.transformer.cjs
Normal file
32
packages/vant-cli/cjs/jest.transformer.cjs
Normal file
@@ -0,0 +1,32 @@
|
||||
const { transform: babelTransform } = require('@babel/core');
|
||||
const { transformSync: esbuildTransformSync } = require('esbuild');
|
||||
|
||||
const isJsxFile = (path) => /\.(j|t)sx$/.test(path);
|
||||
const isTsxFile = (path) => /\.tsx$/.test(path);
|
||||
|
||||
const transformJsx = (code, path) => {
|
||||
const babelResult = babelTransform(code, {
|
||||
filename: path,
|
||||
babelrc: false,
|
||||
presets: isTsxFile(path) ? ['@babel/preset-typescript'] : [],
|
||||
plugins: [['@vue/babel-plugin-jsx']],
|
||||
});
|
||||
return babelResult?.code || '';
|
||||
};
|
||||
|
||||
const transformScript = (code) =>
|
||||
esbuildTransformSync(code, {
|
||||
target: 'es2016',
|
||||
format: 'cjs',
|
||||
loader: 'ts',
|
||||
}).code;
|
||||
|
||||
module.exports = {
|
||||
canInstrument: true,
|
||||
process(code, path) {
|
||||
if (isJsxFile(path)) {
|
||||
code = transformJsx(code, path);
|
||||
}
|
||||
return transformScript(code);
|
||||
},
|
||||
};
|
||||
@@ -48,12 +48,12 @@
|
||||
"vue": "^3.2.20"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@babel/core": "^7.16.0",
|
||||
"@babel/preset-env": "^7.16.0",
|
||||
"@babel/preset-typescript": "^7.16.0",
|
||||
"@docsearch/css": "3.0.0-alpha.41",
|
||||
"@docsearch/js": "3.0.0-alpha.41",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@vant/eslint-config": "^3.3.2",
|
||||
"@vant/markdown-vetur": "^2.2.0",
|
||||
"@vant/stylelint-config": "^1.4.2",
|
||||
@@ -62,12 +62,12 @@
|
||||
"@vitejs/plugin-vue-jsx": "^1.2.0",
|
||||
"@vue/babel-plugin-jsx": "^1.1.1",
|
||||
"autoprefixer": "^10.4.0",
|
||||
"babel-jest": "^27.3.1",
|
||||
"chalk": "^4.1.2",
|
||||
"clean-css": "^5.2.2",
|
||||
"commander": "^8.3.0",
|
||||
"consola": "^2.15.3",
|
||||
"conventional-changelog": "^3.1.24",
|
||||
"esbuild": "^0.14.2",
|
||||
"eslint": "^8.1.0",
|
||||
"execa": "^5.1.1",
|
||||
"fast-glob": "^3.2.7",
|
||||
|
||||
Reference in New Issue
Block a user