Skip to content

Commit e19adcb

Browse files
authored
chore: remove support for browser field in config (#9943)
1 parent 687089b commit e19adcb

25 files changed

Lines changed: 29 additions & 189 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[jest-config, jest-resolve]` [**BREAKING**] Remove support for `browser` field ([#9943](https://github.com/facebook/jest/pull/9943))
8+
79
### Chore & Maintenance
810

911
- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))

TestUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
6767

6868
const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
6969
automock: false,
70-
browser: false,
7170
cache: false,
7271
cacheDirectory: '/test_cache_dir/',
7372
clearMocks: false,

docs/Configuration.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ Default: `0`
105105

106106
By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after `n` failures. Setting bail to `true` is the same as setting bail to `1`.
107107

108-
### `browser` [boolean]
109-
110-
Default: `false`
111-
112-
Respect Browserify's [`"browser"` field](https://github.com/substack/browserify-handbook#browser-field) in `package.json` when resolving modules. Some modules export different versions based on whether they are operating in Node or a browser.
113-
114108
### `cacheDirectory` [string]
115109

116110
Default: `"/tmp/<path>"`
@@ -689,7 +683,6 @@ This option allows the use of a custom resolver. This resolver must be a node mo
689683
```json
690684
{
691685
"basedir": string,
692-
"browser": bool,
693686
"defaultResolver": "function(request, options)",
694687
"extensions": [string],
695688
"moduleDirectory": [string],
@@ -700,7 +693,18 @@ This option allows the use of a custom resolver. This resolver must be a node mo
700693

701694
The function should either return a path to the module that should be resolved or throw an error if the module can't be found.
702695

703-
Note: the defaultResolver passed as options is the jest default resolver which might be useful when you write your custom one. It takes the same arguments as your custom one, e.g. (request, options).
696+
Note: the defaultResolver passed as options is the Jest default resolver which might be useful when you write your custom one. It takes the same arguments as your custom one, e.g. `(request, options)`.
697+
698+
For example, if you want to respect Browserify's [`"browser"` field](https://github.com/browserify/browserify-handbook/blob/master/readme.markdown#browser-field), you can use the following configuration:
699+
700+
```json
701+
{
702+
...
703+
"jest": {
704+
"resolver": "browser-resolve"
705+
}
706+
}
707+
```
704708

705709
### `restoreMocks` [boolean]
706710

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:545:17)
39+
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542: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:545:17)
68+
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542:17)
6969
at Object.require (index.js:10:1)
7070
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ FAIL __tests__/test.js
3737
| ^
3838
9 |
3939
40-
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:299:11)
40+
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:297:11)
4141
at Object.require (index.js:8:18)
4242
`;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
55
"configs": [
66
{
77
"automock": false,
8-
"browser": false,
98
"cache": false,
109
"cacheDirectory": "/tmp/jest",
1110
"clearMocks": false,

e2e/__tests__/resolveBrowserField.test.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ module.exports = {
5656
// Stop running tests after \`n\` failures
5757
// bail: 0,
5858
59-
// Respect \\"browser\\" field in package.json when resolving modules
60-
// browser: false,
61-
6259
// The directory where Jest should store its cached dependency information
6360
// cacheDirectory: \\"/tmp/jest\\",
6461

packages/jest-config/src/Defaults.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);
1515
const defaultOptions: Config.DefaultOptions = {
1616
automock: false,
1717
bail: 0,
18-
browser: false,
1918
cache: true,
2019
cacheDirectory: getCacheDirectory(),
2120
changedFilesWithAncestor: false,

packages/jest-config/src/Deprecated.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import prettyFormat = require('pretty-format');
1111
const format = (value: unknown) => prettyFormat(value, {min: true});
1212

1313
export default {
14+
browser: () => ` Option ${chalk.bold(
15+
'"browser"',
16+
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as follows:
17+
{
18+
${chalk.bold('"resolve"')}: ${chalk.bold('"browser-resolve"')}
19+
}
20+
`,
21+
1422
mapCoverage: () => ` Option ${chalk.bold(
1523
'"mapCoverage"',
1624
)} has been removed, as it's no longer necessary.

0 commit comments

Comments
 (0)