Skip to content

Commit e08c81e

Browse files
thymikeecpojer
authored andcommitted
Replace babel-polyfill with only regenerator-runtime (#2755)
1 parent f4c3b78 commit e08c81e

File tree

8 files changed

+50
-24
lines changed

8 files changed

+50
-24
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ This test used `expect` and `toBe` to test that two values were exactly identica
6262

6363
### Using Babel
6464

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

6767
```
68-
npm install --save-dev babel-jest babel-polyfill
68+
npm install --save-dev babel-jest regenerator-runtime
6969
```
7070

71+
*Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn*
72+
7173
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:
7274

7375
```js

docs/GettingStarted.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ This test used `expect` and `toBe` to test that two values were exactly identica
5555

5656
### Using Babel
5757

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

6060
```
61-
npm install --save-dev babel-jest babel-polyfill
61+
npm install --save-dev babel-jest regenerator-runtime
6262
```
6363

64+
*Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn*
65+
6466
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:
6567

6668
```js

examples/async/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"devDependencies": {
33
"babel-jest": "*",
44
"babel-plugin-transform-async-to-generator": "^6.5.0",
5-
"babel-polyfill": "*",
65
"babel-preset-es2015": "*",
7-
"jest": "*"
6+
"jest": "*",
7+
"regenerator-runtime": "*"
88
},
99
"scripts": {
1010
"test": "jest"

examples/enzyme/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
},
66
"devDependencies": {
77
"babel-jest": "*",
8-
"babel-polyfill": "*",
98
"babel-preset-es2015": "*",
109
"babel-preset-react": "*",
1110
"enzyme": "~2.4.1",
1211
"jest": "*",
13-
"react-addons-test-utils": "15.3.2"
12+
"react-addons-test-utils": "15.3.2",
13+
"regenerator-runtime": "*"
1414
},
1515
"scripts": {
1616
"test": "jest"

examples/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
},
66
"devDependencies": {
77
"babel-jest": "*",
8-
"babel-polyfill": "*",
98
"babel-preset-es2015": "*",
109
"babel-preset-react": "*",
1110
"jest": "*",
12-
"react-addons-test-utils": "~15.3.1"
11+
"react-addons-test-utils": "~15.3.1",
12+
"regenerator-runtime": "*"
1313
},
1414
"scripts": {
1515
"test": "jest"

examples/snapshot/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
},
55
"devDependencies": {
66
"babel-jest": "*",
7-
"babel-polyfill": "*",
87
"babel-preset-es2015": "*",
98
"babel-preset-react": "*",
109
"jest": "*",
11-
"react-test-renderer": "*"
10+
"react-test-renderer": "*",
11+
"regenerator-runtime": "*"
1212
},
1313
"scripts": {
1414
"test": "jest"

packages/jest-config/src/__tests__/normalize-test.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,15 @@ describe('babel-jest', () => {
518518
expect(config.transform[0][0]).toBe(DEFAULT_JS_PATTERN);
519519
expect(config.transform[0][1])
520520
.toEqual(path.sep + 'node_modules' + path.sep + 'babel-jest');
521-
expect(config.setupFiles)
522-
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
521+
expect(config.setupFiles).toEqual([
522+
path.sep +
523+
'node_modules' +
524+
path.sep +
525+
'regenerator-runtime' +
526+
path.sep +
527+
'runtime',
528+
]);
529+
523530
});
524531

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

534541
expect(config.transform[0][0]).toBe(customJSPattern);
535542
expect(config.transform[0][1]).toEqual('/node_modules/babel-jest');
536-
expect(config.setupFiles)
537-
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
543+
expect(config.setupFiles).toEqual([
544+
path.sep +
545+
'node_modules' +
546+
path.sep +
547+
'regenerator-runtime' +
548+
path.sep +
549+
'runtime',
550+
]);
551+
538552
});
539553

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

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

554568
const {config} = normalize({
@@ -560,8 +574,15 @@ describe('babel-jest', () => {
560574
},
561575
});
562576

563-
expect(config.setupFiles)
564-
.toEqual([path.sep + 'node_modules' + path.sep + 'babel-polyfill']);
577+
expect(config.setupFiles).toEqual([
578+
path.sep +
579+
'node_modules' +
580+
path.sep +
581+
'regenerator-runtime' +
582+
path.sep +
583+
'runtime',
584+
]);
585+
565586
});
566587
});
567588

packages/jest-config/src/normalize.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,13 @@ function normalize(config: InitialConfig, argv: Object = {}) {
375375
}, newConfig);
376376

377377
if (babelJest) {
378-
const polyfillPath = Resolver.findNodeModule('babel-polyfill', {
379-
basedir: config.rootDir,
380-
});
378+
const regeneratorRuntimePath = Resolver.findNodeModule(
379+
'regenerator-runtime/runtime',
380+
{basedir: config.rootDir},
381+
);
381382

382-
if (polyfillPath) {
383-
newConfig.setupFiles.unshift(polyfillPath);
383+
if (regeneratorRuntimePath) {
384+
newConfig.setupFiles.unshift(regeneratorRuntimePath);
384385
}
385386
}
386387

0 commit comments

Comments
 (0)