Skip to content

Commit c9481ac

Browse files
committed
craft a test
1 parent 6771bd4 commit c9481ac

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function userResolver(path, options) {
12+
const defaultResolver = require('../__tests__/defaultResolver.js');
13+
const [clearPath, query] = path.split('?');
14+
return defaultResolver(clearPath, options) + (query ? '?' + query : '');
15+
};

packages/jest-runtime/src/__tests__/runtime_require_module.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,47 @@ describe('Runtime requireModule', () => {
248248
expect(hastePackage.isHastePackage).toBe(true);
249249
}));
250250

251+
it('supports resolving the same path to multiple modules', () =>
252+
createRuntime(__filename, {
253+
// using the default resolver as a custom resolver
254+
resolver: require.resolve('../__mocks__/resourceQueryResolver.js'),
255+
}).then(runtime => {
256+
const moduleNoQuery1 = runtime.requireModule(
257+
runtime.__mockRootPath,
258+
'./moduleWithResourceQuery.js',
259+
);
260+
const moduleNoQuery2 = runtime.requireModule(
261+
runtime.__mockRootPath,
262+
'./moduleWithResourceQuery.js',
263+
);
264+
expect(moduleNoQuery1.name).toBe('moduleWithoutResourceQuery');
265+
expect(moduleNoQuery1).toBe(moduleNoQuery2);
266+
267+
const moduleWithQueryA = runtime.requireModule(
268+
runtime.__mockRootPath,
269+
'./moduleWithResourceQuery.js?a',
270+
);
271+
const moduleWithQueryB = runtime.requireModule(
272+
runtime.__mockRootPath,
273+
'./moduleWithResourceQuery.js?b',
274+
);
275+
expect(moduleWithQueryA.name).toBe('moduleWithoutResourceQuery');
276+
expect(moduleWithQueryB.name).toBe('moduleWithoutResourceQuery');
277+
expect(moduleWithQueryA).not.toBe(moduleWithQueryB);
278+
279+
const moduleWithSameQuery1 = runtime.requireModule(
280+
runtime.__mockRootPath,
281+
'./moduleWithResourceQuery.js?sameQuery',
282+
);
283+
const moduleWithSameQuery2 = runtime.requireModule(
284+
runtime.__mockRootPath,
285+
'./moduleWithResourceQuery.js?sameQuery',
286+
);
287+
expect(moduleWithSameQuery1.name).toBe('moduleWithoutResourceQuery');
288+
expect(moduleWithSameQuery2.name).toBe('moduleWithoutResourceQuery');
289+
expect(moduleWithSameQuery1).toBe(moduleWithSameQuery2);
290+
}));
291+
251292
it('resolves node modules properly when crawling node_modules', () =>
252293
// While we are crawling a node module, we shouldn't put package.json
253294
// files of node modules to resolve to `package.json` but rather resolve
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
// this object reference should be uniq per each module compilation
10+
const newObject = {name: 'moduleWithoutResourceQuery'};
11+
12+
module.exports = newObject;

0 commit comments

Comments
 (0)