Recently I found myself having to bundle the tests to overcome all the hurdles caused by combinations of AVA, TypeScript and type: "module" (https://github.com/vadimdemedes/dom-chef/pull/68 and https://github.com/sindresorhus/refined-github/pull/3206), so having AVA support some kind of build step might be helpful.
{
"ava": {
"build": "rollup --config --out tests tests/_source/*"
}
}
rollup && avaava without having to run an npm script firstava --watch would trigger the build as wellAdditionally, it could automatically handle the creation of a temporary build folder
{
"ava": {
// Notice there's no "source" folder anymore because AVA would treat $TEMP as the test folder
"build": "rollup --config --out $TEMP tests/*"
}
}
The infrastructure we use for @ava/babel and @ava/typescript could work for this.
How would you select a test file from inside the bundle though?
If you precompile AVA can load ESM test files though. https://github.com/avajs/ava/issues/2347#issuecomment-698499005 shows how you could do it on the fly with ts-node as well (I've been meaning to get that added to the docs).
FWIW in my TypeScript projects, running a separate tsc in watch mode works well enough with AVA's watch mode and @ava/typescript.
How would you select a test file from inside the bundle though?
I never tried. I suppose if the bundle is set up to have multiple outputs AVA would still see each test file.
#2347 (comment) shows how you could do it on the fly with
ts-nodeas well
I'll try replacing https://github.com/sindresorhus/refined-github/pull/3206 with that solution perhaps, but with all those experimental flags it looks like a time bomb :(
in my TypeScript projects, running a separate
tscin watch mode
Can you point me to one such example? I'd like to see how you're configuring the built folder
How would you select a test file from inside the bundle though?
I never tried. I suppose if the bundle is set up to have multiple outputs AVA would still see each test file.
Test file selection is driven by the file system. What the TypeScript provider does is provide a way to map that to a _different_ file at runtime. Presumably we could select a bundle entrypoint or something like that.
with all those experimental flags it looks like a time bomb :(
I think from AVA's side it'll be OK — you're really dependent on the behavior in Node.js.
in my TypeScript projects, running a separate
tscin watch modeCan you point me to one such example? I'd like to see how you're configuring the built folder
Have a look at https://github.com/avajs/cooperate.