Skip to content

Commit

Permalink
solution 3
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-leonov committed Jan 29, 2020
1 parent ce9ba0f commit 0e03d34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class Runtime {
'__mocks__',
moduleFileName,
);
if (fs.existsSync(potentialManualMock)) {
if (fs.existsSync(potentialManualMock.split('?')[0])) {
isManualMock = true;
modulePath = potentialManualMock;
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' : '');
};

Expand Down

0 comments on commit 0e03d34

Please sign in to comment.