diff --git a/docs/recipes/babelrc.md b/docs/recipes/babelrc.md index 39f42c053..b3d43fbda 100644 --- a/docs/recipes/babelrc.md +++ b/docs/recipes/babelrc.md @@ -13,7 +13,7 @@ There are multiple options for configuring how AVA transpiles your tests using B ## AVA's default transpiler behavior -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`. +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. ## Customizing how AVA transpiles your tests @@ -30,6 +30,24 @@ You can override the default Babel configuration AVA uses for test transpilation } ``` +## Use Babel Polyfills + +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. + +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. + +You can enable `babel-polyfill` by adding it to AVA's `require` option: + +```json +{ + "ava": { + "require": [ + "babel-polyfill" + ] + } +} +``` + ## Transpiling Sources 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: