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

Babel 7 #7016

Merged
merged 70 commits into from
Dec 18, 2018
Merged

Babel 7 #7016

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
ea9ab40
Start babel migration.
milesj Sep 5, 2018
60efb77
More fixes.
milesj Sep 5, 2018
cfa0dc8
More things.
milesj Sep 5, 2018
cf9b8c1
Fix RN.
milesj Sep 5, 2018
36b4ce7
More updates.
milesj Sep 5, 2018
94d953f
Update configs.
Sep 10, 2018
63e5b11
Update RN support.
Sep 10, 2018
299b3e4
Rework Babel config loading.
Sep 10, 2018
c04e77a
Update deps.
Sep 10, 2018
080a6e3
Update some deps.
Sep 10, 2018
0d62cef
Fix rollup build.
Sep 10, 2018
6459523
Remove browser build plugin.
Sep 10, 2018
c6d5c80
Target IE8.
Sep 10, 2018
35c5a06
Update to beta RN.
Sep 10, 2018
d2ab617
Parser updates.
Sep 10, 2018
7287a11
Upgrade istanbul.
Sep 10, 2018
0760c89
Rework lazy.
Sep 10, 2018
0a2efd0
More work and polish.
Sep 11, 2018
5fee976
Use transformSync.
Sep 12, 2018
84bc7ce
Update react-native.
Sep 12, 2018
4e26ae8
Fix RN tests.
Sep 12, 2018
46d0d38
Final fixes.
milesj Sep 16, 2018
1b21e1c
Minor changes.
milesj Sep 16, 2018
397f43e
Use babel for TS.
milesj Sep 16, 2018
9140760
Update deps. Run install.
milesj Sep 21, 2018
8d6248e
Update editor support.
milesj Sep 21, 2018
e47e545
Add TS argument.
milesj Sep 21, 2018
40e668b
dedupe
SimenB Sep 21, 2018
c066ebc
remove unneeded babel 7 example
SimenB Sep 21, 2018
09979af
nohoist react-native
SimenB Sep 21, 2018
a64c188
Merge branch 'master' into babel-7
SimenB Oct 17, 2018
b4a35eb
botched merge by yarn
SimenB Oct 17, 2018
6153100
update hash
SimenB Oct 17, 2018
c57600b
use babel.config.js
SimenB Oct 17, 2018
53986b1
update snapshot
SimenB Oct 18, 2018
ab099ac
Merge branch 'master' into babel-7
SimenB Oct 18, 2018
e5204d8
add missing plugin to babel config
SimenB Oct 18, 2018
f1189dd
dep cleanup
SimenB Oct 18, 2018
bcf7d87
remove builtins from browser build
SimenB Oct 18, 2018
d729d1f
rollback immutable js to fix test
SimenB Oct 18, 2018
0f0c1bd
add babel config to fix node 6
SimenB Oct 18, 2018
18e2d53
Merge branch 'master' into babel-7
SimenB Oct 18, 2018
e3a4df4
fix react-native example
SimenB Oct 20, 2018
d68f6a2
Merge branch 'master' into babel-7
SimenB Oct 21, 2018
ec4cfbc
Merge branch 'master' into babel-7
SimenB Oct 24, 2018
1d976ae
Merge branch 'master' into babel-7
SimenB Oct 24, 2018
2bca3b6
Merge branch 'master' into babel-7
SimenB Nov 20, 2018
be1617d
Merge remote-tracking branch 'origin/master' into babel-7
SimenB Dec 11, 2018
8389898
coverage?
SimenB Nov 27, 2018
2164043
add copyright notice
SimenB Dec 11, 2018
f6ff11a
update snapshots
SimenB Dec 11, 2018
965cc3d
moar copyright
SimenB Dec 11, 2018
4eda413
fix script_transformer test missing package.json to resolve to
thymikee Dec 12, 2018
6a663d0
fix init test
thymikee Dec 15, 2018
63e06be
fix repl by es6 export Runtime
thymikee Dec 15, 2018
0041cea
cleanup babel.config.js
SimenB Dec 16, 2018
1388570
fix promise test by targetting higher Node version without Promise po…
thymikee Dec 17, 2018
74d4f0f
add babelrcRoots back
thymikee Dec 17, 2018
bec6675
Revert "fix promise test by targetting higher Node version without Pr…
SimenB Dec 17, 2018
1d2cde5
polyfill nothing via babel preset env
SimenB Dec 17, 2018
f251080
jest.mock to jest.spyOn
thymikee Dec 17, 2018
480e1d4
update e2e snapshot
thymikee Dec 17, 2018
7af41a8
leave only examples in babelrcRoots
thymikee Dec 17, 2018
54765c9
update lockfile
SimenB Dec 18, 2018
7c557e2
super ugly fix symbol
SimenB Dec 18, 2018
e835860
fix windows tests
SimenB Dec 18, 2018
dd8cfe0
fix test for node 6
SimenB Dec 18, 2018
dadd03e
inline require slash in mock
SimenB Dec 18, 2018
c3c8e83
gah, windows :(
SimenB Dec 18, 2018
095242e
update changelog
SimenB Dec 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381))
- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448))
- `[*]` [**BREAKING**] Upgrade to Babel 7, dropping support for Babel 6 ([#7016](https://github.com/facebook/jest/pull/7016))
- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))
Expand Down
35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,22 @@ If you'd like to learn more about running `jest` through the command line, take

