From 4040368f065246c4d0b7ced8faeb5b0437613f31 Mon Sep 17 00:00:00 2001 From: Peter Leonov Date: Sat, 19 Jan 2019 20:30:26 +0100 Subject: [PATCH] solution 3 --- packages/jest-runtime/src/ScriptTransformer.js | 4 ++-- packages/jest-runtime/src/index.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/jest-runtime/src/ScriptTransformer.js b/packages/jest-runtime/src/ScriptTransformer.js index aef3d85022b9..7e1124bbdcf7 100644 --- a/packages/jest-runtime/src/ScriptTransformer.js +++ b/packages/jest-runtime/src/ScriptTransformer.js @@ -301,7 +301,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; @@ -513,7 +513,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' : ''); }; diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 05dc03a7a35b..030c7a879b37 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -343,9 +343,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 @@ -413,7 +413,7 @@ class Runtime { '__mocks__', moduleFileName, ); - if (fs.existsSync(potentialManualMock)) { + if (fs.existsSync(potentialManualMock.split('?')[0])) { manualMock = true; modulePath = potentialManualMock; } @@ -511,7 +511,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]; }