Skip to content

Commit

Permalink
Improve Babel recipe (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Breisch authored and novemberborn committed Apr 4, 2017
1 parent 146c3e2 commit ecdadfa
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/recipes/babelrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit ecdadfa

Please sign in to comment.