nodejs/modules

Feature: Code coverage/instrumentation

GeoffreyBooth opened this issue · 4 comments

  • I want to write a code coverage tool that gathers great data about both ESM and CommonJS imports.
  • My code coverage tool is able to retrieve data about ESM modules on par with what is available about CommonJS modules.

Use cases 3, 11.

As a maintainer of NYC I'd like to ensure that we can provide coverage for ESM modules. For CJS modules by default we hook require.extensions, we also have the ability to hook vm.runInThisContext and vm.runInContext. In all of these methods we add instrumentat (coverage counters) to the code before passing it to the original method.

We need a similar ability to support native ESM. Currently to test ESM with nyc can only be done by having babel transpile to commonjs or by using --require esm.

Would it be possible for nyc to use the native V8 coverage info for ESM files? That way it may get away with not transforming the code. I assume the version of node that ships ESM would also have proper support for those APIs already.

c8 uses native V8 coverage. I just gave this a try with c8 node --experimental-modules ./bin.mjs, I did not get any coverage (tested with node 10.15.3 and 11.13.0).

In either case c8 is a different project from nyc. Native V8 coverage is very promising but IMO it's not ready to replace nyc.

I think even if nyc could be ported to use v8 coverage there are other tools (transpilers, APM,...) which have the same/similar need.