standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

esm v3.2.10 breaks nyc + ava #741

Closed sergiitk closed 5 years ago

sergiitk commented 5 years ago

After updating esm from 3.2.0 to 3.2.14 in my project (sergiitk/pagerbeauty#94) nyc stopped reporting code coverage. I run my tests with nyc + ava; ava requires esm. Here's my setup:

Test command:

    "test:unit:coverage": "NODE_ENV=test nyc --all -s ava test/unit",

nyc config:

  "extension": [
    ".jsx",
    ".mjs"
  ]

Ava config:

  require: ['esm'],
  babel: false,
  compileEnhancements: false,
  extensions: [
    'js',
    'mjs',
  ],

I was able to pinpoint excatly what release introduced the regression: it's 3.2.10. The changelog for this release looks unrelated. I used yarn resolution to dowgrade to 3.2.9 and nyc works as expected.

Here's how nyc report with esm >3.2.10 looks like:

Here's the same code with esm pinned to 3.2.9 works as expected:

jdalton commented 5 years ago

Hi @sergiitk!

From the https://github.com/standard-things/esm/compare/3.2.9...3.2.10 range I see https://github.com/standard-things/esm/commit/e5a3dcdd11e7460afeaa297283b0d72fe02f20b6. I noticed the files you're wanting code-coverage for are .mjs. Under the esm rules:

:lock: .mjs files are limited to basic functionality without support for esm options.

This is because in the current and next experimental phase of modules in Node the .mjs module will not support features like nyc. The easy way around this is to simply use .js for ESM code.

sergiitk commented 5 years ago

Thank you for the explanation @jdalton. And my apologies for the invalid report.

jdalton commented 5 years ago

@sergiitk No worries! Thank you for reporting the issue (don't worry about the issue designation).

sergiitk commented 5 years ago

@jdalton FYI I replaced --experimental-modules with -r esm, renamed .mjs -> .js. Latest esm 3.2.14 works perfect with nyc + ava! Thanks a lot!

Ref sergiitk/pagerbeauty#96. Also for those who interested, this is good reads confirming what @jdalton said: http://2ality.com/2018/12/nodejs-esm-phases.html https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md