Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 2.48 KB

babelrc.md

File metadata and controls

88 lines (65 loc) · 2.48 KB

Configuring Babel

Translations: Français

There are multiple options for configuring how AVA transpiles your tests using Babel.

Specify a complete config in package.json

The babelrc option defaults to false, meaning .babelrc files are not considered when transpiling tests. This means you must specify your complete config in package.json.

{
  "ava": {
    "babel": {
      "plugins": ["rewire"],
      "presets": ["es2015"]
    }
  }
}

Extend existing .babelrc without modification

Use the "inherit" shortcut if you want your tests transpiled the same as your sources. This will use your .babelrc directly (with a few additional internal plugins).

package.json:

{
 "ava": {
   "babel": "inherit"
 }
}

Extend existing .babelrc with additional plugins or presets

Set babelrc to true. This will use your .babelrc and extend it with any additional plugins specified.

package.json:

{
  "ava": {
    "babel": {
      "babelrc": true,
      "plugins": ["custom-plugin-name"],
      "presets": ["custom-preset"]
    }
  }
}

Extend alternate config file.

If, for some reason, you do not want to extend .babelrc, set the extends option to the alternate config you want to use during testing.

package.json:

{
  "ava": {
    "babel": {
      "extends": "./babel-test-config.json",
      "plugins": ["custom-plugin-name"],
      "presets": ["custom-preset"]
    }
  }
}

The above uses babel-test-config.json as the base config, and extends it with the custom plugins and presets specified.

Notes

AVA always adds a few custom Babel plugins when transpiling your plugins. They serve a variety of functions:

  • Enable power-assert support.
  • Rewrite require paths internal AVA dependencies like babel-runtime (important if you are still using npm@2).
  • Generate test metadata to determine which files should be run first (future).
  • Static analysis of dependencies for precompilation (future).