Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add integration test using browser-resolve #11140

Merged
merged 4 commits into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -65,6 +65,7 @@
- `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921))
- `[*]` Make it easier for Jest's packages to use the VM escape hatch ([#10824](https://github.com/facebook/jest/pull/10824))
- `[*]` [**BREAKING**] Remove deprecated `mapCoverage` ([#9968](https://github.com/facebook/jest/pull/9968))
- `[docs]` Correct example using `browser-resolve` ([#11140](https://github.com/facebook/jest/pull/11140))
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126))
- `[jest-console]` Export LogEntry ([#11017](https://github.com/facebook/jest/pull/11017))
Expand Down
9 changes: 8 additions & 1 deletion docs/Configuration.md
Expand Up @@ -784,11 +784,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

By combining `defaultResolver` and `packageFilter` we can implement a `package.json` "pre-processor" that allows us to change how the default resolver will resolve modules. For example, imagine we want to use the field `"module"` if it is present, otherwise fallback to `"main"`:

```json
Expand Down
19 changes: 19 additions & 0 deletions e2e/__tests__/browserResolve.ts
@@ -0,0 +1,19 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import * as path from 'path';
import {runYarnInstall} from '../Utils';
import runJest from '../runJest';

test('browser resolver works', () => {
const dir = path.resolve(__dirname, '../browser-resolver');
runYarnInstall(dir);

const {exitCode} = runJest('browser-resolver');

expect(exitCode).toBe(0);
});
16 changes: 16 additions & 0 deletions e2e/browser-resolver/__tests__/test.js
@@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/* eslint-env browser */

'use strict';

const div = require('../fake-pkg');

test('dummy test', () => {
expect(div).toBeInstanceOf(HTMLDivElement);
});
16 changes: 16 additions & 0 deletions e2e/browser-resolver/fake-pkg/main.js
@@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/* eslint-env browser */

'use strict';

const div = document.createElement('div');

div.innerText = 'Hello!';

module.exports = div;
10 changes: 10 additions & 0 deletions e2e/browser-resolver/fake-pkg/package.json
@@ -0,0 +1,10 @@
{
"name": "fake-pkg",
"version": "1.0.0",
"main": "./nope.js",
"browser": {
"./nope.js": "./main.js"
},
"dependencies": {
}
}
9 changes: 9 additions & 0 deletions e2e/browser-resolver/package.json
@@ -0,0 +1,9 @@
{
"jest": {
"resolver": "<rootDir>/resolver.js",
"testEnvironment": "jsdom"
},
"dependencies": {
"browser-resolve": "^2.0.0"
}
}
12 changes: 12 additions & 0 deletions e2e/browser-resolver/resolver.js
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
75 changes: 75 additions & 0 deletions e2e/browser-resolver/yarn.lock
@@ -0,0 +1,75 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4
cacheKey: 7

"browser-resolve@npm:^2.0.0":
version: 2.0.0
resolution: "browser-resolve@npm:2.0.0"
dependencies:
resolve: ^1.17.0
checksum: 162cf825f0cd2c5921446af7abf6a98a538f41825a8562c354e5d11e49fbdb2917f12888c2560f08df3589902ce6538afc5c30c2778b6e2cd29a0bfa12ce780a
languageName: node
linkType: hard

"function-bind@npm:^1.1.1":
version: 1.1.1
resolution: "function-bind@npm:1.1.1"
checksum: ffad86e7d2010ba179aaa6a3987d2cc0ed48fa92d27f1ed84bfa06d14f77deeed5bfbae7f00bdebc0c54218392cab2b18ecc080e2c72f592431927b87a27d42b
languageName: node
linkType: hard

"has@npm:^1.0.3":
version: 1.0.3
resolution: "has@npm:1.0.3"
dependencies:
function-bind: ^1.1.1
checksum: c686e15300d41364486c099a9259d9c418022c294244843dcd712c4c286ff839d4f23a25413baa28c4d2c1e828afc2aaab70f685400b391533980223c71fa1ca
languageName: node
linkType: hard

"is-core-module@npm:^2.2.0":
version: 2.2.0
resolution: "is-core-module@npm:2.2.0"
dependencies:
has: ^1.0.3
checksum: 2344744de98a3bc22e2bb30895f307d7889f09e963f9bcb1cc321788f508c8b463f75e0a9ca009eeeb8eb9465181b5c15f1ec9299a6bb6921cfbb2423892e0ba
languageName: node
linkType: hard

