Skip to content

🛠️ Repo: Test "require interface" #2982

Open

Description

We're currently testing the ability to require("mocha").it and require("mocha").describe but none of the other exported interface functions: https://github.com/mochajs/mocha/blob/f20de56637b2223f614ce40adc0d41a58030f042/test/unit/required-tokens.spec.js

Full list here:

mocha/lib/mocha.js

Lines 200 to 214 in 2bc9c4d

this.suite.on('pre-require', function (context) {
exports.afterEach = context.afterEach || context.teardown;
exports.after = context.after || context.suiteTeardown;
exports.beforeEach = context.beforeEach || context.setup;
exports.before = context.before || context.suiteSetup;
exports.describe = context.describe || context.suite;
exports.it = context.it || context.test;
exports.setup = context.setup || context.beforeEach;
exports.suiteSetup = context.suiteSetup || context.before;
exports.suiteTeardown = context.suiteTeardown || context.after;
exports.suite = context.suite || context.describe;
exports.teardown = context.teardown || context.afterEach;
exports.test = context.test || context.it;
exports.run = context.run;
});

I think the test file above should just use the global describe and it, but inside the it we should assert that the exports all are equal to the corresponding globals. It would be "more brittle" in the sense that we would have to change the test if we wanted to change the implementation from a simple reference copy to having separate global and exported functions, but I have a hard time imagining why we'd want/need to do that at the moment, and equality comparison would be fine for the current implementation and waaaaay easier than coming up with a way to use every last one of them and check for the correct behavior (and the current test doesn't even do the correct-behavior part for the two functions it does try using).

While we're in there, let's remove the done since the test is (and would still be) synchronous.

Note that once #2972 is resolved we should include xit (and whatever other x functions we have) in the new test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: repository toolingconcerning ease of contributionsemver-patchimplementation requires increase of "patch" version number; "bug fixes"status: accepting prsMocha can use your help with this one!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions