From 552c20879853e3339812c58632ec7558f6f1c40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E?= <1395348685z@gmail.com> Date: Sun, 12 Sep 2021 22:43:18 +0800 Subject: [PATCH 1/2] fix(browser): stop using all global vars when init --- browser-entry.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/browser-entry.js b/browser-entry.js index dee3789231..cb59ecc39d 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -216,4 +216,29 @@ global.mocha = mocha; // this allows test/acceptance/required-tokens.js to pass; thus, // you can now do `const describe = require('mocha').describe` in a // browser context (assuming browserification). should fix #880 -module.exports = Object.assign(mocha, global); +[ + 'Mocha', + 'after', + 'afterEach', + 'before', + 'beforeEach', + 'context', + 'describe', + 'it', + 'mocha', + 'run', + 'setup', + 'specify', + 'suite', + 'suiteSetup', + 'suiteTeardown', + 'teardown', + 'test', + 'xcontext', + 'xdescribe', + 'xit', + 'xspecify' +].forEach(function(key) { + if (key in global) mocha[key] = global[key]; +}); +module.exports = mocha; From dda91481e419aac2904c6bcf455e1bce8a04caea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E?= <1395348685z@gmail.com> Date: Thu, 16 Sep 2021 13:38:13 +0800 Subject: [PATCH 2/2] fix(browser): remove token requirements --- browser-entry.js | 28 ---------------------------- lib/cli/watch-run.js | 4 ++-- test/browser-specific/setup.js | 2 ++ test/unit/required-tokens.spec.js | 12 ------------ 4 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 test/unit/required-tokens.spec.js diff --git a/browser-entry.js b/browser-entry.js index cb59ecc39d..9719c3d528 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -213,32 +213,4 @@ Mocha.process = process; global.Mocha = Mocha; global.mocha = mocha; -// this allows test/acceptance/required-tokens.js to pass; thus, -// you can now do `const describe = require('mocha').describe` in a -// browser context (assuming browserification). should fix #880 -[ - 'Mocha', - 'after', - 'afterEach', - 'before', - 'beforeEach', - 'context', - 'describe', - 'it', - 'mocha', - 'run', - 'setup', - 'specify', - 'suite', - 'suiteSetup', - 'suiteTeardown', - 'teardown', - 'test', - 'xcontext', - 'xdescribe', - 'xit', - 'xspecify' -].forEach(function(key) { - if (key in global) mocha[key] = global[key]; -}); module.exports = mocha; diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js index dabcd535fb..93f5059f1c 100644 --- a/lib/cli/watch-run.js +++ b/lib/cli/watch-run.js @@ -46,7 +46,7 @@ exports.watchParallelRun = ( // this `require` is needed because the require cache has been cleared. the dynamic // exports set via the below call to `mocha.ui()` won't work properly if a - // test depends on this module (see `required-tokens.spec.js`). + // test depends on this module. const Mocha = require('../mocha'); // ... and now that we've gotten a new module, we need to use it again due @@ -108,7 +108,7 @@ exports.watchRun = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => { // this `require` is needed because the require cache has been cleared. the dynamic // exports set via the below call to `mocha.ui()` won't work properly if a - // test depends on this module (see `required-tokens.spec.js`). + // test depends on this module. const Mocha = require('../mocha'); // ... and now that we've gotten a new module, we need to use it again due diff --git a/test/browser-specific/setup.js b/test/browser-specific/setup.js index 611346665a..2c9b490b2d 100644 --- a/test/browser-specific/setup.js +++ b/test/browser-specific/setup.js @@ -8,3 +8,5 @@ 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 deleted file mode 100644 index 9b6f88433f..0000000000 --- a/test/unit/required-tokens.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var describe = require('../..').describe; -var it = require('../..').it; - -describe('using imported describe', function() { - it('using imported it', function(done) { - assert.ok(true); - done(); - }); -});