Skip to content

Commit

Permalink
Removes a code branch, fixes #4985 (#6036)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and cpojer committed Apr 20, 2018
1 parent ef8f9ce commit 0722a1e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 39 deletions.
1 change: 1 addition & 0 deletions integration-tests/custom-resolver/__mocks__/manual-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('bar');
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ test('should use the custom resolver', () => {
test('should have regenerator injected', () => {
expect(global.fakeRegeneratorInjected).toEqual(true);
});

test('should work with automock', () => {
jest.mock('foo');

const foo = require('foo');
foo();

expect(foo).toHaveBeenCalled();
});

test('should allow manual mocks to make require calls through the resolver', () => {
jest.mock('../manual-mock');

expect(require('../manual-mock')).toEqual('bar');
});
2 changes: 1 addition & 1 deletion integration-tests/custom-resolver/bar.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = () => {};
module.exports = 'bar';
1 change: 1 addition & 0 deletions integration-tests/custom-resolver/manual-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('Must be mocked');
22 changes: 0 additions & 22 deletions packages/jest-resolve/src/__tests__/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,6 @@ describe('getMockModule', () => {
path.dirname(src),
);
});

it('is possible to use custom resolver to resolve deps inside mock modules without moduleNameMapper', () => {
userResolver.mockImplementation(() => 'module');

const moduleMap = new ModuleMap({
duplicates: [],
map: [],
mocks: [],
});
const resolver = new Resolver(moduleMap, {
resolver: require.resolve('../__mocks__/userResolver'),
});
const src = require.resolve('../');
resolver.getMockModule(src, 'dependentModule');

expect(userResolver).toHaveBeenCalled();
expect(userResolver.mock.calls[0][0]).toBe('dependentModule');
expect(userResolver.mock.calls[0][1]).toHaveProperty(
'basedir',
path.dirname(src),
);
});
});

describe('nodeModulesPaths', () => {
Expand Down
16 changes: 0 additions & 16 deletions packages/jest-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,6 @@ Please check:
}
}
}
if (resolver) {
// if moduleNameMapper didn't match anything, fallback to just the
// regular resolver
const module =
this.getModule(moduleName) ||
Resolver.findNodeModule(moduleName, {
basedir: dirname,
browser: this._options.browser,
extensions,
moduleDirectory,
paths,
resolver,
rootDir: this._options.rootDir,
});
return module;
}
return null;
}

Expand Down

0 comments on commit 0722a1e

Please sign in to comment.