Skip to content

Commit

Permalink
chore: remove support for browser field in config (#9943)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 2, 2020
1 parent 687089b commit e19adcb
Show file tree
Hide file tree
Showing 25 changed files with 29 additions and 189 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-config, jest-resolve]` [**BREAKING**] Remove support for `browser` field ([#9943](https://github.com/facebook/jest/pull/9943))

### Chore & Maintenance

- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
Expand Down
1 change: 0 additions & 1 deletion TestUtils.ts
Expand Up @@ -67,7 +67,6 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {

const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
automock: false,
browser: false,
cache: false,
cacheDirectory: '/test_cache_dir/',
clearMocks: false,
Expand Down
20 changes: 12 additions & 8 deletions docs/Configuration.md
Expand Up @@ -105,12 +105,6 @@ Default: `0`

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`.

### `browser` [boolean]

Default: `false`

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.

### `cacheDirectory` [string]

Default: `"/tmp/<path>"`
Expand Down Expand Up @@ -689,7 +683,6 @@ This option allows the use of a custom resolver. This resolver must be a node mo
```json
{
"basedir": string,
"browser": bool,
"defaultResolver": "function(request, options)",
"extensions": [string],
"moduleDirectory": [string],
Expand All @@ -700,7 +693,18 @@ This option allows the use of a custom resolver. This resolver must be a node mo

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.

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).
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)`.

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:

```json
{
...
"jest": {
"resolver": "browser-resolve"
}
}
```

