Skip to content

Commit

Permalink
Fix mochajs#4559 by making functions returned by entrypoints lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
giltayar committed Jan 24, 2021
1 parent 22e5af8 commit 9499f28
Show file tree
Hide file tree
Showing 12 changed files with 28,540 additions and 103 deletions.
65 changes: 53 additions & 12 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
/** This file exists only for Node v10. Once v10 support is removed, we can safely delete this file */
import Mocha from './index.js';

export default Mocha;

export const before = Mocha.before;
export const after = Mocha.after;
export const beforeEach = Mocha.beforeEach;
export const afterEach = Mocha.afterEach;
export const describe = Mocha.describe;
export const suite = Mocha.suite;
export const suiteSetup = Mocha.suiteSetup;
export const suiteTeardown = Mocha.suiteTeardown;
export const it = Mocha.it;
export const xit = Mocha.xit;
export const test = Mocha.test;
export const run = Mocha.run;
// API stuff
export const utils = Mocha.utils;
export const interfaces = Mocha.interfaces;
export const reporters = Mocha.reporters;
export const Runnable = Mocha.Runnable;
export const Context = Mocha.Context;
export const Runner = Mocha.Runner;
export const Suite = Mocha.Suite;
export const Hook = Mocha.Hook;
export const Test = Mocha.Test;
export const unloadFile = Mocha.unloadFile;

/*
* Why do we not export Mocha.* directory, but rather pass throug proxy functions?
* Because Mocha.* is changed on each creation of a new Mocha instance,
* and the static Mocha.* is set before running a test suite, and so we
* changes on each new Mocha instance. Usually this is not a problem, as there is only
* one Mocha instance. Except in the instance of parallel execution, where a worker is
* reused to run another test file, and so creates another Mocha instance.
*
*/

// functions used by BDD tests
export const describe = (...args) => Mocha.describe(...args);
describe.only = (...args) => Mocha.describe.only(...args);
describe.skip = (...args) => Mocha.describe.skip(...args);
export const context = (...args) => Mocha.describe(...args);
context.only = (...args) => Mocha.describe.only(...args);
context.skip = (...args) => Mocha.describe.skip(...args);
export const it = (...args) => Mocha.it(...args);
it.only = (...args) => Mocha.it.only(...args);
it.skip = (...args) => Mocha.it.skip(...args);
export const specify = (...args) => Mocha.it(...args);
specify.only = (...args) => Mocha.it.only(...args);
specify.skip = (...args) => Mocha.it.skip(...args);
export const xit = (...args) => Mocha.xit(...args);
export const before = (...args) => Mocha.before(...args); // also used by QUNIT tests
export const after = (...args) => Mocha.after(...args); // also used by QUNIT tests
export const beforeEach = (...args) => Mocha.beforeEach(...args); // also used by QUNIT tests
export const afterEach = (...args) => Mocha.afterEach(...args); // also used by QUNIT tests

// functions used by TDD tests
export const suite = (...args) => Mocha.suite(...args); // also used by QUNIT tests
suite.only = (...args) => Mocha.suite.only(...args);
suite.skip = (...args) => Mocha.suite.skip(...args);
export const test = (...args) => Mocha.test(...args); // also used by QUNIT tests
test.only = (...args) => Mocha.it.only(...args);
test.skip = (...args) => Mocha.it.skip(...args);
export const suiteSetup = (...args) => Mocha.suiteSetup(...args);
export const suiteTeardown = (...args) => Mocha.suiteTeardown(...args);
export const setup = (...args) => Mocha.setup(...args);
export const teardown = (...args) => Mocha.teardown(...args);
26 changes: 17 additions & 9 deletions lib/entrypoints/bdd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use strict';
const Mocha = require('../../index.js');

exports.describe = Mocha.describe;
exports.context = Mocha.describe;
exports.it = Mocha.it;
exports.specify = Mocha.it;
exports.xit = Mocha.xit;
exports.before = Mocha.before;
exports.after = Mocha.after;
exports.beforeEach = Mocha.beforeEach;
exports.afterEach = Mocha.afterEach;
exports.describe = (...args) => Mocha.describe(...args);
exports.describe.only = (...args) => Mocha.describe.only(...args);
exports.describe.skip = (...args) => Mocha.describe.skip(...args);
exports.context = (...args) => Mocha.describe(...args);
exports.context.only = (...args) => Mocha.describe.only(...args);
exports.context.skip = (...args) => Mocha.describe.skip(...args);
exports.it = (...args) => Mocha.it(...args);
exports.it.only = (...args) => Mocha.it.only(...args);
exports.it.skip = (...args) => Mocha.it.skip(...args);
exports.specify = (...args) => Mocha.it(...args);
exports.specify.only = (...args) => Mocha.it.only(...args);
exports.specify.skip = (...args) => Mocha.it.skip(...args);
exports.xit = (...args) => Mocha.xit(...args);
exports.before = (...args) => Mocha.before(...args);
exports.after = (...args) => Mocha.after(...args);
exports.beforeEach = (...args) => Mocha.beforeEach(...args);
exports.afterEach = (...args) => Mocha.afterEach(...args);
24 changes: 15 additions & 9 deletions lib/entrypoints/bdd.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Mocha from '../../index.js';

