Skip to content

Commit

Permalink
refactor(resolver): use ts types from jest-resolve (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl authored Apr 30, 2022
1 parent 04195d5 commit 84fa5b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
},
testEnvironment: 'jsdom',
modulePathIgnorePatterns: ['examples/.*', 'website/.*'],
resolver: '<rootDir>/build/resolvers/ng-jest-resolver',
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
testPathIgnorePatterns: ['/node_modules/', '/examples/', '/e2e/.*/__tests__', '\\.snap$'],
transform: {
Expand Down
4 changes: 3 additions & 1 deletion src/resolvers/ng-jest-resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ResolverOptions } from 'jest-resolve';

import ngJestResolver from './ng-jest-resolver';

test.each([
Expand All @@ -9,7 +11,7 @@ test.each([

ngJestResolver('foo', {
defaultResolver: mockedDefaultResolver,
});
} as unknown as ResolverOptions);

expect(mockedDefaultResolver).toHaveBeenCalled();
expect(mockedDefaultResolver.mock.calls[0][0]).toEqual('foo');
Expand Down
21 changes: 11 additions & 10 deletions src/resolvers/ng-jest-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const ngJestResolver = (
path: string,
// `jest-resolve` didn't expose `ResolverOptions` type
options: { defaultResolver: (path: string, options: Record<string, unknown>) => string },
): string =>
options.defaultResolver(path, {
import type { SyncResolver } from 'jest-resolve';

const ngJestResolver: SyncResolver = (path, options) => {
return options.defaultResolver(path, {
...options,
packageFilter: (pkg: Record<string, unknown>) => ({
...pkg,
main: pkg.main || pkg.es2015 || pkg.module,
}),
packageFilter(pkg) {
return {
...pkg,
main: pkg.main || pkg.es2015 || pkg.module,
};
},
});
};

export = ngJestResolver;

0 comments on commit 84fa5b4

Please sign in to comment.