Skip to content

Commit

Permalink
chore: remove support for browser field in config
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 1, 2020
1 parent 80b6905 commit 3775116
Show file tree
Hide file tree
Showing 20 changed files with 16 additions and 178 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

### Performance
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
7 changes: 0 additions & 7 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 Down
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.

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
12 changes: 12 additions & 0 deletions packages/jest-config/src/Deprecated.ts
Expand Up @@ -11,6 +11,18 @@ 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.
Jest now treats your current configuration as:
{
${chalk.bold('"resolve"')}: ${chalk.bold('"browser-resolve"')}
}
Please update your configuration.
`,

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
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 @@ -303,7 +303,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
4 changes: 0 additions & 4 deletions packages/jest-types/src/Config.ts
Expand Up @@ -34,7 +34,6 @@ export interface ConfigGlobals {
export type DefaultOptions = {
automock: boolean;
bail: number;
browser: boolean;
cache: boolean;
cacheDirectory: Path;
changedFilesWithAncestor: boolean;
Expand Down Expand Up @@ -99,7 +98,6 @@ export type InitialOptionsWithRootDir = InitialOptions &
export type InitialOptions = Partial<{
automock: boolean;
bail: boolean | number;
browser: boolean;
cache: boolean;
cacheDirectory: Path;
clearMocks: boolean;
Expand Down Expand Up @@ -301,7 +299,6 @@ export type GlobalConfig = {

export type ProjectConfig = {
automock: boolean;
browser: boolean;
cache: boolean;
cacheDirectory: Path;
clearMocks: boolean;
Expand Down Expand Up @@ -360,7 +357,6 @@ export type Argv = Arguments<
all: boolean;
automock: boolean;
bail: boolean | number;
browser: boolean;
cache: boolean;
cacheDirectory: string;
changedFilesWithAncestor: boolean;
Expand Down
21 changes: 1 addition & 20 deletions yarn.lock
Expand Up @@ -2217,13 +2217,6 @@
resolved "https://registry.yarnpkg.com/@types/braces/-/braces-3.0.0.tgz#7da1c0d44ff1c7eb660a36ec078ea61ba7eb42cb"
integrity sha512-TbH79tcyi9FHwbyboOKeRachRq63mSuWYXOflsNO9ZyE5ClQ/JaozNKl+aWUq87qPNsXasXxi2AbgfwIJ+8GQw==

"@types/browser-resolve@^1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@types/browser-resolve/-/browser-resolve-1.11.0.tgz#28c427182a6e340b3d7082b62da8128c562f04d6"
integrity sha512-fI2q5j/5w2TuO+lIGj7bMcvOQQCo5Eq71OLiWttohpp4xW6xhA9ltN2ielMSvl5ochAIY0Z3E8LtVRMIGLYy2w==
dependencies:
"@types/resolve" "*"

"@types/cheerio@^0.22.8":
version "0.22.17"
resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.17.tgz#e54f71c3135f71ebc16c8dc62edad533872c9e72"
Expand Down Expand Up @@ -2514,7 +2507,7 @@
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/resolve@*", "@types/resolve@^1.14.0":
"@types/resolve@^1.14.0":
version "1.14.0"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.14.0.tgz#c95d696264f8e53e764a7c0b83e9317b458b76c3"
integrity sha512-bmjNBW6tok+67iOsASeYSJxSgY++BIR35nGyGLORTDirhra9reJ0shgGL3U7KPDUbOBCx8JrlCjd4d/y5uiMRQ==
Expand Down Expand Up @@ -3818,13 +3811,6 @@ browser-process-hrtime@^1.0.0:
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"
integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==

browser-resolve@^1.11.3:
version "1.11.3"
resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.3.tgz#9b7cbb3d0f510e4cb86bdbd796124d28b5890af6"
integrity sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ==
dependencies:
resolve "1.1.7"

browser-stdout@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"
Expand Down Expand Up @@ -12731,11 +12717,6 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=

resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.0, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.8.1:
version "1.17.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
Expand Down

0 comments on commit 3775116

Please sign in to comment.