diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 63e3ca1e2d7a..455b3f851611 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -220,7 +220,9 @@ class ScriptTransformer { const cacheFilenamePrefix = path .basename(filename, path.extname(filename)) .replace(/\W/g, ''); - return slash(path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`)); + return slash( + path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`), + ); } private _getFileCachePath( @@ -240,7 +242,9 @@ class ScriptTransformer { ): Promise { const cacheKey = await this._getCacheKeyAsync(content, filename, options); - return this._createCachedFilename(filename, cacheKey); + const tmp = this._createCachedFilename(filename, cacheKey); + // createDirectory(path.dirname(tmp)); + return tmp; } private _getTransformPath(filename: string) { @@ -462,6 +466,7 @@ class ScriptTransformer { const {transformer, transformerConfig = {}} = this._getTransformer(filename) ?? {}; const cacheFilePath = this._getFileCachePath(filename, content, options); + createDirectory(path.dirname(cacheFilePath)); const sourceMapPath = `${cacheFilePath}.map`; // Ignore cache if `config.cache` is set (--no-cache) const code = this._config.cache ? readCodeCacheFile(cacheFilePath) : null; @@ -522,6 +527,7 @@ class ScriptTransformer { content, options, ); + createDirectory(path.dirname(cacheFilePath)); const sourceMapPath = `${cacheFilePath}.map`; // Ignore cache if `config.cache` is set (--no-cache) const code = this._config.cache ? readCodeCacheFile(cacheFilePath) : null;