This repository was archived by the owner on Dec 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} |