From 3b718bc9bf5b810a668a45fd6eefe63f88264825 Mon Sep 17 00:00:00 2001 From: Peter Leonov Date: Wed, 29 Jan 2020 21:51:21 +0100 Subject: [PATCH] solution 3 --- packages/jest-runtime/src/index.js | 8 ++++---- packages/jest-transform/src/ScriptTransformer.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index e6f393eef733..c35277a567e3 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -346,9 +346,9 @@ class Runtime { loaded: false, }; moduleRegistry[modulePath] = localModule; - if (path.extname(modulePath) === '.json') { + if (path.extname(modulePath.split('?')[0]) === '.json') { localModule.exports = this._environment.global.JSON.parse( - stripBOM(fs.readFileSync(modulePath, 'utf8')), + stripBOM(fs.readFileSync(modulePath.split('?')[0], 'utf8')), ); } else if (path.extname(modulePath) === '.node') { // $FlowFixMe @@ -422,7 +422,7 @@ class Runtime { '__mocks__', moduleFileName, ); - if (fs.existsSync(potentialManualMock)) { + if (fs.existsSync(potentialManualMock.split('?')[0])) { isManualMock = true; modulePath = potentialManualMock; } @@ -520,7 +520,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.js b/packages/jest-transform/src/ScriptTransformer.js index 44b5959fb39e..a678784ebca0 100644 --- a/packages/jest-transform/src/ScriptTransformer.js +++ b/packages/jest-transform/src/ScriptTransformer.js @@ -299,7 +299,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 wrappedCode: string; @@ -511,7 +511,7 @@ const readCacheFile = (cachePath: Path): ?string => { }; const getScriptCacheKey = (filename, instrument: boolean) => { - const mtime = fs.statSync(filename).mtime; + const mtime = fs.statSync(filename.split('?')[0]).mtime; return filename + '_' + mtime.getTime() + (instrument ? '_instrumented' : ''); };