Using TS / ava 4 / ESM; entire app seems to be getting compiled separately for each test, what am I doing wrong? #2908
Replies: 3 comments 2 replies
-
This is the culprit: Every test file runs in a separate worker thread, so modules have to be loaded and compiled in each thread. It'll be much better to precompile using |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I was able to get this working by changing a few things. I added "scripts": {
"test": "tsc && tsc-alias && ava"
},
"devDependencies": {
"tsc-alias": "^1.4.2"
},
"ava": {
"timeout": "30s",
"files": ["dist/test/**/*.test.js"]
} Not ideal, but at least it works and doesn't try to compile the app 20 times. |
Beta Was this translation helpful? Give feedback.
-
I'm converting a large monorepo from Jest (tests have been broken for about six months) to Ava 4 rc1. For the most part it has been relatively smooth sailing once I got things working. Overall I'm fairly happy with ava and it seems to work great, but as I converted more and more tests over I noticed the compilation time was growing pretty excessively. The application that I'm converting takes about 6-7 seconds to build using rollup on my local dev desktop (Intel Core i9-10900 with 10 cores (20 w/ HT) and 32gb RAM). When I execute individual tests I'm seeing pretty similar compile times (using esbuild as noted below in the config).
When I run all tests together (currently 16 separate test files) I'm seeing 24 instances of esbuild spawn that are (I'm assuming) compiling my application 24 separate times before the tests are executed.
(Note: the CPU percentage displayed in the 3rd column is representative of overall CPU usage I believe, a process using 100% of a single CPU core is usually represented as using "5.00" percent of the CPU. I'm not certain why some of these are using more than that, but my overall system CPU usage is at 100% for the duration of the test execution)
This takes a good 45-60 seconds at this point and every file I add increases this by 5-6 seconds. I'm assuming that I'm doing something wrong, but honestly can't figure out what. I looked in to the
@ava/typescript
plugin but could not get it working - although I have TypeScript working without using that plugin so wasn't sure if it was needed.I've considered refactoring the tests to use or call the compiled JS output of my application but haven't gone that route since it would be a pretty significant refactor. Currently each test file imports the
main()
function of the application and spawns its own instance on a random port (express based API app).Aside from the issue I'm mentioning (which I've worked around by adding the
timeout: 5m
config option) ava is working well and doing what I expect. What can I add / change or configure to reduce the amount of compilation that is needed when running tests?One last thing to note, I have tried to mess with the
concurrency
andworkerThreads
options. Neither seems to really solve the problem: running as child processes doesn't result in much difference besides 24 node.exe instances spawning each with an esbuild.exe child. Changing the concurrency to 1, 2, 4 or 10 didn't do much besides reduce the number of esbuild instances spawned (as expected, of course). No matter the setting the tests would take about the same amount of time (+/- 5 seconds or so) to execute to completion.Versions being used:
ava configuration from package.json:
Here is an example test file (login.test.ts).
@main
and@util
are imports from the main application being tested (aliased using TS paths config). I've excluded a few tests for brevity:Finally, here are the tsconfig(s) used (the first one extends the second):
Beta Was this translation helpful? Give feedback.
All reactions