### `restoreMocks` [boolean]

Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Expand Up @@ -36,7 +36,7 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:545:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542:17)
at Object.require (index.js:10:1)
`;

Expand Down Expand Up @@ -65,6 +65,6 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:545:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542:17)
at Object.require (index.js:10:1)
`;
Expand Up @@ -37,6 +37,6 @@ FAIL __tests__/test.js
| ^
9 |
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:299:11)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:297:11)
at Object.require (index.js:8:18)
`;
1 change: 0 additions & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -5,7 +5,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
"configs": [
{
"automock": false,
"browser": false,
"cache": false,
"cacheDirectory": "/tmp/jest",
"clearMocks": false,
Expand Down
72 changes: 0 additions & 72 deletions e2e/__tests__/resolveBrowserField.test.ts

This file was deleted.

Expand Up @@ -56,9 +56,6 @@ module.exports = {
// Stop running tests after \`n\` failures
// bail: 0,
// Respect \\"browser\\" field in package.json when resolving modules
// browser: false,
// The directory where Jest should store its cached dependency information
// cacheDirectory: \\"/tmp/jest\\",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/Defaults.ts
Expand Up @@ -15,7 +15,6 @@ const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);
const defaultOptions: Config.DefaultOptions = {
automock: false,
bail: 0,
browser: false,
cache: true,
cacheDirectory: getCacheDirectory(),
changedFilesWithAncestor: false,
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-config/src/Deprecated.ts
Expand Up @@ -11,6 +11,14 @@ import prettyFormat = require('pretty-format');
const format = (value: unknown) => prettyFormat(value, {min: true});

export default {
browser: () => ` Option ${chalk.bold(
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as follows:
{
${chalk.bold('"resolve"')}: ${chalk.bold('"browser-resolve"')}
}
`,

mapCoverage: () => ` Option ${chalk.bold(
'"mapCoverage"',
)} has been removed, as it's no longer necessary.
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/Descriptions.ts
Expand Up @@ -10,7 +10,6 @@ import type {Config} from '@jest/types';
const descriptions: {[key in keyof Config.InitialOptions]: string} = {
automock: 'All imported modules in your tests should be mocked automatically',
bail: 'Stop running tests after `n` failures',
browser: 'Respect "browser" field in package.json when resolving modules',
cacheDirectory:
'The directory where Jest should store its cached dependency information',
clearMocks: 'Automatically clear mock calls and instances between every test',
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -15,7 +15,6 @@ const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);
const initialOptions: Config.InitialOptions = {
automock: false,
bail: multipleValidOptions(false, 0),
browser: false,
cache: true,
cacheDirectory: '/tmp/user/jest',
changedFilesWithAncestor: false,
Expand Down
14 changes: 0 additions & 14 deletions packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -154,20 +154,6 @@ describe('automock', () => {
});
});

describe('browser', () => {
it('falsy browser is not overwritten', () => {
const {options} = normalize(
{
browser: true,
rootDir: '/root/path/foo',
},
{},
);

expect(options.browser).toBe(true);
});
});

describe('collectCoverageOnlyFrom', () => {
it('normalizes all paths relative to rootDir', () => {
const {options} = normalize(
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -163,7 +163,6 @@ const groupOptions = (
}),
projectConfig: Object.freeze({
automock: options.automock,
browser: options.browser,
cache: options.cache,
cacheDirectory: options.cacheDirectory,
clearMocks: options.clearMocks,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -869,7 +869,6 @@ export default function normalize(
break;
}
case 'automock':
case 'browser':
case 'cache':
case 'changedSince':
case 'changedFilesWithAncestor':
Expand Down
Expand Up @@ -4,7 +4,6 @@ exports[`prints the config object 1`] = `
{
"configs": {
"automock": false,
"browser": false,
"cache": false,
"cacheDirectory": "/test_cache_dir/",
"clearMocks": false,
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-resolve/package.json
Expand Up @@ -18,7 +18,6 @@
},
"dependencies": {
"@jest/types": "^25.5.0",
"browser-resolve": "^1.11.3",
"chalk": "^3.0.0",
"graceful-fs": "^4.2.4",
"jest-pnp-resolver": "^1.2.1",
Expand All @@ -28,7 +27,6 @@
"slash": "^3.0.0"
},
"devDependencies": {
"@types/browser-resolve": "^1.11.0",
"@types/graceful-fs": "^4.1.3",
"@types/resolve": "^1.14.0",
"jest-haste-map": "^25.5.1"
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-resolve/src/defaultResolver.ts
Expand Up @@ -7,7 +7,6 @@

import * as fs from 'graceful-fs';
import {sync as resolveSync} from 'resolve';
import {sync as browserResolve} from 'browser-resolve';
import {sync as realpath} from 'realpath-native';
import pnpResolver from 'jest-pnp-resolver';
import type {Config} from '@jest/types';
Expand All @@ -31,9 +30,7 @@ export default function defaultResolver(
return pnpResolver(path, options);
}

const resolve = options.browser ? browserResolve : resolveSync;

const result = resolve(path, {
const result = resolveSync(path, {
basedir: options.basedir,
extensions: options.extensions,
isDirectory,
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-resolve/src/index.ts
Expand Up @@ -62,7 +62,6 @@ class Resolver {

constructor(moduleMap: ModuleMap, options: ResolverConfig) {
this._options = {
browser: options.browser,
defaultPlatform: options.defaultPlatform,
extensions: options.extensions,
hasCoreModules:
Expand Down Expand Up @@ -184,7 +183,6 @@ class Resolver {
const resolveNodeModule = (name: Config.Path, throwIfNotFound = false) =>
Resolver.findNodeModule(name, {
basedir: dirname,
browser: this._options.browser,
extensions,
moduleDirectory,
paths,
Expand Down Expand Up @@ -438,7 +436,6 @@ class Resolver {
this.getModule(updatedName) ||
Resolver.findNodeModule(updatedName, {
basedir: dirname,
browser: this._options.browser,
extensions,
moduleDirectory,
paths,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-resolve/src/types.ts
Expand Up @@ -8,7 +8,6 @@
import type {Config} from '@jest/types';

export type ResolverConfig = {
browser?: boolean;
defaultPlatform?: string | null;
extensions: Array<string>;
hasCoreModules: boolean;
Expand Down
43 changes: 0 additions & 43 deletions packages/jest-runtime/src/__tests__/resolve_browser.test.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -302,7 +302,6 @@ class Runtime {
moduleMap: HasteMap.ModuleMap,
): Resolver {
return new Resolver(moduleMap, {
browser: config.browser,
defaultPlatform: config.haste.defaultPlatform,
extensions: config.moduleFileExtensions.map(extension => '.' + extension),
hasCoreModules: true,
Expand Down

0 comments on commit e19adcb

Please sign in to comment.