mirror of https://github.com/facebook/jest.git
fix: add integration test using browser-resolve (#11140)
This commit is contained in:
parent
711b60262a
commit
78af37990d
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
|
@ -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);
|
||||
});
|
|
@ -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;
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "fake-pkg",
|
||||
"version": "1.0.0",
|
||||
"main": "./nope.js",
|
||||
"browser": {
|
||||
"./nope.js": "./main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"jest": {
|
||||
"resolver": "<rootDir>/resolver.js",
|
||||
"testEnvironment": "jsdom"
|
||||
},
|
||||
"dependencies": {
|
||||
"browser-resolve": "^2.0.0"
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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
|
|
@ -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>;
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue