ava icon indicating copy to clipboard operation
ava copied to clipboard

Make dependency tracking work with ESM imports

Open novemberborn opened this issue 5 years ago • 2 comments

AVA's watch mode tracks which source files are loaded by which test files. This way it knows which test files to re-run. This is based on instrumenting the require code in Node.js. We won't be able to track ESM dependencies using this method.

We'll have to find a different way of resolving dependencies. Perhaps by analyzing the imports of test files. We'll have to allow our Babel and TypeScript providers to participate in this.

I think maybe Jest's haste map does something similar, but it's not documented.

novemberborn avatar Feb 02 '20 13:02 novemberborn

feel free to ignore me, --I'd like to mention this package I released and use https://www.npmjs.com/package/resolvewithplus

perhaps you could use this package or something like it. It was originally written for CJS modules but successfully resolves MJS modules as well.

// returns the full path to the 'main' koa file following CJS rules
resolvewithplus('koa', '/Users/bumble/resolvewith/test/', { esm : true });

the single-file used by the package https://github.com/iambumblehead/resolvewithplus/blob/master/src/resolvewithplus.js

iambumblehead avatar Jul 27 '21 19:07 iambumblehead

I'm not sure if this is related, but it seems the ignoredByWatcher option does not prevent the watcher from looping. I am able to reproduce it minimally in this repo: https://github.com/rxbugs/ava-watch-ignore

Just run npm run test:watch

See https://github.com/avajs/ava/issues/2957

razor-x avatar Jan 28 '22 21:01 razor-x

Looking to tackle with #3123.

novemberborn avatar Oct 23 '22 16:10 novemberborn

Done in https://github.com/avajs/ava/pull/3218.

novemberborn avatar Jul 03 '23 14:07 novemberborn