Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix(browser): enable 'bdd' import for bundlers (#4769)

Juerg B012d79de0069
diff --git a/browser-entry.js b/browser-entry.js
index 9719c3d5..7f1dd996 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 2c9b490b..61134666 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 00000000..bb9f05f4
--- /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();
+ });
+});