Investigate getting test specs to be able to use ESM import
mattcollier opened this issue · comments
I spent some time looking into this and tried some things at the test suite level for a bedrock-module.
https://stackoverflow.com/a/60522428
According to that, we might just be able to call mocha -r esm
here
That method has been working for standalone testing. Maybe a related issue is getting coverage working with nyc, mocha, and esm code. nyc also has a way to require esm, but I've had issues with it sometimes working, sometimes not, in the same repo, and no idea what changed. There may be some general pattern that helps with mocha and nyc.
Also experiencing issues with coverage with nyc not working with bedrock-foo repos that are using esm module. It works sometimes and most of the times it doesn't work, and there are no errors.
One of the examples would be https://github.com/digitalbazaar/bedrock-meter. When running the coverage script, it gives the following summary and in the report we can only see the index.js file.
Statements : 100% ( 2/2 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 2/2 )
Tried adding the nyc --require esm
flag to the coverage script in bedrock-meter test package.json but that didn't work either and gave the same result as above.
Some of the repos that might be impacted by this are:
- https://github.com/digitalbazaar/bedrock-app-identity
- https://github.com/digitalbazaar/bedrock-config-yaml
- https://github.com/digitalbazaar/bedrock-did-io
- https://github.com/digitalbazaar/bedrock-health
- https://github.com/digitalbazaar/bedrock-jsonld-document-loader
- https://github.com/digitalbazaar/bedrock-meter-http
I found this issue which gave me the idea that c8
might be a drop-in replacement for nyc
Which appears to be the case:
This PR shows the necessary mods:
digitalbazaar/bedrock-meter#4
https://app.codecov.io/gh/digitalbazaar/bedrock-meter/commits?page=1
This has been fixed, we can use ESM import now, closing.