Skip to content
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

Handle compilation/bundle step #2589

Closed
fregante opened this issue Sep 29, 2020 · 4 comments
Closed

Handle compilation/bundle step #2589

fregante opened this issue Sep 29, 2020 · 4 comments
Labels

Comments

@fregante
Copy link

Recently I found myself having to bundle the tests to overcome all the hurdles caused by combinations of AVA, TypeScript and type: "module" (vadimdemedes/dom-chef#68 and refined-github/refined-github#3206), so having AVA support some kind of build step might be helpful.

{
  "ava": {
    "build": "rollup --config --out tests tests/_source/*"
  }
}

Advantages over rollup && ava

  • running straight ava without having to run an npm script first
  • running ava --watch would trigger the build as well

Additionally, 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/*"
  }
}

Additional advantages

  • not having to figure out and manually configure the temporary middle folder for git, AVA, XO
@novemberborn
Copy link
Member

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. #2347 (comment) 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.

@fregante
Copy link
Author

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-node as well

I'll try replacing refined-github/refined-github#3206 with that solution perhaps, but with all those experimental flags it looks like a time bomb :(

in my TypeScript projects, running a separate tsc in watch mode

Can you point me to one such example? I'd like to see how you're configuring the built folder

@novemberborn
Copy link
Member

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 tsc in watch mode

Can 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.

@fregante
Copy link
Author

fregante commented Feb 3, 2023

Closing because those issues have since been resolved (refined-github/refined-github#4002 and vadimdemedes/dom-chef#86) and I started using Vitest where I want to avoid ESM issues

@fregante fregante closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants