Skip to content

Commit

Permalink
stub further changes with .path
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-leonov committed Mar 29, 2020
1 parent 36754bb commit c6f2e74
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ const setupPreset = (
// Force re-evaluation to support multiple projects
try {
if (presetModule) {
delete require.cache[require.resolve(presetModule)];
delete require.cache[require.resolve(presetModule.path)];
}
} catch (e) {}

// @ts-ignore: `presetModule` can be null?
preset = require(presetModule);
preset = require(presetModule.path);
} catch (error) {
if (error instanceof SyntaxError || error instanceof TypeError) {
throw createConfigError(
Expand Down Expand Up @@ -435,7 +435,7 @@ const normalizeReporters = (options: Config.InitialOptionsWithRootDir) => {
` Module name: ${reporterPath}`,
);
}
normalizedReporterConfig[0] = reporter;
normalizedReporterConfig[0] = reporter.path;
}
return normalizedReporterConfig;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const resolve = (
);
}
/// can cast as string since nulls will be thrown
return module as string;
return module?.path as string;
};

export const escapeGlobCharacters = (path: Config.Path): Config.Glob =>
Expand Down Expand Up @@ -139,7 +139,7 @@ export const resolveWithPrefix = (
resolver: resolver || undefined,
});
if (module) {
return module;
return module.path;
}

try {
Expand All @@ -151,7 +151,7 @@ export const resolveWithPrefix = (
resolver: resolver || undefined,
});
if (module) {
return module;
return module.path;
}

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DependencyResolver {
file,
dependency,
options,
);
).path;
} catch {
try {
resolvedDependency = this._resolver.getMockModule(file, dependency);
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ class Runtime {
this._moduleMocker.clearAllMocks();
}

private _resolveModule(from: Config.Path, to?: string) {
return to ? this._resolver.resolveModule(from, to) : from;
private _resolveModule(from: Config.Path, to?: string): string {
return to ? this._resolver.resolveModule(from, to).path : from;
}

private _requireResolve(
Expand All @@ -702,7 +702,7 @@ class Runtime {
{paths: [absolutePath]},
);
if (module) {
return module;
return module.path;
}
}

Expand Down Expand Up @@ -939,6 +939,7 @@ class Runtime {
filename,
id: filename,
loaded: false,
rpth: {id: 'InitialModule', path: filename}
});
};

Expand Down Expand Up @@ -978,7 +979,7 @@ class Runtime {

private _generateMock(from: Config.Path, moduleName: string) {
const modulePath =
this._resolver.resolveStubModuleName(from, moduleName) ||
this._resolver.resolveStubModuleName(from, moduleName)?.path ||
this._resolveModule(from, moduleName);
if (!(modulePath in this._mockMetaDataCache)) {
// This allows us to handle circular dependencies while generating an
Expand Down

0 comments on commit c6f2e74

Please sign in to comment.