Esm: Code coverage no longer working: nyc + Mocha + @std/esm

Created on 3 Oct 2017  路  10Comments  路  Source: standard-things/esm

With 0.5.X I was able to run my tests as:

nyc --require @std/esm mocha ./test/**/*

This would enable me to write source code and tests in ESM with code coverage.

After upgrading I can get the tests to run if I move the require into mocha:

nyc mocha --require @std/esm ./test/**/*

My guess this is because you aren't messing with the system require method like before. Is there any way to get this working or is code coverage a lost cause?

bug

Most helpful comment

v0.11.3 is released :tada:

All 10 comments

Hi @gauntface!

It depends on how nyc is requiring things. The @std/esm loader detects its use in node params and will enable a more aggressive hook if that's the case. Can you create a simple repro repo for me to look at.

Will try and put together a small repro later tonight.

If you are curious, our test project is here: https://github.com/GoogleChrome/workbox/tree/v3-std-esm-bump (tests are run via npm run test -- ./test/**/node/**/*.mjs)

I have been trying to understand the interaction between std/esm and nyc for the last few days myself because, no matter what I try, I couldn't get it to work. The one thing that stuck out to me is that nyc resets require.extensions, see this line, since that seems like the wrong thing to do in every case I can come up with.

Hi @grimmr!

It depends on how you've hooked @std/esm.
If you use the programmatic API it won't hook the traditional require.extensions:

index.js

require = require("@std/esm")(module)
require("./main.mjs")

Okay @gauntface!

I should have a patch for this soon. You'll be able to continue to use:

nyc --require @std/esm mocha ./test/**/*

@gauntface


When I upgrade the v3 branch of Workbox to the WIP @std/esm of our master branch I get these test fails

and

Any ideas?

@gauntface

NM I figured it out. Follow-up patching soon 馃構

Update:
Fixed it https://github.com/standard-things/esm/commit/1203a372b00f3d3b6cb2a0df9d8901186d84a3c4!
Even tested it with this workaround comment removed and 馃挴 workbox tests pass!

v0.11.3 is released :tada:

Ha ha, thank you @jdalton looks awesome.

A batch of our tests are using proxyquire and seems to be our new problem area. Will dig into how we can get off of it.

Was this page helpful?
0 / 5 - 0 ratings