-
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
Experimentally configure module formats for test files #2540
Conversation
Thanks for the PR! It may take me a few more days before I can have a good look at this, sorry. |
@macarie I wasn't online much this weekend so I haven't been able to look at this yet, sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far @macarie!
You didn't mention it, but we still need to use this configuration to load the test file right?
I think we should make this an opt-in experimental feature for now, but we can deal with that when we're ready to ship this.
I'm not sure I understand what you are asking, what do you mean? |
Never mind, I'd forgotten how these module types are used. |
I did the changes you proposed, now it only accepts I don't really like the error messages, something else that might work?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good @macarie! I need to play with this regarding the error messages.
Regarding the tests, would you be up for writing integration-style tests? See https://github.com/avajs/ava/tree/master/test — it's all a bit fresh but the idea is to set up a fixture project with (in this case) the configuration you want to test, and then running AVA in that project and checking the results.
Fixes avajs#2345 by adding an object form for the `"extensions"` configuration. This implementation: 1. if `"extensions"` is not defined uses the default module configuration for `mjs`, `cjs`, and `js` 2. generates the module types from the array form of the `extensions` configuration keeping the default module type for `mjs`, `cjs`, and `js` if they're defined and uses `"commonjs"` for everything else, thus maintaining backwords compatibility. 3. generates the module types from the object form of the `extensions` configuration and prevents changing the module type for `mjs`, `cjs`, and `js` extensions (for `js` the `"type"` field cannot be overridden).
…n types for everything else
01d02ae
to
5d953fe
Compare
@novemberborn I've tried doing some tests. Node v10 fails because I've used an The I wouldn't try setting anything as As always, any feedback is welcome 🙂 |
Just on this, have a look at this branch: https://github.com/avajs/ava/blob/shared-worker-plugins/ava.config.js It's OK to skip these tests in Node.js 10. |
@macarie cool! I'm about to push some tweaks. My apologies for the refactoring, hopefully you agree it's an improvement and not just me being silly 😄 You took a good stab at the tests. I think it's better to use separate test files, and then use that to exclude ESM tests from Node.js 10. Snapshots should be used with caution, it's easy to think you're testing something even though you aren't. I've also renamed some files. I've made the feature experimental for now, using the Your feedback on my changes aside, I think what's left here now is to update the documentation? |
Use a more explicit switch statement to clarify the logic.
* Use separate test files for better grouping * Prefer assertions over snapshots * But do snapshot error messages * Stop AVA from running tests that require ESM on Node.js 10 * Avoid the esm package
Nice work @novemberborn!
Yeah, everything's more straightforward now and a bit easier to follow, more Go-ish I'd say 😝
Not sure about it. I think it gives more the idea that you can configure what files to load and not how to load them 🤔
Yes! Do you want to write it or should I give it a shot? |
Please don't tell my coworkers 😉
How about
I'd like to follow the |
It'd be great if you could give it a shot first. |
This sounds good to me.
Sorry, I was talking about line 50, the default for "unrecognized" extensions, not the
Sure 🙂 |
I think |
Sorry for the delay, it's been a busy few weeks. Anyway... I've updated the documentation, I wasn't sure where to write about the new feature tho, so I chose I've also changed |
No I think that's great. I'm about to push some changes to make it a little clearer what this is for. Let me know what you think.
👍 |
@macarie I believe this is ready now? |
@novemberborn other than the small change I proposed (feel free to ignore it) I think that this is ready, yes 😄 |
Co-authored-by: Raul <raul@macarie.me>
🎊 thanks @macarie! I'll try and ship a release later today. |
3.12 is now available. |
Should resolve #2345 by adding an object form for the
"extensions"
configuration.I did some tests and it doesn't work, if
"type"
is"module"
you can'trequire()
ajs
file from that package, nor the opposite, if you try Node gets angry:require() of [...]/index.test.js from [...]/node_modules/ava/lib/worker/subprocess.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
I've tried to keep the edits as small and self-contained as possibile. I'm not sure if what I did and how I did it is the right approach, but it seems to be working.
This is how AVA behaves now:
"extensions"
is not defined the default module configuration formjs
,cjs
, andjs
is used."extensions"
is an array the module types are generated automatically for each extension, keeping the default type formjs
,cjs
, andjs
, only if they're defined, and using"commonjs"
for everything else, thus maintaining backwards compatibility."extensions"
is an object the module types are read from the configuration, but the type formjs
,cjs
, andjs
is locked and can only be set to their default type, the default type forjs
is based on the"type"
field because it cannot be overridden.Now, in
package.json
(or in a config file), it's possible to have:If you try to change
js
to"module"
(notice the missing"type"
) it'll throw an error:✖ .js files can only be configured as ’commonjs’ when the nearest parent package.json does not contain "type": "module", found ’module’ instead.
For
cjs
andmjs
files:✖ .cjs files can only be configured as ’commonjs’, found ’module’ instead.
Local tests are passing, not with Node
v14.5.0
tho. I don't know why they fail (something with the reporters I guess), but they also fail onmaster
, so I'm not sure what's going on.I didn't write tests yet, and no documentation either, if what I did looks good I'll do those next 👌🏼