-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for when overriding default resolver
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function userResolver(path, options) { | ||
return require('./module'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']), | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 42; |