Skip to content

Commit 0e03d34

Browse files
committed
solution 3
1 parent ce9ba0f commit 0e03d34

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/jest-runtime/src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class Runtime {
432432
'__mocks__',
433433
moduleFileName,
434434
);
435-
if (fs.existsSync(potentialManualMock)) {
435+
if (fs.existsSync(potentialManualMock.split('?')[0])) {
436436
isManualMock = true;
437437
modulePath = potentialManualMock;
438438
}
@@ -472,8 +472,8 @@ class Runtime {
472472
options: InternalModuleOptions | undefined,
473473
moduleRegistry: ModuleRegistry,
474474
) {
475-
if (path.extname(modulePath) === '.json') {
476-
const text = stripBOM(fs.readFileSync(modulePath, 'utf8'));
475+
if (path.extname(modulePath.split('?')[0]) === '.json') {
476+
const text = stripBOM(fs.readFileSync(modulePath.split('?')[0], 'utf8'));
477477

478478
const transformedFile = this._scriptTransformer.transformJson(
479479
modulePath,
@@ -484,8 +484,8 @@ class Runtime {
484484
localModule.exports = this._environment.global.JSON.parse(
485485
transformedFile,
486486
);
487-
} else if (path.extname(modulePath) === '.node') {
488-
localModule.exports = require(modulePath);
487+
} else if (path.extname(modulePath.split('?')[0]) === '.node') {
488+
localModule.exports = require(modulePath.split('?')[0]);
489489
} else {
490490
// Only include the fromPath if a moduleName is given. Else treat as root.
491491
const fromPath = moduleName ? from : null;
@@ -619,7 +619,7 @@ class Runtime {
619619
if (
620620
coveredFiles.has(sourcePath) &&
621621
this._needsCoverageMapped.has(sourcePath) &&
622-
fs.existsSync(this._sourceMapRegistry[sourcePath])
622+
fs.existsSync(this._sourceMapRegistry[sourcePath].split('?')[0])
623623
) {
624624
result[sourcePath] = this._sourceMapRegistry[sourcePath];
625625
}

packages/jest-transform/src/ScriptTransformer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export default class ScriptTransformer {
375375
const isInternalModule = !!(options && options.isInternalModule);
376376
const isCoreModule = !!(options && options.isCoreModule);
377377
const content = stripShebang(
378-
fileSource || fs.readFileSync(filename, 'utf8'),
378+
fileSource || fs.readFileSync(filename.split('?')[0], 'utf8'),
379379
);
380380

381381
let code = content;
@@ -678,7 +678,7 @@ const readCacheFile = (cachePath: Config.Path): string | null => {
678678
};
679679

680680
const getScriptCacheKey = (filename: Config.Path, instrument: boolean) => {
681-
const mtime = fs.statSync(filename).mtime;
681+
const mtime = fs.statSync(filename.split('?')[0]).mtime;
682682
return filename + '_' + mtime.getTime() + (instrument ? '_instrumented' : '');
683683
};
684684

0 commit comments

Comments
 (0)