Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Watch A Directory And Run Mocha JS With ES Modules When Files Change

This is how I'm running Mochajs in watch mode with ES Modules:

Code

mocha --watch --parallel

Adding `--parallel` is based off this comment to a GitHub issue about `--watch` not working by itself with ES Modules.

If you try to run `mocha --watch` without `--parallel` it produces errors like:

Code

Error [ERR_REQUIRE_ESM]: require() of ES Module 
/file/path/file.mjs not supported.
Instead change the require of /file/path/file.mjs 
to a dynamic import() which is available in all 
CommonJS modules.

(I think I've done the dynamic import stuff before in other projects, but haven't tried it with Mocha yet)