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

35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,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
22 changes: 22 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
// babelrcRoots: ['.', 'packages/*', 'examples/*'],
plugins: [
// Required by some examples, like react-native. Without this plugin,
// they will simply crash before relative configs can be found.
// '@babel/plugin-proposal-class-properties',
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
],
presets: [
[
'@babel/preset-env',
{
shippedProposals: true,
targets: {node: '6'},
useBuiltIns: 'usage',
},
],
'@babel/preset-flow',
// Some tests contain JSX
'@babel/preset-react',
],
};
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
41 changes: 7 additions & 34 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,49 +79,22 @@ jest --init

### Using Babel

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

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

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

_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`. 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"],
"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
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 @@ -109,7 +109,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 @@ -279,23 +279,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`code coverage for transform instrumented code 1`] = `
Object {
"covered.js": Object {
"_coverageSchema": "332fd63041d2c1bcb487cc26dd0d5f7d97098a6c",
"_coverageSchema": "43e27e138ebf9cfc5966b082cf9a028302ed4184",
"b": Object {},
"branchMap": Object {},
"f": Object {
Expand Down
14 changes: 8 additions & 6 deletions e2e/__tests__/__snapshots__/expect-async-matcher.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ exports[`shows the correct errors in stderr when failing tests 1`] = `
27 | });

at __tests__/failure.test.js:24:54
at __tests__/failure.test.js:11:191
at __tests__/failure.test.js:11:437
at __tests__/failure.test.js:11:99
at __tests__/failure.test.js:13:103
at __tests__/failure.test.js:15:194
at __tests__/failure.test.js:15:364
at __tests__/failure.test.js:15:97

● fail with expected promise values and not

Expand All @@ -69,9 +70,10 @@ exports[`shows the correct errors in stderr when failing tests 1`] = `
33 | });

at __tests__/failure.test.js:30:61
at __tests__/failure.test.js:11:191
at __tests__/failure.test.js:11:437
at __tests__/failure.test.js:11:99
at __tests__/failure.test.js:13:103
at __tests__/failure.test.js:15:194
at __tests__/failure.test.js:15:364
at __tests__/failure.test.js:15:97

"
`;
7 changes: 4 additions & 3 deletions e2e/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,10 @@ exports[`works with node assert 1`] = `
83 |

at __tests__/node_assertion_error.test.js:81:10
at __tests__/node_assertion_error.test.js:12:191
at __tests__/node_assertion_error.test.js:12:437
at __tests__/node_assertion_error.test.js:12:99
at __tests__/node_assertion_error.test.js:13:103
at __tests__/node_assertion_error.test.js:15:194
at __tests__/node_assertion_error.test.js:15:364
at __tests__/node_assertion_error.test.js:15:97

"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`moduleNameMapper wrong configuration 1`] = `
12 | module.exports = () => 'test';
13 |

at packages/jest-resolve/build/index.js:411:17
at packages/jest-resolve/build/index.js:430:17
at index.js:10:1

"
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/dependency_clash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ test('fails with syntax error on flow types', () => {
writeFiles(tempDir, {
'.babelrc': `
{
"plugins": [
"${require.resolve('babel-plugin-transform-flow-strip-types')}"
"presets": [
"${require.resolve('@babel/preset-flow')}"
]
}
`,
Expand Down
12 changes: 0 additions & 12 deletions e2e/babel-plugin-jest-hoist/.babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions e2e/babel-plugin-jest-hoist/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
plugins: ['jest-hoist'],
presets: ['@babel/preset-env', '@babel/preset-flow'],
};
4 changes: 2 additions & 2 deletions e2e/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.9.0",
"@babel/preset-env": "7.0.0",
"@babel/preset-flow": "7.0.0",
"react": "*"
},
"jest": {
Expand Down
Loading