Meteor 3.3.x and meteortesting:mocha/lmieulet:meteor-coverage

Hi,

I have issue using meteortesting:mocha/lmieulet:meteor-coverage whith meteor@3.3.x when modern: true

With modern: false, it works well but with modern: true, i have the following error (all tests passed but the coverage not):

W20250909-10:14:44.909(2)? (STDERR) Error: Failed to save lcovonly coverage. 500 [object Object]
W20250909-10:14:44.910(2)? (STDERR)     at packages/meteortesting:mocha/server.handleCoverage.js:21:11
W20250909-10:14:44.910(2)? (STDERR)     at Generator.next (<anonymous>)
W20250909-10:14:44.910(2)? (STDERR)     at asyncGeneratorStep (/tmp/meteor-test-run1j4ree.uzqzq/.meteor/local/build/programs/server/packages/meteortesting_mocha.js:280:28)
W20250909-10:14:44.910(2)? (STDERR)     at _next (/tmp/meteor-test-run1j4ree.uzqzq/.meteor/local/build/programs/server/packages/meteortesting_mocha.js:298:17)
W20250909-10:14:44.910(2)? (STDERR)     at processTicksAndRejections (node:internal/process/task_queues:105:5)

The command line is the following :

MONGO_URL='' BABEL_ENV=test TEST_CLIENT=0 NO_HMR=1 COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_APP_FOLDER=$PWD/ meteor test --once --driver-package meteortesting:mocha

Thanks.

I’d appreciate it if you could prepare a minimal repo for this. Matching your config is tricky. Having one would save a lot of time so I can focus on the fix.

For SWC, we may need to use it with kwonoj/swc-plugin-coverage-instrument. Having an example repository will allow me to play with it and provide a skeleton for everyone.

Thanks. Here a minimal repo :

meteor run then meteor npm run test and you get the error.

looking at packages/meteortesting:mocha/server.handleCoverage.js:21:11 error :

I20250910-16:46:09.190(2)?     url: 'http://localhost:3000/coverage/export/lcovonly',
I20250910-16:46:09.190(2)?     status: 500,
I20250910-16:46:09.190(2)?     statusText: 'Internal Server Error',
I20250910-16:46:09.190(2)?     headers: Headers { [Symbol(map)]: [Object: null prototype] },
I20250910-16:46:09.190(2)?     counter: 0
I20250910-16:46:09.191(2)?   }
I20250910-16:46:09.191(2)? }
I20250910-16:46:09.191(2)? data: { type: 'No coverage to export' }
I20250910-16:46:09.191(2)? url: /coverage/export/lcovonly
I20250910-16:46:09.191(2)? message: Failed to save lcovonly coverage.

it seems there is no more instrumentation made by babel-plugin-istanbul

Yeah, because with "modern": true, we use SWC as the transpiler. The reason way I was suggesting to incorporate kwonoj/swc-plugin-coverage-instrument. if you can play with it, go ahead and let us know what you get. I will when I have free time.

It was my next step :wink:

So, I removed babel-plugin-istanbul and installed GitHub - kwonoj/swc-plugin-coverage-instrument: istanbuljs compatible SWC coverage instrumentation plugin.
I configured it in swc.config.js as documented.

And now, everything works well. Coverage is back.

Thanks.

1 Like

Aha, great! Could you push the changes?

They can serve as a good example for others adopting modern SWC and have test coverage. Maybe we could also open a PR on lmieulet:meteor-coverage to update the docs and mention this step and point to your changes for those using Meteor modern build stack.

Sure.

in package.json, set modern: true

meteor npm remove -D babel-plugin-istanbul
meteor npm i -D swc-plugin-coverage-instrument

in the file swc.config.js:

module.exports = {
  jsc: {
    baseUrl: './',
    experimental: {
      plugins: [
        [
          'swc-plugin-coverage-instrument',
          {
            unstableExclude: [
              '**/node_modules/**',
              '**/.meteor/**',
              '**/packages/**',
              '**/tests/**',
            ],
          },
        ],
      ],
    },
  },
};

run your tests and you should have your coverage. At least, this setup works for me.

2 Likes