Skip to content

Commit

Permalink
fix(testing): correctly error with jest.mock for invalid filepaths (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Apr 6, 2023
1 parent 454344b commit 083f4f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 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 } 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;
}
};

1 comment on commit 083f4f1

@vercel
Copy link

@vercel vercel bot commented on 083f4f1 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.