### Using Babel

[Babel](http://babeljs.io/) is automatically handled by Jest using `babel-jest`. You don't need install anything extra for using Babel.
To use [Babel](http://babeljs.io/), install the `babel-jest` and `@babel/core` packages:

> Note: If you are using Babel version 7 then you need to install `babel-jest`, `babel-core@^7.0.0-bridge.0` and `@babel/core` with the following command:
>
> ```bash
> yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime
> ```
```bash
yarn add --dev babel-jest @babel/core
```

Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://reactjs.org) with the [`babel-preset-env`](https://babeljs.io/docs/plugins/preset-env/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
Don't forget to add a [`babel.config.js`](https://babeljs.io/docs/en/config-files) file in your project's root folder. For example, if you are using ES6 and [React.js](https://reactjs.org) with the [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) and [`@babel/preset-react`](https://babeljs.io/docs/en/babel-preset-react) presets:

```json
{
"presets": ["env", "react"]
}
```js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};
```

You are now set up to use all ES6 features and React specific syntax.

> Note: If you are using a more complicated Babel configuration, using Babel's `env` option, keep in mind that Jest will automatically define `NODE_ENV` as `test`. It will not use `development` section like Babel does by default when no `NODE_ENV` is set.

> Note: If you've turned off transpilation of ES modules with the option `{ "modules": false }`, you have to make sure to turn this on in your test environment.

```json
{
"presets": [["env", {"modules": false}], "react"],
"env": {
"test": {
"presets": [["env"], "react"]
}
}
}
```

> Note: `babel-jest` is automatically installed when installing Jest and will automatically transform files if a babel configuration exists in your project. To avoid this behavior, you can explicitly reset the `transform` configuration option:

```json
Expand Down
19 changes: 19 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

module.exports = {
babelrcRoots: ['examples/*'],
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
],
presets: [
[
'@babel/preset-env',
{
shippedProposals: true,
targets: {node: 6},
},
],
'@babel/preset-flow',
],
};
2 changes: 1 addition & 1 deletion docs/Es6ClassMocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jest.mock('./sound-player', () => {
});
```

This will throw **_TypeError: \_soundPlayer2.default is not a constructor_**, unless the code is transpiled to ES5, e.g. by babel-preset-env. (ES5 doesn't have arrow functions nor classes, so both will be transpiled to plain functions.)
This will throw **_TypeError: \_soundPlayer2.default is not a constructor_**, unless the code is transpiled to ES5, e.g. by `@babel/preset-env`. (ES5 doesn't have arrow functions nor classes, so both will be transpiled to plain functions.)

## Keeping track of usage (spying on the mock)

Expand Down
36 changes: 7 additions & 29 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,22 @@ jest --init

### Using Babel

To use [Babel](http://babeljs.io/), install the `babel-jest` and `regenerator-runtime` packages via `yarn`:
To use [Babel](http://babeljs.io/), install the `babel-jest` and `@babel/core` packages via `yarn`:

```bash
yarn add --dev babel-jest babel-core regenerator-runtime
yarn add --dev babel-jest @babel/core
```

Or `npm`:
Don't forget to add a [`babel.config.js`](https://babeljs.io/docs/en/config-files) file in your project's root folder. For example, if you are using ES6 and [React.js](https://reactjs.org) with the [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) and [`@babel/preset-react`](https://babeljs.io/docs/en/babel-preset-react) presets:

```bash
npm install --save-dev babel-jest babel-core regenerator-runtime
```

> Note: If you are using Babel version 7 then you need to install `babel-jest`, `babel-core@^7.0.0-bridge.0` and `@babel/core` with the following command or its `npm` equivalent:
>
> ```bash
> yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime
> ```
>
> You will need to use `babel.config.js` in order to transpile `node_modules`. See https://babeljs.io/docs/en/next/config-files for more information.
>
> You can also see the example in the Jest repository: https://github.com/facebook/jest/tree/master/examples/babel-7

_Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn_

Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://facebook.github.io/react/) with the [`babel-preset-env`](https://babeljs.io/docs/plugins/preset-env/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:

```json
{
"presets": ["env", "react"]
}
```js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};
```

You are now set up to use all ES6 features and React specific syntax.

> Note: If you are using a more complicated Babel configuration, using Babel's `env` option, keep in mind that Jest will automatically define `NODE_ENV` as `test` **if not already set** to something else. It will not use `development` section like Babel does by default when no `NODE_ENV` is set.

> Note: If you've turned off transpilation of ES6 modules with the option `{ "modules": false }`, you have to make sure to turn this on in your test environment.

```json
{
"presets": [["env", {"modules": false}], "react"],
Expand Down
2 changes: 1 addition & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ If you are using Facebook's [`create-react-app`](https://github.com/facebookincu

## Caching Issues

The transform script was changed or babel was updated and the changes aren't being recognized by Jest?
The transform script was changed or Babel was updated and the changes aren't being recognized by Jest?

Retry with [`--no-cache`](CLI.md#cache). Jest caches transformed module files to speed up test execution. If you are using your own custom transformer, consider adding a `getCacheKey` function to it: [getCacheKey in Relay](https://github.com/facebook/relay/blob/58cf36c73769690f0bbf90562707eadb062b029d/scripts/jest/preprocessor.js#L56-L61).

Expand Down
2 changes: 1 addition & 1 deletion docs/TutorialAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ it('works with async/await and resolves', async () => {
});
```

To enable async/await in your project, install [`babel-preset-env`](http://babeljs.io/docs/plugins/preset-env/) and enable the feature in your `.babelrc` file.
To enable async/await in your project, install [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) and enable the feature in your `babel.config.js` file.

## Error handling

Expand Down
33 changes: 16 additions & 17 deletions docs/TutorialReact.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you have an existing application you'll need to install a few packages to mak
Run

```bash
yarn add --dev jest babel-jest babel-preset-env babel-preset-react react-test-renderer
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react react-test-renderer
```

Your `package.json` should look something like this (where `<current-version>` is the actual latest version number for the package). Please add the scripts and jest configuration entries:
Expand All @@ -36,9 +36,9 @@ Your `package.json` should look something like this (where `<current-version>` i
"react-dom": "<current-version>"
},
"devDependencies": {
"@babel/preset-env": "<current-version>",
"@babel/preset-react": "<current-version>",
"babel-jest": "<current-version>",
"babel-preset-env": "<current-version>",
"babel-preset-react": "<current-version>",
"jest": "<current-version>",
"react-test-renderer": "<current-version>"
},
Expand All @@ -47,11 +47,11 @@ Your `package.json` should look something like this (where `<current-version>` i
}
```

```json
// .babelrc
{
"presets": ["env", "react"]
}
```js
// babel.config.js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};
```

**And you're good to go!**
Expand Down Expand Up @@ -309,23 +309,22 @@ If you need more advanced functionality, you can also build your own transformer
// custom-transformer.js
'use strict';

const babel = require('babel-core');
const {transform} = require('@babel/core');
const jestPreset = require('babel-preset-jest');

module.exports = {
process(src, filename) {
if (babel.util.canCompile(filename)) {
return babel.transform(src, {
filename,
presets: [jestPreset],
});
}
return src;
const result = transform(src, {
filename,
presets: [jestPreset],
});

return result ? result.code : src;
},
};
```

Don't forget to install the `babel-core` and `babel-preset-jest` packages for this example to work.
Don't forget to install the `@babel/core` and `babel-preset-jest` packages for this example to work.

To make this work with Jest you need to update your Jest configuration with this: `"transform": {"\\.js$": "path/to/custom-transformer.js"}`.

Expand Down
2 changes: 1 addition & 1 deletion docs/TutorialReactNative.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ The preset sets up the environment and is very opinionated and based on what we

### transformIgnorePatterns customization

The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array-string) option can be used to whitelist or blacklist files from being transformed with babel. Many react-native npm modules unfortunately don't pre-compile their source code before publishing.
The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array-string) option can be used to whitelist or blacklist files from being transformed with Babel. Many react-native npm modules unfortunately don't pre-compile their source code before publishing.

By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by whitelisting modules other than react-native:

Expand Down
46 changes: 23 additions & 23 deletions e2e/__tests__/__snapshots__/coverage_report.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ exports[`generates coverage when using the testRegex config param 1`] = `
"-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files </> | 56.52</> | 0</> | 50</> | 55.56</> | </> |
coverage-report </> | 41.18</> | 0</> | 25</> | 42.86</> | </> |
OtherFile.js </> | 100</> | 100</> | 100</> | 100</> | </> |
Sum.js </> | 85.71</> | 100</> | 50</> | 100</> | </> |
SumDependency.js </> | 0</> | 0</> | 0</> | 0</> | 8,10,12</> |
notRequiredInTestSuite.js </> | 0</> | 0</> | 0</> | 0</> | 8,15,16,17,19</> |
coverage-report/cached-duplicates/a</> | 100</> | 100</> | 100</> | 100</> | </> |
Identical.js </> | 100</> | 100</> | 100</> | 100</> | </> |
coverage-report/cached-duplicates/b</> | 100</> | 100</> | 100</> | 100</> | </> |
Identical.js </> | 100</> | 100</> | 100</> | 100</> | </> |
All files | 59.09 | 0 | 50 | 58.82 | |
coverage-report | 43.75 | 0 | 25 | 46.15 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
-------------------------------------|----------|----------|----------|----------|-------------------|"
`;

Expand All @@ -72,12 +72,12 @@ exports[`outputs coverage report 1`] = `
"-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.52 | 0 | 50 | 55.56 | |
coverage-report | 41.18 | 0 | 25 | 42.86 | |
All files | 59.09 | 0 | 50 | 58.82 | |
coverage-report | 43.75 | 0 | 25 | 46.15 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Expand All @@ -88,20 +88,20 @@ All files | 56.52 | 0 | 50 | 55.56
exports[`outputs coverage report when text and text-summary is requested 1`] = `
"
=============================== Coverage summary ===============================
Statements : 56.52% ( 13/23 )
Statements : 59.09% ( 13/22 )
Branches : 0% ( 0/4 )
Functions : 50% ( 3/6 )
Lines : 55.56% ( 10/18 )
Lines : 58.82% ( 10/17 )
================================================================================
-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.52 | 0 | 50 | 55.56 | |
coverage-report | 41.18 | 0 | 25 | 42.86 | |
All files | 59.09 | 0 | 50 | 58.82 | |
coverage-report | 43.75 | 0 | 25 | 46.15 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Expand All @@ -113,12 +113,12 @@ exports[`outputs coverage report when text is requested 1`] = `
"-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.52 | 0 | 50 | 55.56 | |
coverage-report | 41.18 | 0 | 25 | 42.86 | |
All files | 59.09 | 0 | 50 | 58.82 | |
coverage-report | 43.75 | 0 | 25 | 46.15 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Expand All @@ -129,9 +129,9 @@ All files | 56.52 | 0 | 50 | 55.56
exports[`outputs coverage report when text-summary is requested 1`] = `
"
=============================== Coverage summary ===============================
Statements : 56.52% ( 13/23 )
Statements : 59.09% ( 13/22 )
Branches : 0% ( 0/4 )
Functions : 50% ( 3/6 )
Lines : 55.56% ( 10/18 )
Lines : 58.82% ( 10/17 )
================================================================================"
`;
Loading