-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel plugins not loading when overridden in package.json AVA section #674
Comments
Additional notesSo after I submit this issue I set
And it repeats slowly accumulating for each file AVA loads Obviously the console logs are from some that I dropped trying to figure out how AVA is working internally, a copy of my file can be found in this gist |
I think the/a bug is here in the options.plugins.push. Possibly a |
That helps a lot actually, PR incoming |
@dcousineau There are other issues where we are discussing solutions: |
I'll dig in further thanks! |
Since `babelConfig` in the CachingPrecompiler.prototype._factory method was a JavaScript object coming from an external source, the .push was altering the array in place. objectAssign is shallow so the plugins were being mutated, ensuring that AVA's required plugins were continually apending for each file loaded and parsed. Using .concat ensures the original plugins array is not mutated and thus doesn't collect plugins like a hoarder.
@jamestalmage aha I get it now. I'm curious, do you think there'd be a way to provide configuration for the babel-register for the sources? In the mean time I'm making my webpack config force its own babel config and will use babelrc to include the rewire plugin, in general I only want rewire plugin operating in a testing context but not when building the client. |
Ah, I see your dilemma. We still need to implement an // package.json
{
"ava": {
"babel" : {
"extends": "./babelrc",
"plugins": ["rewire"]
}
}
} It was discussed along with #573, but never got implemented. |
@jamestalmage if and only if I can specify the babel config for the source files as well (not just the test files) which I think is my real ask. (but an extends would be great as well) Should I close this issue or rename it as a feature request? After doing some other things and sleeping on it I realize this is not a bug given what you've told me about the differences in transpiling test files and transpiling source files. |
If you want the same config for both tests and sources, do With |
The @dcousineau I'm closing this for now. Please feel free to reopen if you still have issues. |
I have the exact same use case, trying to use babel-plugin-rewire only in tests. |
Your best bet is to have it default to installing rewire / everything you need for testing. That way your most common operation, running tests, needs no special environment variable set. Use envs to turn off that stuff when you go to build. |
Good point, apply the env to the least common tasks to remove redundant bits.
But that's just Babel now. Anyhow, things work, testing away! 😂 |
I've found that I have to do the same as @kosmotaur:
For my main build I want babel to ignore modules as to allow Webpack 2 tree-shaking but need babel to transpile them in a test context. Not matter what I tried in |
@djskinner did you try specifying the |
Yes, you're right about the presets getting replace as I'd expected. I ended up doing this:
|
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:With our
.babelrc
looking like: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 oncaching-transform
's part.Environment
Node.js v5.9.0
darwin 15.4.0
AVA 0.13.0
The text was updated successfully, but these errors were encountered: