From 9ed47ef4e4d4fc87e7b7d7fecebb7646c67908b8 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Thu, 14 Oct 2021 10:21:45 +0200 Subject: [PATCH] fix(browser): enable 'bdd' import for bundlers --- browser-entry.js | 12 +++++++++++- test/browser-specific/setup.js | 2 -- test/unit/required-tokens.spec.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/unit/required-tokens.spec.js diff --git a/browser-entry.js b/browser-entry.js index 9719c3d528..7f1dd99689 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -209,8 +209,18 @@ Mocha.process = process; /** * Expose mocha. */ - global.Mocha = Mocha; global.mocha = mocha; +// for bundlers: enable `import {describe, it} from 'mocha'` +// `bdd` interface only +// prettier-ignore +[ + 'describe', 'context', 'it', 'specify', + 'xdescribe', 'xcontext', 'xit', 'xspecify', + 'before', 'beforeEach', 'afterEach', 'after' +].forEach(function(key) { + mocha[key] = global[key]; +}); + module.exports = mocha; diff --git a/test/browser-specific/setup.js b/test/browser-specific/setup.js index 2c9b490b2d..611346665a 100644 --- a/test/browser-specific/setup.js +++ b/test/browser-specific/setup.js @@ -8,5 +8,3 @@ global.expect = require('unexpected') .use(require('unexpected-map')) .use(require('unexpected-sinon')) .use(require('unexpected-eventemitter')); - -require('../../browser-entry'); diff --git a/test/unit/required-tokens.spec.js b/test/unit/required-tokens.spec.js new file mode 100644 index 0000000000..bb9f05f44e --- /dev/null +++ b/test/unit/required-tokens.spec.js @@ -0,0 +1,11 @@ +'use strict'; + +const assert = require('assert'); +const {describe, it} = require('../..'); + +describe('using imported "describe"', function() { + it('using imported "it"', function(done) { + assert.ok(true); + done(); + }); +});