Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testing): correctly error with jest.mock for invalid filepaths #15445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/jest/plugins/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, extname } from 'path';
import { dirname, extname, join } from 'path';
import { resolve as resolveExports } from 'resolve.exports';
import type defaultResolver from 'jest-resolve/build/defaultResolver';

Expand Down Expand Up @@ -81,7 +81,11 @@ module.exports = function (path: string, options: ResolveOptions) {
ts = ts || require('typescript');
compilerSetup = compilerSetup || getCompilerSetup(options.rootDir);
const { compilerOptions, host } = compilerSetup;
return ts.resolveModuleName(path, options.basedir, compilerOptions, host)
.resolvedModule.resolvedFileName;
return ts.resolveModuleName(
path,
join(options.basedir, 'fake-placeholder.ts'),
compilerOptions,
host
).resolvedModule.resolvedFileName;
}
};
8 changes: 6 additions & 2 deletions scripts/patched-jest-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ module.exports = function (path, options) {
} else if (path === '@nrwl/devkit/testing') {
return join(__dirname, '../', './packages/devkit/testing.js');
}
return ts.resolveModuleName(path, options.basedir, compilerOptions, host)
.resolvedModule.resolvedFileName;
return ts.resolveModuleName(
path,
join(options.basedir, 'fake-placeholder.ts'),
compilerOptions,
host
).resolvedModule.resolvedFileName;
}
};