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 4766302 commit d56a4b0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/jest-resolve/src/__mocks__/userResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2014-present, 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';

module.exports = function userResolver(path, options) {
return 'module';
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

'use strict';

const path = require('path');
const ModuleMap = require('jest-haste-map').ModuleMap;
const Resolver = require('../');

Expand Down Expand Up @@ -37,3 +38,34 @@ describe('isCoreModule', () => {
expect(isCore).toEqual(false);
});
});

describe('findNodeModule', () => {
it('is possible to override the default resolver', () => {
const nodePaths = process.env.NODE_PATH
? process.env.NODE_PATH.split(path.delimiter)
: null;

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

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

expect(newPath).toBe('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']),
});
});
});

0 comments on commit d56a4b0

Please sign in to comment.