diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index adaabfaef07c..db203c005be3 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -542,26 +542,35 @@ class ScriptTransformer { let shouldCallTransform = false; - if (transformer && this.shouldTransform(filename)) { - shouldCallTransform = true; - const process = transformer.processAsync ?? transformer.process; - - // This is probably dead code since `_getTransformerAsync` already asserts this - invariant( - typeof process === 'function', - 'A transformer must always export either a `process` or `processAsync`', - ); + // success + // success + if (transformer) { + // if (cacheFilePath) { + // createDirectory(path.dirname(cacheFilePath)); + // } + // failure + if (this.shouldTransform(filename)) { + // failed + shouldCallTransform = true; + const process = transformer.processAsync ?? transformer.process; + + // This is probably dead code since `_getTransformerAsync` already asserts this + invariant( + typeof process === 'function', + 'A transformer must always export either a `process` or `processAsync`', + ); - processed = await process(content, filename, { - ...options, - cacheFS: this._cacheFS, - config: this._config, - configString: this._cache.configString, - transformerConfig, - }); + processed = await process(content, filename, { + ...options, + cacheFS: this._cacheFS, + config: this._config, + configString: this._cache.configString, + transformerConfig, + }); + } } - createDirectory(path.dirname(filename)); + createDirectory(path.dirname(cacheFilePath)); return this._buildTransformResult( filename, cacheFilePath, @@ -811,10 +820,12 @@ class ScriptTransformer { } shouldTransform(filename: string): boolean { + // failed const ignoreRegexp = this._cache.ignorePatternsRegExp; const isIgnored = ignoreRegexp ? ignoreRegexp.test(filename) : false; return this._config.transform.length !== 0 && !isIgnored; + // failed } }