Skip to content

Commit

Permalink
[heft-jest] Fix node-modules-symlink-resolver (#5013)
Browse files Browse the repository at this point in the history
Co-authored-by: David Michon <[email protected]>
  • Loading branch information
dmichon-msft and dmichon-msft authored Nov 23, 2024
1 parent 8540003 commit 871fdf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-jest-plugin",
"comment": "Fix a bug in `jest-node-modules-symlink-resolver` with respect to evaluating paths that don't exist. Expected behavior in that situation is to return the input path.",
"type": "patch"
}
],
"packageName": "@rushstack/heft-jest-plugin"
}
7 changes: 1 addition & 6 deletions heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as path from 'node:path';
import { RealNodeModulePathResolver } from '@rushstack/node-core-library/lib/RealNodeModulePath';

const jestResolvePackageFolder: string = path.dirname(require.resolve('jest-resolve/package.json'));
const jestResolveFileWalkersPath: string = path.resolve(jestResolvePackageFolder, './build/fileWalkers.js');

const jestUtilPackageFolder: string = path.dirname(
require.resolve('jest-util/package.json', { paths: [jestResolvePackageFolder] })
Expand All @@ -14,11 +13,6 @@ const jestUtilTryRealpathPath: string = path.resolve(jestUtilPackageFolder, './b

const { realNodeModulePath }: RealNodeModulePathResolver = new RealNodeModulePathResolver();

const fileWalkersModule: {
realpathSync: (filePath: string) => string;
} = require(jestResolveFileWalkersPath);
fileWalkersModule.realpathSync = realNodeModulePath;

const tryRealpathModule: {
default: (filePath: string) => string;
} = require(jestUtilTryRealpathPath);
Expand All @@ -28,6 +22,7 @@ tryRealpathModule.default = (input: string): string => {
} catch (error) {
// Not using the helper from FileSystem here because this code loads in every Jest worker process
// and FileSystem has a lot of extra dependencies
// These error codes cloned from the logic in jest-util's tryRealpath.js
if (error.code !== 'ENOENT' && error.code !== 'EISDIR') {
throw error;
}
Expand Down

0 comments on commit 871fdf2

Please sign in to comment.