-
Notifications
You must be signed in to change notification settings - Fork 147
Running mocha programmatically #89
Comments
I'll fix that for the next release. |
So, 0.8.0 fixed the issue using the mocha wrapper, but I am still having issues running mocha programmatically with a Node script. I am importing mocha using |
Programmatic usage would look something like: require = require("@std/esm")(module)
require("./test-bootstrap.mjs") The |
I have the following setup:
That way my dependent projects (which also have std/esm with the same options) can do I did notice with 0.8.0 that my dependent projects get a completely unrelated error now (that I could break off into a separate issue) when running
Where project is the dependency of the project running the bin script. |
@eliw00d Can you create a test repo for me to look at? |
I'm actually getting this error trying to use esm with ava. I can update my repo to show you. |
@mAAdhaTTah Thanks! |
For my example: https://github.com/valtech-nyc/brookjs-cli Git clone, npm install, and on line 41, change
repeated 5 times (once for each test file). |
The inclusion of the JS code at the top seems significant... |
@eliw00d The |
@jdalton I updated the repo, but as long as you npm/yarn installed in both dependency and dependent the my-scripts should work. Regardless, sounds like this might be an issue I should bring up with Mocha, then. Thanks! |
@mAAdhaTTah |
@jdalton Were you able to get my-scripts to work? That should show the error I was running into with 0.8.0 that was not present with 0.7.1. |
@mAAdhaTTah I found the source of the error (it's likely related to the one @eliw00d is seeing). After I resolve that though |
So that means it simply wouldn't do anything when run by ava/mocha? I'm not really sure of the underlying mechanism here. |
@mAAdhaTTah With the changes to the API in v0.6.0 the loader no longer hooks into the universal module loader mechanism of Node. So folks need to opt-in with the API Mocha does a nifty trick where it takes its |
Sounds good. I'll open an issue there. Thanks! |
If mocha is run like this:
mocha -r @std/esm --recursive ./src/test
It results in
Unexpected token import
errors.However, if mocha is run like this:
node -r @std/esm ./node_modules/mocha/bin/_mocha --recursive ./src/test
It works as expected, since _mocha is a script and mocha is a wrapper.
So, if I wanted to run mocha programmatically, like this:
./scripts/test.js
And have an npm script like this:
./package.json
It results in the same
Unexpected token import
errors as the mocha wrapper.Any thoughts?
The text was updated successfully, but these errors were encountered: