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.

1 Like

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.

1 Like

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.

3 Likes

I found only a specific version of swc-plugin-coverage-instrument works:

swc-plugin-coverage-instrument@0.0.28

not:

swc-plugin-coverage-instrument@0.0.26
or
swc-plugin-coverage-instrument@0.0.32 (the latest)

At least those two versions crash!

Which rspack and Meteor version have you ?

Meteor 3.3.2 with modern=true

Unless I am mistaken, Meteor 3.3.2 uses swc 1.12.14 so swc_core is 32.0.2.

sw_core dependency for swc-plugin-coverage-instrument@0.0.32 is 47.0.3 So it will not work.

Correct @nachocodoner ?

Yes, you’re right.

Meteor 3.3.2 is fixed to use @swc/core 1.12.14 through a custom NPM package.

With the latest Meteor 3.4-rc.1 I bumped the internal Meteor SWC version to 1.15.3, which uses swc_core v48.0.2, likely compatible with swc-plugin-coverage-instrument@0.0.32.

Upgrading to Meteor 3.4-rc.1 won’t force you to use the Rspack integration, so you can update and still use the Meteor bundler alone. Besides this, I want to mention that adopting Rspack for your app code will make your setup depend on Rspack, which updates SWC on its own schedule.

1 Like

Could any of you help me out?

I made the changes mentioned by @harry73 about swc, however, I’m getting a 500 error. I’m not sure how to proceed

 Export code coverage
 - Out html
 [coverage] export coverage using the following format [ html ] options [ {
   path: '/home/ferjep/yourdnafamily/octopussy/.coverage',
   verbose: true
 } ]
 Write asset: ./base.css
 Write asset: ./block-navigation.js
 Write asset: ./sort-arrow-sprite.png
 Write asset: ./sorter.js
 Write asset: ./prettify.css
 Write asset: ./prettify.js
 (STDERR) Error: Failed to save html report. 500 [object Object]
 (STDERR)     at request (packages/meteortesting:mocha/server.handleCoverage.js:21:11)
 (STDERR)     at processTicksAndRejections (node:internal/process/task_queues:105:5)
 [coverage] export coverage using the following format [ http ] options [ {
   path: '/home/ferjep/yourdnafamily/octopussy/.coverage',
   verbose: true,
   filepath: undefined
 } ]

This is how I’m running it

COVERAGE=1 COVERAGE_VERBOSE=1 COVERAGE_APP_FOLDER=$PWD/ TEST_WATCH=1 COVERAGE_OUT_HTML=1 meteor test --driver-package meteortesting:mocha --settings settings-development.json

package.json (meteor only)

  "meteor": {
    "modern": {
      "transpiler": {
        "verbose": false
      }
    },
    "mainModule": {
      "client": "client/main.js",
      "server": "server/main.js"
    }
  },

Hi,

Which Meteor and swc-plugin-coverage-instrument version do you run?

Meteor 3.3.2 and swc-plugin-coverage-instrument 0.0.32

try with swc-plugin-coverage-instrument 0.0.28

It gets worse I think. I get code errors now

error on boot.js /tmp/meteor-test-run1q6cxtm.302vl/.meteor/local/build/programs/server/app/app.js:107086
const ANDME_FORMAT = (cov_16790224454079739546().s[4]++, await getFormat(‘andme’, ‘v4’, undefined));
^^^^^^^^^

SyntaxError: Unexpected identifier ‘getFormat’
at new Script (node:vm:117:7)
at createScript (node:vm:269:10)
at Object.runInThisContext (node:vm:317:10)
at /tools/static-assets/server/boot.js:414:32
at /tools/static-assets/server/boot.js:502:11
at Function.run (/tmp/meteor-test-run1q6cxtm.302vl/.meteor/local/build/programs/server/tools/tool-env/profile.ts:651:14)
at startServerProcess (/tools/static-assets/server/boot.js:501:17)
at Object. (/tools/static-assets/server/boot.js:506:2)
at Object. (/tools/static-assets/server/boot.js:510:4)
at Module. (node:internal/modules/cjs/loader:1688:14)
at Module.Mp._compile (/tools/static-assets/server/runtime.js:91:21)
at Object.Module._extensions…js (/tools/static-assets/server/runtime.js:125:21)
at Module. (node:internal/modules/cjs/loader:1423:32)
at Module.Mp.load (/tools/static-assets/server/runtime.js:35:31)
at Function._load (node:internal/modules/cjs/loader:1246:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
/tmp/meteor-test-run1q6cxtm.302vl/.meteor/local/build/programs/server/app/app.js:107086

@nachocodoner Could you help me somehow?

I have 2 projects with kind of the same set up and have the same 500 error

Have you tried using the Meteor 3.4-rc.1 version I mentioned above, which bumps SWC to the latest and should include a swc_core version compatible with swc-plugin-coverage-instrument@0.0.32?

If not, and to help you further, I’d need a bit more to reproduce your issue. Could you provide a minimal reproduction repository where I can quickly see the problem and explore a fix?

1 Like