Skip to content

Commit

Permalink
Add test for when overriding default resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmr committed Feb 24, 2017
1 parent d90b53e commit f512150
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/jest-resolve/src/__mocks__/userResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function userResolver(path, options) {
return require('./module');
};
48 changes: 48 additions & 0 deletions packages/jest-resolve/src/__tests__/Resolver-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2017, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const path = require('path');

const nodePaths =
(process.env.NODE_PATH ? process.env.NODE_PATH.split(path.delimiter) : null);

describe('Resolve', () => {
describe('findNodeModule', () => {
it('is possible to override the default resolver', () => {

jest.mock('../__mocks__/userResolver');
const userResolver = require('../__mocks__/userResolver');
userResolver.mockImplementation(() => require('./fixtures/module'));

const Resolver = require('jest-resolve');

const newPath = Resolver.findNodeModule('test',
{
basedir: '/',
browser: true,
extensions: ['js'],
moduleDirectory: ['node_modules'],
paths: ['/something'],
resolver: require.resolve('../__mocks__/userResolver'),
}
);

expect(newPath).toBe(require('./fixtures/module'));
expect(userResolver.mock.calls[0][0]).toBe('test');
expect(userResolver.mock.calls[0][1]).toEqual({
basedir: '/',
browser: true,
extensions: ['js'],
moduleDirectory: ['node_modules'],
paths: (nodePaths || []).concat(['/something']),
});
});
});
});
1 change: 1 addition & 0 deletions packages/jest-resolve/src/__tests__/fixtures/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42;

0 comments on commit f512150

Please sign in to comment.