max-top-level-suites

Description

This rule enforces having a limited amount of top-level suites in a file. By default, a single suite per file is allowed. Multiple describe blocks is often a sign that a test should be broken down to multiple files.

One of the possible problems if having multiple suites is that, if you are, for example, going through tests one by one and focusing them (using describe.only), you might not notice describe block(s) that are down there at the bottom of a file which may lead to tests being unintentionally skipped.

The rule supports describe, context and suite suite function names and different valid suite name prefixes like skip or only.

Incorrect

describe('foo', function () {
    it('should do foo', function() {});
});

describe('bar', function() {
    it('should do bar', function() {});
});

Correct

describe('foo', function () {
    it('should do foo', function() {});

    describe('bar', function() {
        it('should do bar', function() {});
    });
});

Configuration

If you want to change the suite limit to, for instance, 2 suites per file:

rules: {
   "mocha/max-top-level-suites": ["warn", {limit: 2}]
},