Skip to content

Commit

Permalink
fix(testing): resolve absolute paths for ts path mappings in jest res…
Browse files Browse the repository at this point in the history
…olver (#23346)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #22617
  • Loading branch information
leosvelperez authored May 13, 2024
1 parent 6f197e9 commit 1a981f7
Showing 1 changed file with 7 additions and 3 deletions.
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, join } from 'path';
import { dirname, extname, join, resolve } from 'path';
import { resolve as resolveExports } from 'resolve.exports';
import type defaultResolver from 'jest-resolve/build/defaultResolver';

Expand Down Expand Up @@ -75,11 +75,15 @@ module.exports = function (path: string, options: ResolveOptions) {
ts = ts || require('typescript');
compilerSetup = compilerSetup || getCompilerSetup(options.rootDir);
const { compilerOptions, host } = compilerSetup;
return ts.resolveModuleName(
const resolvedFileName = ts.resolveModuleName(
path,
join(options.basedir, 'fake-placeholder.ts'),
compilerOptions,
host
).resolvedModule.resolvedFileName;
).resolvedModule?.resolvedFileName;
if (!resolvedFileName) {
throw new Error(`Could not resolve ${path}`);
}
return resolve(options.rootDir, resolvedFileName);
}
};

0 comments on commit 1a981f7

Please sign in to comment.