Skip to content

Commit ecdadfa

Browse files
Florian Breischnovemberborn
Florian Breisch
authored andcommitted
Improve Babel recipe (#1290)
1 parent 146c3e2 commit ecdadfa

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/recipes/babelrc.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are multiple options for configuring how AVA transpiles your tests using B
1313

1414
## AVA's default transpiler behavior
1515

16-
By default, AVA transpiles your tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`.
16+
AVA lets you use some nifty JavaScript features, like [async functions](https://github.com/avajs/ava#async-function-support). To make this work on older Node.js versions AVA transpiles the tests and helper files using the [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) Babel preset. This is great for projects where you do not use Babel for your source, but do want to use the newest JavaScript features for your tests.
1717

1818
## Customizing how AVA transpiles your tests
1919

@@ -30,6 +30,24 @@ You can override the default Babel configuration AVA uses for test transpilation
3030
}
3131
```
3232

33+
## Use Babel Polyfills
34+
35+
AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying Node.js 4 environment.
36+
37+
By loading [Babel's Polyfill module](https://babeljs.io/docs/usage/polyfill/) you can opt in to these features. Note that this will modify the environment, which may influence how your program behaves.
38+
39+
You can enable `babel-polyfill` by adding it to AVA's `require` option:
40+
41+
```json
42+
{
43+
"ava": {
44+
"require": [
45+
"babel-polyfill"
46+
]
47+
}
48+
}
49+
```
50+
3351
## Transpiling Sources
3452

3553
To transpile your sources, you will need to define a [`babel config` ](http://babeljs.io/docs/usage/babelrc/) in `package.json` or a `.babelrc` file. Also, you will need to tell AVA to load [`babel-register`](http://babeljs.io/docs/usage/require/) in every forked process, by adding it to the `require` section of your AVA config:

0 commit comments

Comments
 (0)