Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

feat: Support @vue/vue2-jest #106

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Changes from all commits
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
15 changes: 14 additions & 1 deletion jest.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { transform } = require('./dist/index')

function requireVueJest() {
const names = ['@vue/vue2-jest', 'vue-jest']
for (const name of names) {
try {
return require(name)
}
catch (e) {
// Try next module
}
}
throw new Error(`Cannot find a Jest transformer for Vue SFC, you should install one of these packages: ${names.join(', ')}`)
}

module.exports = {
process(source, filename, ...args) {
const transformed = transform(source, filename)
const code = transformed ? transformed.code : source
return require('vue-jest').process.call(this, code, filename, ...args)
return requireVueJest().process.call(this, code, filename, ...args)
},
}