The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

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

TODO: Pull subtitle into page object

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

code_start_default_section code_end_default_section

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

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

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

-- p

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

-- code/
-- bash

mocha --watch --parallel

-- /code

-- p

Adding `--parallel` is based off <<link|this comment|https://github.com/mochajs/mocha/issues/4374#issuecomment-666620281>> to a GitHub issue about `--watch` not working by itself with ES Modules.

-- p

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

-- code/
-- bash

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.

-- /code

-- p

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


-- categories
-- JavaScript
-- Test Driven Development
-- Mocha

-- metadata
-- date: 2022-05-14 13:11:10
-- id: 29ag2did
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws