8000 fix: fixed `lang='tsx'` files not working for vue2-jest by Yama-Tomo · Pull Request #395 · vuejs/vue-jest · GitHub
[go: up one dir, main page]

Skip to content

fix: fixed lang='tsx' files not working for vue2-jest #395

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 4 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
fix: transpile as tsx when lang='tsx'
  • Loading branch information
Yama-Tomo committed Oct 1, 2021
commit 10f2ee0d884c524ad53857dfa24114d7abf4e0f8
2 changes: 1 addition & 1 deletion packages/vue2-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const generateCode = require('./generate-code')
function resolveTransformer(lang = 'js', vueJestConfig) {
const transformer = getCustomTransformer(vueJestConfig['transform'], lang)
if (/^typescript$|tsx?$/.test(lang)) {
return transformer || require('./transformers/typescript')
return transformer || require('./transformers/typescript')(lang)
} else if (/^coffee$|coffeescript$/.test(lang)) {
return transformer || coffeescriptTransformer
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/vue2-jest/lib/transformers/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
getVueJestConfig
} = require('../utils')

module.exports = {
module.exports = scriptLang => ({
process(scriptContent, filePath, config) {
ensureRequire('typescript', ['typescript'])
const typescript = require('typescript')
Expand All @@ -16,7 +16,7 @@ module.exports = {

const res = typescript.transpileModule(scriptContent, {
...tsconfig,
fileName: filePath
fileName: filePath + (scriptLang === 'tsx' ? '.tsx' : '')
})

res.outputText = stripInlineSourceMap(res.outputText)
Expand All @@ -32,4 +32,4 @@ module.exports = {

return transformer.process(res.outputText, filePath, config)
}
}
})
0