From f28d6fe1bea23da9bdab52e8adda598dc891745a Mon Sep 17 00:00:00 2001 From: "JeongHoon Byun (a.k.a Outsider)" Date: Sun, 30 Aug 2020 20:43:37 +0900 Subject: [PATCH 01/29] fix typo in 8.1.2 changelog (#4432) Signed-off-by: Outsider --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ce03feb5..d6511f8934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ## :bug: Fixes - [#4418](https://github.com/mochajs/mocha/issues/4418): Fix command-line flag incompatibility in forthcoming Node.js v14.9.0 ([**@boneskull**](https://github.com/boneskull)) -- [#4401](https://github.com/mochajs/mocha/issues/4401): Fix missing global variable in browser ([**@irrationelle**](https://github.com/irrationelle)) +- [#4401](https://github.com/mochajs/mocha/issues/4401): Fix missing global variable in browser ([**@irrationnelle**](https://github.com/irrationnelle)) ## :lock: Security Fixes From 06a7f2199d10cc9002d6c23a302ff719f2b72a3e Mon Sep 17 00:00:00 2001 From: Donghoon Song Date: Sun, 30 Aug 2020 16:01:37 +0900 Subject: [PATCH 02/29] remove wallaby-logo.png trim option --- docs/_includes/default.liquid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_includes/default.liquid b/docs/_includes/default.liquid index 1b146cd001..58a49edb0c 100644 --- a/docs/_includes/default.liquid +++ b/docs/_includes/default.liquid @@ -52,7 +52,7 @@ title="Mocha is sponsored by Wallaby" > From c1db2a6b6c056753feae8ddb9d7343f99fc94245 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 2 Sep 2020 13:25:30 -0700 Subject: [PATCH 03/29] redirect webpack test output to a temp dir Signed-off-by: Christopher Hiller --- test/browser-specific/fixtures/webpack/webpack.config.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/browser-specific/fixtures/webpack/webpack.config.js b/test/browser-specific/fixtures/webpack/webpack.config.js index f43a80d010..53d4769c8e 100644 --- a/test/browser-specific/fixtures/webpack/webpack.config.js +++ b/test/browser-specific/fixtures/webpack/webpack.config.js @@ -1,9 +1,18 @@ 'use strict'; const FailOnErrorsPlugin = require('fail-on-errors-webpack-plugin'); +const {tmpdir} = require('os'); +const {join} = require('path'); + +const outputPath = join(tmpdir(), 'mocha-test-webpack'); + +console.error('output dir: %s', outputPath); module.exports = { entry: require.resolve('./webpack.fixture.mjs'), + output: { + path: outputPath + }, plugins: [ new FailOnErrorsPlugin({ failOnErrors: true, From 12db9dbc9dd3b0ec31c182d0e41a6ec615735401 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 8 Sep 2020 12:58:01 -0700 Subject: [PATCH 04/29] implementation of global setup/teardown; closes #4308 (#4360) * implementation of global setup/teardown; closes #4308 * move deprecate() and warn() from utils into errors module This avoids a circular dependency which arises when Mocha is bundled. These are private APIs. --- .eslintignore | 1 + .wallaby.js | 3 +- docs/index.md | 526 +++-- lib/cli/run-helpers.js | 71 +- lib/cli/run.js | 14 +- lib/cli/watch-run.js | 79 +- lib/errors.js | 149 +- lib/mocha.js | 307 ++- lib/nodejs/parallel-buffered-runner.js | 18 + lib/nodejs/worker.js | 17 +- lib/plugin-loader.js | 286 +++ lib/runner.js | 253 ++- lib/suite.js | 7 +- lib/utils.js | 80 +- package-lock.json | 1243 ++--------- package.json | 4 +- test/assertions.js | 275 ++- test/browser-specific/setup.js | 2 + .../integration/fixtures/deprecate.fixture.js | 8 +- .../global-setup-teardown-multiple.fixture.js | 20 + .../global-setup-teardown.fixture.js | 10 + .../global-fixtures/global-setup.fixture.js | 6 + .../global-teardown.fixture.js | 5 + .../root-hooks}/esm/package.json | 0 .../esm/root-hook-defs-esm.fixture.js | 0 .../root-hooks}/root-hook-defs-a.fixture.js | 0 .../root-hooks}/root-hook-defs-b.fixture.js | 0 .../root-hooks}/root-hook-defs-c.fixture.js | 0 .../root-hooks}/root-hook-defs-d.fixture.js | 0 .../root-hook-defs-esm-broken.fixture.js | 0 .../root-hook-defs-esm.fixture.mjs | 0 .../root-hooks}/root-hook-test-2.fixture.js | 0 .../root-hooks}/root-hook-test.fixture.js | 0 test/integration/helpers.js | 546 +++-- test/integration/hook-err.spec.js | 4 +- test/integration/hooks.spec.js | 4 +- test/integration/multiple-runs.spec.js | 31 +- test/integration/options/extension.spec.js | 4 +- test/integration/options/watch.spec.js | 196 +- test/integration/pending.spec.js | 4 +- .../plugins/global-fixtures.spec.js | 293 +++ .../root-hooks.spec.js} | 44 +- test/integration/retries.spec.js | 4 +- test/node-unit/cli/run-helpers.spec.js | 79 +- test/node-unit/mocha.spec.js | 57 +- test/node-unit/worker.spec.js | 28 +- test/reporters/xunit.spec.js | 28 +- test/setup.js | 2 + test/unit/errors.spec.js | 81 + test/unit/mocha.spec.js | 439 +++- test/unit/plugin-loader.spec.js | 514 +++++ test/unit/runner.spec.js | 1842 +++++++++-------- test/unit/suite.spec.js | 6 +- test/unit/utils.spec.js | 130 +- 54 files changed, 4590 insertions(+), 3130 deletions(-) create mode 100644 lib/plugin-loader.js create mode 100644 test/integration/fixtures/plugins/global-fixtures/global-setup-teardown-multiple.fixture.js create mode 100644 test/integration/fixtures/plugins/global-fixtures/global-setup-teardown.fixture.js create mode 100644 test/integration/fixtures/plugins/global-fixtures/global-setup.fixture.js create mode 100644 test/integration/fixtures/plugins/global-fixtures/global-teardown.fixture.js rename test/integration/fixtures/{options/require => plugins/root-hooks}/esm/package.json (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/esm/root-hook-defs-esm.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-a.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-b.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-c.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-d.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-esm-broken.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-defs-esm.fixture.mjs (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-test-2.fixture.js (100%) rename test/integration/fixtures/{options/require => plugins/root-hooks}/root-hook-test.fixture.js (100%) create mode 100644 test/integration/plugins/global-fixtures.spec.js rename test/integration/{options/require.spec.js => plugins/root-hooks.spec.js} (81%) create mode 100644 test/unit/plugin-loader.spec.js diff --git a/.eslintignore b/.eslintignore index a7a33c25c6..bf70c4ebbe 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,6 +2,7 @@ coverage/ mocha.js *.fixture.js docs/_site +docs/api docs/_dist docs/example out/ diff --git a/.wallaby.js b/.wallaby.js index b23a244650..59083bb5f4 100644 --- a/.wallaby.js +++ b/.wallaby.js @@ -48,6 +48,7 @@ module.exports = () => { ); require('./test/setup'); }, - debug: true + debug: true, + runMode: 'onsave' }; }; diff --git a/docs/index.md b/docs/index.md index b8396ea39e..ebe5f86ed1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -78,9 +78,9 @@ In your editor: ```js var assert = require('assert'); -describe('Array', function () { - describe('#indexOf()', function () { - it('should return -1 when the value is not present', function () { +describe('Array', function() { + describe('#indexOf()', function() { + it('should return -1 when the value is not present', function() { assert.equal([1, 2, 3].indexOf(4), -1); }); }); @@ -116,51 +116,65 @@ $ npm test ## Run Cycle Overview -A brief outline on the order Mocha's components are executed. -Worth noting that all hooks, `describe` and `it` callbacks are run in the order they are defined (i.e. found in the file). - -``` -run 'mocha spec.js' -| -spawn child process -| -|--------------> inside child process - process and apply options - | - run spec file/s - | - |--------------> per spec file - suite callbacks (e.g., 'describe') - | - 'before' root-level pre-hook - | - 'before' pre-hook - | - |--------------> per test - 'beforeEach' root-level pre-hook - | - 'beforeEach' pre-hook - | - test callbacks (e.g., 'it') - | - 'afterEach' post-hook - | - 'afterEach' root-level post-hook - |<-------------- per test end - | - 'after' post-hook - | - 'after' root-level post-hooks - |<-------------- per spec file end -|<-------------- inside child process end -``` +> Updated for v9.0.0. + +The following is a mid-level outline of Mocha's "flow of execution" when run in Node.js; the "less important" details have been omitted. + +In a browser, test files are loaded by `