export const describe = Mocha.describe;
export const context = Mocha.describe;
export const it = Mocha.it;
export const specify = Mocha.it;
export const xit = Mocha.xit;
export const before = Mocha.before;
export const after = Mocha.after;
export const beforeEach = Mocha.beforeEach;
export const afterEach = Mocha.afterEach;
export const describe = (...args) => Mocha.describe(...args);
describe.only = (...args) => Mocha.describe.only(...args);
describe.skip = (...args) => Mocha.describe.skip(...args);
export const context = (...args) => Mocha.describe(...args);
export const it = (...args) => Mocha.it(...args);
it.only = (...args) => Mocha.it.only(...args);
it.skip = (...args) => Mocha.it.skip(...args);
export const specify = (...args) => Mocha.it(...args);
specify.only = (...args) => Mocha.it.only(...args);
specify.skip = (...args) => Mocha.it.skip(...args);
export const xit = (...args) => Mocha.xit(...args);
export const before = (...args) => Mocha.before(...args);
export const after = (...args) => Mocha.after(...args);
export const beforeEach = (...args) => Mocha.beforeEach(...args);
export const afterEach = (...args) => Mocha.afterEach(...args);
52 changes: 37 additions & 15 deletions lib/entrypoints/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,43 @@ export const Hook = Mocha.Hook;
export const Test = Mocha.Test;
export const unloadFile = Mocha.unloadFile;

/*
* Why do we not export Mocha.* directory, but rather pass throug proxy functions?
* Because Mocha.* is changed on each creation of a new Mocha instance,
* and the static Mocha.* is set before running a test suite, and so we
* changes on each new Mocha instance. Usually this is not a problem, as there is only
* one Mocha instance. Except in the instance of parallel execution, where a worker is
* reused to run another test file, and so creates another Mocha instance.
*
*/

// functions used by BDD tests
export const describe = Mocha.describe;
export const context = Mocha.describe;
export const it = Mocha.it;
export const specify = Mocha.it;
export const xit = Mocha.xit;
export const before = Mocha.before; // also used by QUNIT tests
export const after = Mocha.after; // also used by QUNIT tests
export const beforeEach = Mocha.beforeEach; // also used by QUNIT tests
export const afterEach = Mocha.afterEach; // also used by QUNIT tests
export const describe = (...args) => Mocha.describe(...args);
describe.only = (...args) => Mocha.describe.only(...args);
describe.skip = (...args) => Mocha.describe.skip(...args);
export const context = (...args) => Mocha.describe(...args);
context.only = (...args) => Mocha.describe.only(...args);
context.skip = (...args) => Mocha.describe.skip(...args);
export const it = (...args) => Mocha.it(...args);
it.only = (...args) => Mocha.it.only(...args);
it.skip = (...args) => Mocha.it.skip(...args);
export const specify = (...args) => Mocha.it(...args);
specify.only = (...args) => Mocha.it.only(...args);
specify.skip = (...args) => Mocha.it.skip(...args);
export const xit = (...args) => Mocha.xit(...args);
export const before = (...args) => Mocha.before(...args); // also used by QUNIT tests
export const after = (...args) => Mocha.after(...args); // also used by QUNIT tests
export const beforeEach = (...args) => Mocha.beforeEach(...args); // also used by QUNIT tests
export const afterEach = (...args) => Mocha.afterEach(...args); // also used by QUNIT tests

