The MOCHA_GREP env var isn't working with this Meteor 3.4 + rspack setup

Claude Code is trying to run selected tests only. Seems the Meteor implementation of rspack isn’t allowing grep, if it does please advise on how to achieve this, thanks!

FYI - using Mocha for testing.

UPDATE:

The background research on the Meteor rspack grep issue completed. Here's the key finding:

  MOCHA_GREP + Rspack

  MOCHA_GREP is not a Meteor feature — it's from the meteortesting:mocha Atmosphere package. The Meteor 3.4 docs don't mention it at all. The docs do acknowledge that rspack
  testing flows are still being stabilized in the 3.4.x release cycle (Phase 5 roadmap).

  The likely cause: rspack takes over bundling and the process.env.MOCHA_GREP reference in meteortesting:mocha's runtimeArgs.js is either being replaced at build time with an
  empty value, or the env var isn't propagating to the rspack runtime context.

  Workarounds:
  1. meteor test-packages --filter "name" — Meteor's built-in filtering (but only for package tests, not app tests)
  2. Remove rspack temporarily for test runs: meteor remove rspack to fall back to the traditional bundler where MOCHA_GREP works
  3. Wait for Meteor 3.4.x to stabilize test flows with rspack

  For now, running the full suite and filtering output (as we did) is the pragmatic approach.

FYI - I have 1,300 tests for this repo so this is a big downside that I didn’t know before switching to rspack. Might be that this is a known problem/shortcoming and I just didn’t read about it but IMO it’s something that hopefully is fixed soon. Hope the Meteor team agrees.

@a4xrbj1
Hey! I think the issue is that with rspack, the process.env.MOCHA_GREP might not propagate correctly to the test runner :thinking:

Have you tried passing it via Meteor settings instead? Something like:

// settings-test.json
{
  "public": {
    "mochaRuntimeArgs": {
      "mochaOptions": {
        "grep": "your pattern here"
      }
    }
  }
}

Then:

meteor test --driver-package meteortesting:mocha --settings settings-test.json

Under the hood, meteortesting:mocha reads MOCHA_GREP on the server and bridges it to the client via Meteor.settings.public.mochaRuntimeArgs anyway — so passing it directly through settings should bypass whatever rspack does to the env var

1 Like

I didn’t have a test for this scenario, so I’m going to check it myself.

For now, could you try what @dupontbertrand suggested?

Another workaround would be to teach the AI to tag .only on the proper describe/it blocks it acts on, at least until we confirm this is a regression we can fix in 3.4.1.

By the way, next week we will release a beta for Meteor 3.4.1 including many fixes for reports already made. I keep getting reports, and I have two right now including this one to work until next week, so this is a good time to report anything else you see that we can improve. Thanks.