From 0e03d345e68050223880f3a198907f7cb8d3a54c Mon Sep 17 00:00:00 2001 From: Peter Leonov Date: Wed, 29 Jan 2020 22:05:21 +0100 Subject: [PATCH] solution 3 --- packages/jest-runtime/src/index.ts | 12 ++++++------ packages/jest-transform/src/ScriptTransformer.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 7ff305104da9..cc939a87fda4 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -432,7 +432,7 @@ class Runtime { '__mocks__', moduleFileName, ); - if (fs.existsSync(potentialManualMock)) { + if (fs.existsSync(potentialManualMock.split('?')[0])) { isManualMock = true; modulePath = potentialManualMock; } @@ -472,8 +472,8 @@ class Runtime { options: InternalModuleOptions | undefined, moduleRegistry: ModuleRegistry, ) { - if (path.extname(modulePath) === '.json') { - const text = stripBOM(fs.readFileSync(modulePath, 'utf8')); + if (path.extname(modulePath.split('?')[0]) === '.json') { + const text = stripBOM(fs.readFileSync(modulePath.split('?')[0], 'utf8')); const transformedFile = this._scriptTransformer.transformJson( modulePath, @@ -484,8 +484,8 @@ class Runtime { localModule.exports = this._environment.global.JSON.parse( transformedFile, ); - } else if (path.extname(modulePath) === '.node') { - localModule.exports = require(modulePath); + } else if (path.extname(modulePath.split('?')[0]) === '.node') { + localModule.exports = require(modulePath.split('?')[0]); } else { // Only include the fromPath if a moduleName is given. Else treat as root. const fromPath = moduleName ? from : null; @@ -619,7 +619,7 @@ class Runtime { if ( coveredFiles.has(sourcePath) && this._needsCoverageMapped.has(sourcePath) && - fs.existsSync(this._sourceMapRegistry[sourcePath]) + fs.existsSync(this._sourceMapRegistry[sourcePath].split('?')[0]) ) { result[sourcePath] = this._sourceMapRegistry[sourcePath]; } diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 643e7387ddf2..ad173bc97e4a 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -375,7 +375,7 @@ export default class ScriptTransformer { const isInternalModule = !!(options && options.isInternalModule); const isCoreModule = !!(options && options.isCoreModule); const content = stripShebang( - fileSource || fs.readFileSync(filename, 'utf8'), + fileSource || fs.readFileSync(filename.split('?')[0], 'utf8'), ); let code = content; @@ -678,7 +678,7 @@ const readCacheFile = (cachePath: Config.Path): string | null => { }; const getScriptCacheKey = (filename: Config.Path, instrument: boolean) => { - const mtime = fs.statSync(filename).mtime; + const mtime = fs.statSync(filename.split('?')[0]).mtime; return filename + '_' + mtime.getTime() + (instrument ? '_instrumented' : ''); };