// functions used by TDD tests
export const suite = Mocha.suite; // also used by QUNIT tests
export const test = Mocha.test; // also used by QUNIT tests
export const suiteSetup = Mocha.suiteSetup;
export const suiteTeardown = Mocha.suiteTeardown;
export const setup = Mocha.setup;
export const teardown = Mocha.teardown;
export const suite = (...args) => Mocha.suite(...args); // also used by QUNIT tests
suite.only = (...args) => Mocha.suite.only(...args);
suite.skip = (...args) => Mocha.suite.skip(...args);
export const test = (...args) => Mocha.test(...args); // also used by QUNIT tests
test.only = (...args) => Mocha.it.only(...args);
test.skip = (...args) => Mocha.it.skip(...args);
export const suiteSetup = (...args) => Mocha.suiteSetup(...args);
export const suiteTeardown = (...args) => Mocha.suiteTeardown(...args);
export const setup = (...args) => Mocha.setup(...args);
export const teardown = (...args) => Mocha.teardown(...args);
16 changes: 10 additions & 6 deletions lib/entrypoints/qunit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';
const Mocha = require('../../index.js');

exports.before = Mocha.before;
exports.after = Mocha.after;
exports.beforeEach = Mocha.beforeEach;
exports.afterEach = Mocha.afterEach;
exports.suite = Mocha.suite;
exports.test = Mocha.test;
exports.suite = (...args) => Mocha.suite(...args);
exports.suite.only = (...args) => Mocha.suite.only(...args);
exports.suite.skip = (...args) => Mocha.suite.skip(...args);
exports.test = (...args) => Mocha.test(...args);
exports.test.only = (...args) => Mocha.test.only(...args);
exports.test.skip = (...args) => Mocha.test.skip(...args);
exports.before = (...args) => Mocha.before(...args);
exports.after = (...args) => Mocha.after(...args);
exports.beforeEach = (...args) => Mocha.beforeEach(...args);
exports.afterEach = (...args) => Mocha.afterEach(...args);
16 changes: 10 additions & 6 deletions lib/entrypoints/qunit.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Mocha from '../../index.js';

export const before = Mocha.before;
export const after = Mocha.after;
export const beforeEach = Mocha.beforeEach;
export const afterEach = Mocha.afterEach;
export const suite = Mocha.suite;
export const test = Mocha.test;
export const suite = (...args) => Mocha.suite(...args);
suite.only = (...args) => Mocha.suite.only(...args);
suite.skip = (...args) => Mocha.suite.skip(...args);
export const test = (...args) => Mocha.test(...args);
test.only = (...args) => Mocha.it.only(...args);
test.skip = (...args) => Mocha.it.skip(...args);
export const before = (...args) => Mocha.before(...args);
export const after = (...args) => Mocha.after(...args);
export const beforeEach = (...args) => Mocha.beforeEach(...args);
export const afterEach = (...args) => Mocha.afterEach(...args);
16 changes: 10 additions & 6 deletions lib/entrypoints/tdd.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';
const Mocha = require('../../index.js');

exports.suite = Mocha.suite;
exports.test = Mocha.test;
exports.suiteSetup = Mocha.suiteSetup;
exports.suiteTeardown = Mocha.suiteTeardown;
exports.setup = Mocha.setup;
exports.teardown = Mocha.teardown;
exports.suite = (...args) => Mocha.suite(...args);
exports.suite.only = (...args) => Mocha.suite.only(...args);
exports.suite.skip = (...args) => Mocha.suite.skip(...args);
exports.test = (...args) => Mocha.test(...args);
exports.test.only = (...args) => Mocha.test.only(...args);
exports.test.skip = (...args) => Mocha.test.skip(...args);
exports.suiteSetup = (...args) => Mocha.suiteSetup(...args);
exports.suiteTeardown = (...args) => Mocha.suiteTeardown(...args);
exports.setup = (...args) => Mocha.setup(...args);
exports.teardown = (...args) => Mocha.teardown(...args);
16 changes: 10 additions & 6 deletions lib/entrypoints/tdd.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Mocha from '../../index.js';

export const suite = Mocha.suite;
export const test = Mocha.test;
export const suiteSetup = Mocha.suiteSetup;
export const suiteTeardown = Mocha.suiteTeardown;
export const setup = Mocha.setup;
export const teardown = Mocha.teardown;
export const suite = (...args) => Mocha.suite(...args);
suite.only = (...args) => Mocha.suite.only(...args);
suite.skip = (...args) => Mocha.suite.skip(...args);
export const test = (...args) => Mocha.test(...args);
test.only = (...args) => Mocha.it.only(...args);
test.skip = (...args) => Mocha.it.skip(...args);
export const suiteSetup = (...args) => Mocha.suiteSetup(...args);
export const suiteTeardown = (...args) => Mocha.suiteTeardown(...args);
export const setup = (...args) => Mocha.setup(...args);
export const teardown = (...args) => Mocha.teardown(...args);
Loading

0 comments on commit 9499f28

Please sign in to comment.