"path-parse@npm:^1.0.6":
version: 1.0.6
resolution: "path-parse@npm:1.0.6"
checksum: 2eee4b93fb3ae13600e3fca18390d9933bbbcf725a624f6b8df020d87515a74872ff6c58072190d6dc75a5584a683dc6ae5c385ad4e4f4efb6e66af040d56c67
languageName: node
linkType: hard

resolve@^1.17.0:
version: 1.20.0
resolution: "resolve@npm:1.20.0"
dependencies:
is-core-module: ^2.2.0
path-parse: ^1.0.6
checksum: 0f5206d454b30e74d9b2d575b5f8aedf443c4d8b90b84cdf79474ade29bb459075220da3127b682896872a16022ed65cc4db09e0f23849654144d3d75c65cd1b
languageName: node
linkType: hard

"resolve@patch:resolve@^1.17.0#builtin<compat/resolve>":
version: 1.20.0
resolution: "resolve@patch:resolve@npm%3A1.20.0#builtin<compat/resolve>::version=1.20.0&hash=3388aa"
dependencies:
is-core-module: ^2.2.0
path-parse: ^1.0.6
checksum: c4a515b76026806b5b26513fc7bdb80458c532bc91c02ef45ac928d1025585f93bec0b904be39c02131118a37ff7e3f9258f1526850b025d2ec0948bb5fd03d0
languageName: node
linkType: hard

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
browser-resolve: ^2.0.0
languageName: unknown
linkType: soft
11 changes: 4 additions & 7 deletions packages/jest-config/src/Deprecated.ts
Expand Up @@ -12,13 +12,10 @@ import prettyFormat from 'pretty-format';
const format = (value: unknown) => prettyFormat(value, {min: true});

const deprecatedOptions: DeprecatedOptions = {
browser: () => ` Option ${chalk.bold(
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as follows:
{
${chalk.bold('"resolver"')}: ${chalk.bold('"browser-resolve"')}
}
`,
browser: () =>
` Option ${chalk.bold(
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as shown in the documentation: https://jestjs.io/docs/en/configuration#resolver-string`,

preprocessorIgnorePatterns: (options: {
preprocessorIgnorePatterns?: Array<string>;
Expand Down
9 changes: 8 additions & 1 deletion website/blog/2020-05-05-jest-26.md
Expand Up @@ -22,11 +22,18 @@ We are now beginning to address this shortcoming and are working on reducing Jes
```json
{
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

- TypeScript definitions requires a minimum of TypeScript v3.8 ([#9823](https://github.com/facebook/jest/pull/9823))

With the above changes Jest 26 is now 4 MiB smaller than Jest 25.5.4 (53 → 49 MiB). Please keep in mind that many dependencies like Babel are likely already part of your project. Jest's own size was reduced by 1.2 MiB (4.3 -> 3.1 MiB).
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-26.0/Configuration.md
Expand Up @@ -721,11 +721,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

### `restoreMocks` [boolean]

Default: `false`
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-26.2/Configuration.md
Expand Up @@ -729,11 +729,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

### `restoreMocks` [boolean]

Default: `false`
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-26.4/Configuration.md
Expand Up @@ -730,11 +730,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

By combining `defaultResolver` and `packageFilter` we can implement a `package.json` "pre-processor" that allows us to change how the default resolver will resolve modules. For example, imagine we want to use the field `"module"` if it is present, otherwise fallback to `"main"`:

```json
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-26.5/Configuration.md
Expand Up @@ -748,11 +748,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

By combining `defaultResolver` and `packageFilter` we can implement a `package.json` "pre-processor" that allows us to change how the default resolver will resolve modules. For example, imagine we want to use the field `"module"` if it is present, otherwise fallback to `"main"`:

```json
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-26.6/Configuration.md
Expand Up @@ -768,11 +768,18 @@ For example, if you want to respect Browserify's [`"browser"` field](https://git
{
...
"jest": {
"resolver": "browser-resolve"
"resolver": "<rootDir>/resolver.js"
}
}
```

```js
// resolver.js
const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
```

By combining `defaultResolver` and `packageFilter` we can implement a `package.json` "pre-processor" that allows us to change how the default resolver will resolve modules. For example, imagine we want to use the field `"module"` if it is present, otherwise fallback to `"main"`:

```json
Expand Down