Skip to content

Commit

Permalink
Replace babel-polyfill with only regenerator-runtime (#2755)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and cpojer committed Feb 27, 2017
1 parent f4c3b78 commit e08c81e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ This test used `expect` and `toBe` to test that two values were exactly identica

### Using Babel

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

```
npm install --save-dev babel-jest babel-polyfill
npm install --save-dev babel-jest regenerator-runtime
```

*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-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:

```js
Expand Down
6 changes: 4 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ This test used `expect` and `toBe` to test that two values were exactly identica

### Using Babel

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

```
npm install --save-dev babel-jest babel-polyfill
npm install --save-dev babel-jest regenerator-runtime
```

*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-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:

```js
Expand Down
4 changes: 2 additions & 2 deletions examples/async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"devDependencies": {
"babel-jest": "*",
"babel-plugin-transform-async-to-generator": "^6.5.0",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"jest": "*"
"jest": "*",
"regenerator-runtime": "*"
},
"scripts": {
"test": "jest"
Expand Down
4 changes: 2 additions & 2 deletions examples/enzyme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
},
"devDependencies": {
"babel-jest": "*",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"enzyme": "~2.4.1",
"jest": "*",
"react-addons-test-utils": "15.3.2"
"react-addons-test-utils": "15.3.2",
"regenerator-runtime": "*"
},
"scripts": {
"test": "jest"
Expand Down
4 changes: 2 additions & 2 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
},
"devDependencies": {
"babel-jest": "*",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"jest": "*",
"react-addons-test-utils": "~15.3.1"
"react-addons-test-utils": "~15.3.1",
"regenerator-runtime": "*"
},
"scripts": {
"test": "jest"
Expand Down
4 changes: 2 additions & 2 deletions examples/snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
},
"devDependencies": {
"babel-jest": "*",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"jest": "*",
"react-test-renderer": "*"
"react-test-renderer": "*",
"regenerator-runtime": "*"
},
"scripts": {
"test": "jest"
Expand Down
35 changes: 28 additions & 7 deletions packages/jest-config/src/__tests__/normalize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,15 @@ describe('babel-jest', () => {
expect(config.transform[0][0]).toBe(DEFAULT_JS_PATTERN);
expect(config.transform[0][1])
.toEqual(path.sep + 'node_modules' + path.sep + 'babel-jest');
expect(config.setupFiles)
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
expect(config.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);

});

it('uses babel-jest if babel-jest is explicitly specified in a custom transform config', () => {
Expand All @@ -533,8 +540,15 @@ describe('babel-jest', () => {

expect(config.transform[0][0]).toBe(customJSPattern);
expect(config.transform[0][1]).toEqual('/node_modules/babel-jest');
expect(config.setupFiles)
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
expect(config.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);

});

it(`doesn't use babel-jest if its not available`, () => {
Expand All @@ -548,7 +562,7 @@ describe('babel-jest', () => {
expect(config.setupFiles).toEqual([]);
});

it('uses polyfills if babel-jest is explicitly specified', () => {
it('uses regenerator if babel-jest is explicitly specified', () => {
const ROOT_DIR = '<rootDir>' + path.sep;

const {config} = normalize({
Expand All @@ -560,8 +574,15 @@ describe('babel-jest', () => {
},
});

expect(config.setupFiles)
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
expect(config.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);

});
});

Expand Down
11 changes: 6 additions & 5 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ function normalize(config: InitialConfig, argv: Object = {}) {
}, newConfig);

if (babelJest) {
const polyfillPath = Resolver.findNodeModule('babel-polyfill', {
basedir: config.rootDir,
});
const regeneratorRuntimePath = Resolver.findNodeModule(
'regenerator-runtime/runtime',
{basedir: config.rootDir},
);

if (polyfillPath) {
newConfig.setupFiles.unshift(polyfillPath);
if (regeneratorRuntimePath) {
newConfig.setupFiles.unshift(regeneratorRuntimePath);
}
}

Expand Down

0 comments on commit e08c81e

Please sign in to comment.