Skip to content

fix(vue3-jest): reduce getTypeScriptConfig calls #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(vue3-jest): reduce getTypeScriptConfig calls
  • Loading branch information
nogic1008 committed Aug 21, 2022
commit 2f8084d4434a68f587dd236e07bd1b3d036abfce
37 changes: 21 additions & 16 deletions packages/vue3-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ function processScriptSetup(descriptor, filePath, config) {
return result
}

/**
* Process SFC <template> section.
* @param {import('@vue/compiler-sfc').SFCDescriptor} descriptor
* @param {string} filename
* @param {import('@jest/transform').TransformOptions} config
*/
function processTemplate(descriptor, filename, config) {
const { template, scriptSetup } = descriptor

Expand Down Expand Up @@ -118,24 +124,23 @@ function processTemplate(descriptor, filename, config) {

logResultErrors(result)

const tsconfig = getTypeScriptConfig(vueJestConfig.tsConfig)

if (tsconfig) {
// they are using TypeScript.
const { transpileModule } = require('typescript')
const { outputText } = transpileModule(result.code, { tsconfig })
return { code: outputText }
} else {
// babel
const babelify = transform(result.code, {
filename: 'file.js',
presets: ['@babel/preset-env']
})

return {
code: babelify.code
// TypeScript
if (isTS) {
const tsconfig = getTypeScriptConfig(vueJestConfig.tsConfig)
if (tsconfig) {
const { transpileModule } = require('typescript')
const { outputText } = transpileModule(result.code, { tsconfig })
return { code: outputText }
}
}

// babel
const babelify = transform(result.code, {
filename: 'file.js',
presets: ['@babel/preset-env']
})

return { code: babelify.code }
}

function processStyle(styles, filename, config) {
Expand Down