marvinhagemeister / karma-esbuild

Preprocessor based on esbuild for the karma test runner
MIT License
21 stars 10 forks source link

Unwatch files excluded via Karma `config.exclude` #42

Closed theinterned closed 2 years ago

theinterned commented 2 years ago

This is an alternate approach to https://github.com/marvinhagemeister/karma-esbuild/pull/41

What am I trying to accomplish?

This PR adjusts the paths watched via chokidar to respect the configured excludes via karma config.exclude directive.

Previously, chokidar was watching the entire base path. It may be desirable to avoid watching certain files or directories for whatever reason (in my case certain directories were causing errors).

What approach did I take?

I added a call to watcher.unwatch(config.exclude) immediately after starting the chokidar watcher.

theinterned commented 2 years ago

Note: I think this approach warrants tests and I am happy to add some but I wanted to get feedback on the approach first.

jridgewell commented 2 years ago

/cc @marvinhagemeister

theinterned commented 2 years ago

~@jridgewell and @marvinhagemeister I'm a bit stumped on how to test this. I have a WIP test https://github.com/marvinhagemeister/karma-esbuild/pull/42/commits/2007109635434b9feec627e5f7b09162383a8ba7 but I am having trouble figuring out how to assert that the tests are not triggered by a change to an excluded file. Any ideas?~

I figured it out after poking through the pentf docs! https://github.com/marvinhagemeister/karma-esbuild/pull/42/commits/6b180df3e7bdc105c454007f5580c68b7297506a

@jridgewell and @marvinhagemeister let me know if this test is good for you. I'm a bit concerned about the wait required in using asertAlways.

theinterned commented 2 years ago

Thanks @marvinhagemeister let me know if there's anything I can do to help prep a release with this fix in it!

I've prepped a PR to bump the minor version 🤞 https://github.com/marvinhagemeister/karma-esbuild/pull/43