-
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
Add configuration to specify how extensions should be loaded #2345
Comments
This is now available to be worked on. |
How would you handle this? Would it break something if AVA just looked at the Today I played around with the Experimental Loaders Hooks and somehow I managed to get everything working (or at least the basics: The only thing that appears to be blocking is this issue because |
The way I understand it, the
Nice! I imagine you could set those up in a module you can then load using AVA's |
For what I could test, yes, the The problem is that when you go with one you're locked in with that: in my Having the possibility to define how to load tests with different extensions would certainly be nice, but I'm not really sure how useful that would be. Does it even make sense to have Personally, I'd prefer something that Just Works™ out of the box, so following the If I'd really want to have access to // @ava: load-as-commonjs
const test = require('ava')
Yes and no, it is enabled through Another problem I had is that my loader produces inline sourcemaps, enabling |
But Node.js only does that for I'd like AVA core to not do anything beyond what Node.js does by default. So it should recognize the
Right — AVA won't enable experimental options. But that's what the
Yes. There may be one or two open already around removing our source map magic. |
I understand what you're saying, but it does it that way because it's the only type of file it knows how to run beyond If you run That's why I'm saying that AVA should recognize the For Node everything still runs as a I also understand that loading everything as a module when How should we proceed? The more future-proof way would be to For now we could continue reading the {
"ava": {
"extensions": {
".ts": "module",
".re": "commonjs"
}
}
} wouldn't be that bad, we could keep the array and have its children as objects, like Sorry for these extra-long posts, I kinda like writing 🤣 |
For my understanding, would I think loaders are too experimental to influence AVA's defaults. If they stabilize and the default behavior is more clear (and breaking) we could enable that as an experimental AVA feature until we ship the next major release. Your sample configuration looks about right. I'd prefer the object form. |
I did some more tests, I've removed To answer your question: if you don't have
Nice! I'll give it a go then. Do you have any advice before I start? 🙂 |
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).
Is this the case if the loader doesn't specify support for the All of this is still experimental and subject to change, but I guess it'd be good to understand what's going on here, at this point. |
So, I did more testing, when Anyway, with #2540 if you use a loader and request There's a problem tho, if the loader says that it can manage file://[...]/node_modules/ava/lib/worker/subprocess.js:2
const {pathToFileURL} = require("url"); That seems to be caused by |
Thanks for the continued research! I think as long as you can configure AVA to import or require a particular extension then we can use these (experimental) loaders to the fullest.
Some best practices will develop around this. If you're going to co-opt |
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).
Fixes #2345. Co-authored-by: Mark Wubben <mark@novemberborn.net>
Fixes avajs#2345. Co-authored-by: Mark Wubben <mark@novemberborn.net>
We need a way for AVA to know whether to load a particular test file (given its extension) as
commonjs
ormodule
, similar to the"type"
field inpackage.json
.It must not be possible to change how
cjs
andmjs
extensions are loaded. And I have a strong suspicion (but I have not confirmed this) that it's impossible to override the"type"
field (which applies tojs
extensions).Once configured as
module
, we then need toimport()
these test files. This is blocked by #2344.The text was updated successfully, but these errors were encountered: