ava: Babel plugins not loading when overridden in package.json AVA section

Description

The documentation discusses overriding Babel configuration in the AVA section. However it appears at least the "plugins" if not the entire configuration is ignored in favor of .babelrc or the defaults.

Specifically: We need babel-plugin-rewire for our tests so we setup the AVA section of our package.json to look like:

{
  //...
  "ava": {
    "files": [
      "./tests/client/**/*.test.js",
      "./tests/server/**/*.test.js"
    ],
    "source": [
      "./src/client/scripts/**/*.{js,jsx}",
      "!./src/client/scripts/*Entry.js",
      "./src/server/**/*.js"
    ],
    "failFast": true,
    "tap": false,
    "require": [
      "babel-register",
      "babel-polyfill"
    ],
    "babel": {
      "presets": ["es2015", "react", "stage-0"],
      "plugins": ["rewire"]
    }
  },
  //...
}

With our .babelrc looking like:

{
  "presets": ["es2015", "react", "stage-0"]
}

However the tests would fail saying TypeError: Cannot read property ‘Rewire’ of undefined which indicates the plugin isn’t running.

When I update the .babelrc file to include the "plugins": ["rewire"] it works.

Dropping console.logs in the rewire plugin inside of node_modules confirms the plugin doesn’t even attempt to load.

I dropped some console logs into caching-precompiler.js in the _createTransform method and it IS getting the configuration I expect from package.json so the failure may be on caching-transform’s part.

Environment

Node.js v5.9.0 darwin 15.4.0 AVA 0.13.0

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 16 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Good point, apply the env to the least common tasks to remove redundant bits. One more downside is having to repeat sections of .babelrc, in my case, at the moment:

{
  "presets": [
    "es2015",
    "react",
    "stage-2"
  ],
  "plugins": [
    "transform-object-rest-spread"
  ],
  "env": {
    "test": {
      "plugins": [
        "transform-object-rest-spread",
        "rewire"
      ]
    }
  }
}

But that’s just Babel now. Anyhow, things work, testing away! 😂