-
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
Stop transpiling ESM out of the box? #1908
Comments
I wouldn't mind too much either way, but I will say that for me personally, AVA was a nice, practical introduction to ES6 and ESM. There are a lot of blog posts talking about ESM, but it barely has any usage yet outside of projects with a Babel build step. With AVA, it feels native even though it's not, since it's zero-config for test files, and I like that. It feels like the future (and it is). I've always found it pretty easy to test CJS modules with AVA. I think testing Babel projects is a bit harder, but that seems expected to me. As for how to reduce the mental burden on users, I have a few ideas:
|
I don't think it's worth breaking pretty much everyone's tests just because some users don't understand how it works. The solution here is better docs. I do agree the |
I was hoping AVA would rather move to a model where it either transpiles everything (or the specified files to be transpiled) or nothing. That way there's no confusion. |
Thanks @sholladay. I agree with all your points. For Babel projects, I agree that the biggest hurdle is that AVA doesn't compile sources. Especially now that new language features are adopted more quickly this leads to projects that may only be compiled for distribution, either using Babel or webpack. Users get syntax errors when they import non-compiled source files. For projects using webpack, the extra difficulty is that, if they're also compiled using Babel, that Babel configuration typically does not compile ESM, since that's left to webpack. AVA's test-file only support for ESM can be hugely misleading. For projects using
We could revisit our recipes with these project types in mind. We could also detect these syntax errors and point users to the relevant documentation.
Note though that if user compiles ESM syntax through a different tool (webpack, or
Perhaps we need to make it easier to opt-out of AVA's default ESM handling. Right now it involves specifying our |
I could be 👍 for this change if we made the breakage worth it:
Maybe this needs to wait for AVA v2, but I would still like to do all of this in one go to reduce churn for users. |
Yes that makes sense. I'd like something similar for TypeScript. I was thinking to have Agreed that this is for after 1.0. |
I've been trying out ava for the first time today, and can confirm that I totally expected it to transpile my imported files in addition to my test files. I'd be fine with it either transpiling all by default, or none by default (with a single option to enable transpilation of all) as long as it's consistent. In the interim, though, this worked perfectly fine: package.json
It might be a good idea to explicitly point out in the readme under Transpiling imported modules that this is the simplest solution (until a change is made for v2). Until I found this issue, it wasn't very clear what I needed to do to fix the problem |
To add my 2p, I never expected ava to transpile my imported files in addition to my test files and documentation told that somewhere. @chrisdothtml you're a rare case :) Personally I found the ava's recipe about bypassing the ESM transpiling a little outdated (talking about Node 8) and a bit hit-and-miss in general. Things are explained but partially. However, I tried out all setups until one worked and settled with that. There's no All my libraries' sources are in ES6 and I use Rollup to transpile to ESM+CJS+UMD and the main reason behind pointing ava towards ESM build rather than CJS is coverage. If transpiled CJS files are used to calculate coverage, all functions that Babel adds are left out and the scores suffer (not to mention CJS code lines differ in Coveralls.io from ESM source, for example). It's ideal when source is ESM and ava runs on ESM build (no transpiling) and coverage is calculated on ESM build. Sadly, since Babel 7 the usual Looking at higher level, Rollup does the transpiling and it references the Babel config in library's root. I've got |
Agreed. Really like ava, but when trying to bypass transpiling (node.js v8+) none of the recipes and answers really worked here, only a "mix-and-match" combo. In the (eventually) working solution test and source files (using es6 import/export) have to have the .mjs extension, esm must be installed as part of the dev-dependencies, no ava config file or .babelrc file is present, the ava config in package.json must require esm, the babel/extensions need to include js and mjs and module compilation needs to be disabled for testOptions/presets:
It would be great to clean up/clarify the documentation and add specific (verified working) sample skeleton test projects for the most important es6 settings/scenarios for the 1.0.0 final release. |
This would be delightful for smaller projects, the only reason I'm still choosing |
As long as it is a |
It does affect the developer experience though and |
Regular user here (with no knowledge of Babel or AVA internals). I like having my builds completely separate from my tests. That's why I have a babelrc that transpiles sources+tests to an out-dir first. Then I run AVA on the out-dir with edit: getting code coverage to work without polluting the transpiled source files is somewhat of an issue with this setup edit2: I decided not to have test coverage because of reasons outlined here https://medium.com/the-node-js-collection/rethinking-javascript-test-coverage-5726fb272949 edit3: c8 looks like a promising alternative to |
Our setup uses Rollup to bundle ECMAScript Modules into ESM and ES5 (for unsupported browsers), and we want our tests to also be written in ESM. |
Please see #2293. |
Currently we transpile ESM syntax in test files. This has frequently caused confusion when users also rely on that syntax in their source files, but are unclear how to configure AVA to transpile sources. #1905 (comment) being the most recent example.
Further, we only transpile syntax, without implementing the specced behavior. Now that
esm
is available that is probably the better choice for most users. However I don't think it's something we should default to.I wonder if it would be clearer to not transpile ESM syntax, as well as remove it from our examples. We can then more clearly communicate the available options for supporting ESM:
esm
We could consider exposing
esm
asava/esm
, since we already have a dependency on it. Similarly we could implement the ESM-to-CJS compilation through ourava/stage-4
plugin. I'm leaning towards making people explicitly installesm
or the@babel/plugin-transform-modules-commonjs
packages.It'll also be easier to support Node.js experimental ESM support, especially now that we support custom file extensions.
What do folks think?
The text was updated successfully, but these errors were encountered: