Skip to content

Commit cd98198

Browse files
author
Marco Scabbiolo
authored
feat: add require stack & surface Yarn PnP (#9681)
1 parent 553b788 commit cd98198

17 files changed

Lines changed: 223 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- `[jest-runtime]` Require stack when a module cannot be resolved ([#9681](https://github.com/facebook/jest/pull/9681))
56
- `[jest-config]` Support ESM config files with `.js` extension ([#9573](https://github.com/facebook/jest/pull/9573)).
67
- `[jest-runtime]` Override `module.createRequire` to return a Jest-compatible `require` function ([#9469](https://github.com/facebook/jest/pull/9469))
78
- `[jest-haste-map]` [**BREAKING**] Remove `mapper` option ([#9581](https://github.com/facebook/jest/pull/9581))
@@ -11,6 +12,7 @@
1112

1213
### Fixes
1314

15+
- `[jest-runtime]` Yarn PnP errors displayed to the user ([#9681](https://github.com/facebook/jest/pull/9681))
1416
- `[expect]` Handle readonly properties correctly ([#9575](https://github.com/facebook/jest/pull/9575))
1517
- `[jest-cli]` Set `coverageProvider` correctly when provided in config ([#9562](https://github.com/facebook/jest/pull/9562))
1618
- `[jest-cli]` Allow specifying `.cjs` and `.mjs` config files by `--config` CLI option ([#9578](https://github.com/facebook/jest/pull/9578))

e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ FAIL __tests__/index.js
3636
12 | module.exports = () => 'test';
3737
13 |
3838
39-
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:519:17)
39+
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:540:17)
4040
at Object.require (index.js:10:1)
4141
`;
4242

@@ -65,6 +65,6 @@ FAIL __tests__/index.js
6565
12 | module.exports = () => 'test';
6666
13 |
6767
68-
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:519:17)
68+
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:540:17)
6969
at Object.require (index.js:10:1)
7070
`;

e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ FAIL __tests__/test.js
1919
2020
Cannot find module './some-json-file' from 'index.js'
2121
22+
Require stack:
23+
index.js
24+
__tests__/test.js
25+
26+
2227
However, Jest was able to find:
2328
'./some-json-file.json'
2429
@@ -32,6 +37,6 @@ FAIL __tests__/test.js
3237
| ^
3338
9 |
3439
35-
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:276:11)
40+
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:296:11)
3641
at Object.require (index.js:8:18)
3742
`;

e2e/__tests__/pnp.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ it('sucessfully runs the tests inside `pnp/`', () => {
2424
nodeOptions: `--require ${DIR}/.pnp.js`,
2525
});
2626
expect(json.success).toBe(true);
27-
expect(json.numTotalTestSuites).toBe(1);
27+
expect(json.numTotalTestSuites).toBe(2);
2828
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. 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+
it('should surface pnp errors', () => {
10+
expect(() => {
11+
require('undeclared');
12+
}).toThrow(expect.objectContaining({code: 'UNDECLARED_DEPENDENCY'}));
13+
});

e2e/pnp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"dependencies": {
3-
"foo": "link:./lib"
3+
"foo": "link:./lib",
4+
"undeclared": "link:./undeclared-dependency"
45
},
56
"installConfig": {
67
"pnp": true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. 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+
const nope = require('unesitent_module__');
10+
11+
module.exports = () => nope;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "0.0.0"
3+
}

e2e/pnp/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
"foo@link:./lib":
66
version "0.0.0"
77
uid ""
8+
9+
"undeclared@link:./undeclared-dependency":
10+
version "0.0.0"
11+
uid ""

e2e/resolve/Test7.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. 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+
require('./test1');
10+
const requiresUnexistingModule = require('./requiresUnexistingModule');
11+
12+
module.exports = {module: requiresUnexistingModule};

0 commit comments

Comments
 (0)