Skip to content

Commit 83fbdc1

Browse files
committed
feat: support createTransformer() on customTransformer
1 parent ac0884f commit 83fbdc1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/vue2-jest/lib/utils.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) {
8989

9090
function isValidTransformer(transformer) {
9191
return (
92+
isFunction(transformer.createTransformer) ||
9293
isFunction(transformer.process) ||
9394
isFunction(transformer.postprocess) ||
9495
isFunction(transformer.preprocess)
@@ -121,12 +122,13 @@ const getCustomTransformer = function getCustomTransformer(
121122

122123
if (!isValidTransformer(transformer)) {
123124
throwError(
124-
`transformer must contain at least one process, preprocess, or ` +
125-
`postprocess method`
125+
`transformer must contain at least one createTransformer(), process(), preprocess(), or postprocess() method`
126126
)
127127
}
128128

129-
return transformer
129+
return isFunction(transformer.createTransformer)
130+
? transformer.createTransformer()
131+
: transformer
130132
}
131133

132134
const throwError = function error(msg) {

packages/vue3-jest/lib/utils.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) {
9090

9191
function isValidTransformer(transformer) {
9292
return (
93+
isFunction(transformer.createTransformer) ||
9394
isFunction(transformer.process) ||
9495
isFunction(transformer.postprocess) ||
9596
isFunction(transformer.preprocess)
@@ -123,12 +124,13 @@ const getCustomTransformer = function getCustomTransformer(
123124

124125
if (!isValidTransformer(transformer)) {
125126
throwError(
126-
`transformer must contain at least one process, preprocess, or ` +
127-
`postprocess method`
127+
`transformer must contain at least one createTransformer(), process(), preprocess(), or postprocess() method`
128128
)
129129
}
130130

131-
return transformer
131+
return isFunction(transformer.createTransformer)
132+
? transformer.createTransformer()
133+
: transformer
132134
}
133135

134136
const throwError = function error(msg) {

0 commit comments

Comments
 (0)