mocha icon indicating copy to clipboard operation
mocha copied to clipboard

🚀 Feature: Add an option to run all tests, including skipped ones

Open JavaScriptBach opened this issue 1 year ago • 2 comments

Feature Request Checklist

Overview

It would be nice to have an option that could make Mocha run all tests, even skipped ones.

At my company, we skip flaky tests in our CI build to avoid blocking developers, but we'd like to set up a "quarantined" tests build that runs all tests. This allows us to check when flaky tests are no longer flaky and can be safely introduced back into the blocking tests pool.

Suggested Solution

mocha --includeSkipped

Alternatives

Sed all my test files before running Mocha, which isn't particularly sound.

Additional Info

No response

JavaScriptBach avatar Oct 10 '24 22:10 JavaScriptBach

Hmm, but how would Mocha / a project's testing infrastructure know which tests are skipped for flakiness vs. other reasons?

This feels to me like a project-specific preference that would be better solved in project-land. For example, you could write your own function that calls it or it.skip depending on some process.env.RUN_FLAKY_TESTS:

function myIt(title, callback) {
  if (process.env.RUN_FLAKY_TESTS) {
    it(title, callback);
  } else {
    it.skip(title, callback);
  }
}

Am I missing some nuance to the request?

JoshuaKGoldberg avatar Oct 11 '24 14:10 JoshuaKGoldberg

Mocha doesn't need to know why a test is skipped. Under this model, the user asked for all tests to be run, so interpreting the results becomes the user's problem.

Your workaround is fair; it just feels weird that Mocha supports marking a test as skipped, but doesn't support other ways of interacting with it. If I wanted a test to never run, the logical thing to do would be to delete the test entirely.

JavaScriptBach avatar Oct 11 '24 19:10 JavaScriptBach

If I wanted a test to never run, the logical thing to do would be to delete the test entirely.

Not necessarily. Folks sometimes try to keep skipped tests around to make sure they stay valid for static analysis such as linting or type-checking. A test might be skipped for a time-sensitive reason such as an external service not being ready yet or dropping support for something at a known time.

Anyway, per #5027, we're not looking to add a lot of new features. I'm going to go ahead and close this as a pretty specific use case. Thanks for filing + discussing! 🤎

JoshuaKGoldberg avatar Oct 29 '24 20:10 JoshuaKGoldberg

OK, fair enough. Thanks for considering it, and thanks for taking up the maintenance of this project. I feel like it is in good hands after seeing the work you've done in typescript-eslint.

JavaScriptBach avatar Oct 29 '24 21:10 JavaScriptBach