Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mochajs/mocha
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7c09e634267ddc18d1ec08a4bfd999efa317d684
Choose a base ref
...
head repository: mochajs/mocha
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5f96d511dbf913f135b92198aab721a27f6b44fe
Choose a head ref

Commits on Mar 12, 2020

  1. Copy the full SHA
    c7f5e88 View commit details
  2. Remove deprecated methods in mocha.js (#4178)

    Remove following methods and cleanup.
    - Mocha.prototype.ignoreLeaks
    - Mocha.prototype.useColors
    - Mocha.prototype.useInlineDiffs
    - Mocha.prototype.hideDiff
    wnghdcjfe authored Mar 12, 2020
    Copy the full SHA
    6aeeb33 View commit details
  3. Copy the full SHA
    2f26478 View commit details

Commits on Mar 18, 2020

  1. Copy the full SHA
    dfaa654 View commit details
  2. Copy the full SHA
    c1a8adb View commit details

Commits on Mar 19, 2020

  1. Drop mkdirp and replace it with fs.mkdirSync (#4200)

    - Replace mkdirp with fs.mkdirSync using {recursive: true}
    - Drop the dependency mkdirp from Mocha
    - Fix version number of docs and package.json
    HyunSangHan authored Mar 19, 2020
    Copy the full SHA
    f87825a View commit details

Commits on Mar 20, 2020

  1. Copy the full SHA
    6320d3d View commit details

Commits on Mar 23, 2020

  1. Update devDependencies and Travis (#4211)

    * update devDependencies
    * fix linting error
    * .lintstagedrc.json: advanced to simple format
    * travis: run browser tests with Node v12
    juergba authored Mar 23, 2020
    Copy the full SHA
    0e77e41 View commit details

Commits on Mar 25, 2020

  1. Copy the full SHA
    c5fc2be View commit details

Commits on Apr 4, 2020

  1. Copy the full SHA
    54475eb View commit details

Commits on Apr 18, 2020

  1. Copy the full SHA
    8236ffd View commit details

Commits on Apr 20, 2020

  1. Copy the full SHA
    38d579a View commit details

Commits on Apr 22, 2020

  1. remove cruft from wallaby config

    also increase default timeout
    
    Ref: #4198
    boneskull committed Apr 22, 2020
    Copy the full SHA
    6838eaf View commit details

Commits on Apr 24, 2020

  1. refactor Test: add markOnly() for encapsulation (PR #4249)

    * add markOnly instance method to test class
    
    * add test cases for markOnly method
    
    * use markOnly method of test class instead of accessing parent properties method
    
    * refactor cases for test markOnly
    
    * refactor test class unit test markOnly to exhaustively satisfy
    
    Ref: #3689
    arvidOtt authored Apr 24, 2020
    Copy the full SHA
    5f9400d View commit details
  2. enable emoji on website; enable normal ul elements

    grouped these together:
    
    - Site can now use emoji :party:
    - Using the `.single-column` class will render a `ul` element as a "normal" list
    - Suppress the warning about `text` being an unknown language coming out of 11ty/Prism/markdown-it
    
    Ref: #4198
    boneskull committed Apr 24, 2020
    Copy the full SHA
    de759d1 View commit details
  3. fixes some signal handling

    - `landing` reporter befouls the terminal up if `SIGINT` is issued
    - `--exit` test used an incorrect description, and also did not reliably handle `SIGINT` when running
    - `runMocha` helper returns the child process
    
    Ref: #4198
    boneskull committed Apr 24, 2020
    Copy the full SHA
    284b411 View commit details
  4. travis: add job names, add Node.js v14 to matrix

    - fix webhooks
    - remove webhook for `mochajs/mocha`
    - add v14 to Appveyor
    
    Ref: #4198
    boneskull committed Apr 24, 2020
    Copy the full SHA
    a94e2d3 View commit details
  5. better debug output

    - make sure that template strings aren't used in debug statements, since they are eager
    
    Ref: #4198
    boneskull committed Apr 24, 2020
    Copy the full SHA
    a2efd11 View commit details
  6. fix nyc ignorelist

    should keep more garbage out of the coverage
    
    Ref: #4198
    boneskull committed Apr 24, 2020
    Copy the full SHA
    27b799e View commit details
  7. type check before calling retriedTest()

    juergba authored and boneskull committed Apr 24, 2020
    Copy the full SHA
    13e94b1 View commit details

Commits on Apr 25, 2020

  1. Copy the full SHA
    4c0231c View commit details

Commits on Apr 26, 2020

  1. Copy the full SHA
    46f727e View commit details
  2. Mark HTTP 429 responses as allowed failures in hyperlink check. We so…

    …metimes get these from unpkg and it shouldnt block out builds (#4253)
    Munter authored Apr 26, 2020
    Copy the full SHA
    e7add63 View commit details

Commits on Apr 28, 2020

  1. Update @mocha/docdash to 2.1.3

    craigtaub authored and boneskull committed Apr 28, 2020
    Copy the full SHA
    8bc7579 View commit details
  2. refactor validatePlugins to throw coded errors

    - add `createInvalidPluginError` for reporters, UIs, and future plugins
    - ensures the original error is output if the module exists, but it throws (see `test/node-unit/cli/fixtures/bad-module.fixture.js`)
    - remove unneeded `process.cwd()` from call to `path.resolve()`
    
    Ref: #4198
    boneskull committed Apr 28, 2020
    Copy the full SHA
    400bf9b View commit details

Commits on Apr 30, 2020

  1. Copy the full SHA
    b5e7183 View commit details

Commits on May 1, 2020

  1. adds a bunch of keywords

    Did you know that if you click on the "testing" icon on npmjs.com, Mocha is completely absent?
    
    It wants the keyword `testing`, which we do not have.  So I added that and a bunch more.  Since all of
    the other major test frameworks seem to use keywords of others, might as well join that arms race.
    boneskull committed May 1, 2020
    Copy the full SHA
    14da63a View commit details
  2. Exposing filename in JSON, doc, and json-stream reporters (#4219)

    * Exposing filename in JSON reporter
    
    * Added filename to json-stream reporter
    
    * updated tests and also fixed issue with json-stream reporter
    
    * added filenames to doc reporter
    dfebs authored May 1, 2020
    Copy the full SHA
    9c965c9 View commit details

Commits on May 4, 2020

  1. assorted test fixes & refactors (#4240)

    - increase default timeout for wiggle room
    - specify `watch-ignore` in case we run our own tests in watch mode
    - reformat `.mocharc.yml`
    - `integration/fixtures/uncaught/listeners.fixture.js`: reduce number of listeners created to avoid max listener warning
    - `integration/fixtures/diffs.spec.js`: do not pass `-C`; the helper already does this
    - `integration/options/watch.spec.js`: do not use context object; be more specific about spawn options. tweak timings
    - `node-unit/mocha.spec.js`: make more unit-test-like insofar as that's possible when testing w/ `require()`
    - `node-unit/cli/config.spec.js`: rewiremock fixes; assertion tweaks; add test for `.cjs` extension
    - `node-unit/cli/options.spec.js`: rewiremock fixes; increase timeout
    - `unit/hook-timeout.spec.js`: do not override default (configured) timeout
    - `unit/runner.spec.js`: leverage [unexpected-eventemitter](https://npm.im/unexpected-eventemitter)
    - `unit/throw.spec.js`: proper teardown: remove uncaught exception listeners
    - `unit/timeout.spec.js`: increase timeout to _greater than_ default (configured) value
    - `example/config/.mocharc.yml`: quote yaml strings
    
    BONUS
    
    - fixes a weird call to `Mocha.unloadFile()` from `Mocha#unloadFiles()`
    
    Ref: #4198
    boneskull authored May 4, 2020
    Copy the full SHA
    2509ab5 View commit details
  2. test helper improvements (#4241)

    * test helper improvements
    
    - enables `RawResult` (the result of `invokeMocha()` or `invokeMochaAsync()`) to check the exit code via `to have code` assertion
    - add passed/failing/pending assertions for `RawRunResult` (the result of `runMocha()` or `runMochaAsync()`)
    
    - expose `getSummary()`, which can be used with a `RawResult` (when not failing)
    - reorganize the module a bit
    - create `runMochaAsync()` and `runMochaJSONAsync()` which are like `runMocha()` and `runMochaJSON()` except return `Promise`s
    - better trapping of JSON parse errors
    - better default handling of `STDERR` output in subprocesses (print it instead of suppress it!)
    - do not let the `DEBUG` env variable reach subprocesses _unless it was explicitly supplied_
    - add an easily copy-paste-able `command` prop to summary
    - add some missing docstrings
    
    Ref: #4198
    
    * increase timeout in watch test for CI
    
    the same code should be in PR #4240
    boneskull authored May 4, 2020
    Copy the full SHA
    240cb3d View commit details

Commits on May 5, 2020

  1. Copy the full SHA
    65daa9a View commit details
  2. Copy the full SHA
    8b6a76c View commit details

Commits on May 6, 2020

  1. Remove enableTimeout api + allow overriding a disabled timeout (#4260)

    * Reset enableTimeouts. Integration test
    
    * Spec update
    
    * Use function which logs
    
    * Remove _enableTimeouts
    
    * Defensive check for 0
    
    * Use correct timeout value
    
    * Remove superfluous logic.
    
    * Add note about `enableTimeouts` to docs
    
    * Update comment
    
    * Lint fix
    
    * Disable if setting == or grtr to upper
    
    * Swap asser to expect
    
    * Excl docs in coverage + clamp in suite.
    
    * Add note about async tests
    craigtaub authored May 6, 2020
    Copy the full SHA
    c0137eb View commit details

Commits on May 11, 2020

  1. Add ability to run tests in a mocha instance multiple times (#4234); c…

    …loses #2783
    
    * Add ability to run tests in a mocha instance multiple times
    
    * Rename `autoDispsoe` to `cleanReferencesAfterRun`,
    
    Rename since we cannot dispose the entire mocha instance after a test run. We should keep the process.on('uncaughtException') handlers in place in order to not break existing functionality.
    
    * Allow `unloadFiles` to reset `referencesCleaned`.
    
    * Complete rename of _cleanReferencesAfterRun
    
    * Add integration test for running a suite multiple times
    
    * improve api docs
    
    * Docs: fix dead link
    
    * Make sure tests run on older node versions
    
    * Remove `.only` 😅
    
    * Implement `process.listenerCount` in the browser
    
    * Implement mocha states in a finite state machine
    
    * Fix some small remarks
    
    * Make integration tests more damp
    
    * Keep `Runner` api backward compatible
    
    * Unload files when disposed
    
    * Runnable.reset should also reset `err` and `state`
    
    * Also reset hooks
    
    Co-authored-by: Christopher Hiller <boneskull@boneskull.com>
    nicojs and boneskull authored May 11, 2020
    Copy the full SHA
    fbe3ce4 View commit details

Commits on May 12, 2020

  1. --forbid-only doesn't recognize it.only when before crashes (#4256)…

    …; closes #3840
    
    * add fixtures that result in it.only combined with --forbid-only bug
    
    * adapt forbidonly test cases to cover it.only bug
    
    * check if forbid only option is set prior to marking a test only and throw error
    
    * change name of only test back to previous
    
    * use custom assertion for expecting error in forbidOnly tests
    
    * remove empty line
    
    * use createUnsupportedError instead of throw new Error
    
    * use createUnsupportedError instead of throw new Error
    
    * remove check if suite hasOnly and forbidOnly option is set as this is done before runtime
    
    * implement markOnly instance method in suite class
    
    * add unit test for suites markOnly method
    
    * throw exception if --forbid-only option is set even if suite is not selected by grep
    
    * adapt forbidOnly integration tests to check for failure if only suite is not selected by grep
    
    * fix jsdocs of suite markonly
    
    * Revert "fix jsdocs of suite markonly"
    
    This reverts commit cffc71a.
    
    * Revert "adapt forbidOnly integration tests to check for failure if only suite is not selected by grep"
    
    This reverts commit 336425a.
    
    * Revert "throw exception if --forbid-only option is set even if suite is not selected by grep"
    
    This reverts commit f871782.
    
    * Revert "add unit test for suites markOnly method"
    
    This reverts commit c2c8dc8.
    
    * Revert "implement markOnly instance method in suite class"
    
    This reverts commit 4b37e3c.
    arvidOtt authored May 12, 2020
    Copy the full SHA
    184036f View commit details

Commits on May 14, 2020

  1. fix test/unit/hook.spec.js (#4288)

    * fix test/unit/hook.spec.js
    
    `Function.prototype.name` is not available in IE11, and will cause the browser tests to fail.
    
    * another IE11 fix: avoid Array.prototype.findIndex
    
    Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
    boneskull authored May 14, 2020
    Copy the full SHA
    81e203c View commit details
  2. fix improper warnings for invalid reporters (#4275)

    * fix improper warnings for invalid reporters
    
        also: reorganize, add, and refactor a bunch of problematic unit tests for `lib/mocha.js`.  better isolation except where we can't really do that (calling `require`)
    
        there's still missing tests in here, but this is an improvement.
    
    * restrict use of Object.assign in ESLint config
    * add wrapper around process.cwd()
        - better isolation
        - a use of `process.cwd()` in `lib/runner.js` was left in place to avoid conflicts, because another PR will remove it
    boneskull authored May 14, 2020
    Copy the full SHA
    1a4646d View commit details

Commits on May 18, 2020

  1. Copy the full SHA
    442cf5f View commit details
  2. smart quotes and such on website; closes #3716

    I do not know if this actually works, but it might.
    
    Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
    boneskull committed May 18, 2020
    Copy the full SHA
    68eec9e View commit details
  3. do not commit generated content to VCS; closes #3713 (#4289)

    * do not commit generated content to VCS
    
    This removes `markdown-magic` and replaces its functionality with the built-in data capabilities of 11ty.
    
    The TOC, `--help` output, and source files are now all done via global data scripts in `docs/_data`.
    
    When building documentation, we will no longer get changes to e.g., `docs/index.md` because of the automatically generated content.
    
    * add inclusive language plugin to eleventy
    
    Usage of the words as defined in options will result in a warning, and will not break the build.
    
    Also: Eleventy should ignore the historical changelogs in `docs/changelogs`.
    boneskull authored May 18, 2020
    Copy the full SHA
    ca0daa3 View commit details
  4. add Root Hook Plugins

    (documentation will be in another PR)
    
    Adds "root hook plugins", a system to define root hooks via files loaded with `--require`.
    
    This enables root hooks to work in parallel mode.  Because parallel mode runs files in a non-deterministic order, and files do not share a `Mocha` instance, it is not possible to share these hooks with other test files.  This change also works well with third-party libraries for Mocha which need the behavior; these can now be trivially consumed by adding `--require` or `require: 'some-library'` in Mocha's config file.
    
    The way it works is:
    
    1. When a file is loaded via `--require`, we check to see if that file exports a property named `mochaHooks` (can be multiple files).
    1. If it does, we save a reference to the property.
    1. After Yargs' validation phase, we use async middleware to execute root hook plugin functions--or if they are objects, just collect them--and we flatten all hooks found into four buckets corresponding to the four hook types.
    1. Once `Mocha` is instantiated, if it is given a `rootHooks` option, those hooks are applied to the root suite.
    
    This works with parallel tests because we can save a reference to the flattened hooks in each worker process, and a new `Mocha` instance is created with them for each test file.
    
    * * *
    
    Tangential:
    
    - Because a root hook plugin can be defined as an `async` function, I noticed that `utils.type()` does not return `function` for async functions; it returns `asyncfunction`.  I've added a (Node-specific, for now) test for this.
    
    - `handleRequires` is now `async`, since it will need to be anyway to support ESM and calls to `import()`.
    
    - fixed incorrect call to `fs.existsSync()`
    
    Ref: #4198
    boneskull committed May 18, 2020
    Copy the full SHA
    722ce01 View commit details

Commits on May 20, 2020

  1. multiple async done() calls result in failure; closes #4151 (#4152)

    - added a method in `errors` module to create a "multiple done" err
    - modernize `multiple-done.spec.js`
    - refactor errors into constants in `errors` module
    - remove `Runner#started` prop; replace with `Runner#state` prop + constants
    - add a catchall `createFatalError()` function to `errors` module; this is called when a test fails twice by other means (unsure what those means are yet)
    - force color in Travis CI b/c my eyes
    - remove `Runner#uncaughtEnd`; move logic to `Runner#uncaught`, since we can now rely on the value of `Runner#state`.
    - upgrade `unexpected-eventemitter`
    - fix potential listener leak in `Runner#run`
    boneskull authored May 20, 2020
    Copy the full SHA
    cb5eb8e View commit details

Commits on May 22, 2020

  1. fetch sponsors at build time, show ALL non-skeevy sponsors; closes #4271

     (#4272)
    
    * Show all sponsors on site
    
    - change ordering: sponsors, then backers
    - blacklist bad actors
    - rename `default.html` to `default.liquid`, because it's a Liquid template.
    - fiddles with the CSS a bit
    - do not attempt to display a link if there is no website
    
    * use smaller imgs for backers
    
    * Fetch all open collective sponsor images to save their dimensions
    
    * Reworked avatars. LEss reflows due to image dimensions. Smoother loading animation that doesn't wait for all images. Progressive enhanced
    
    * Add standardised lazy loading to all images
    
    * Set height on badges to avoid page reflows
    
    * Add node version specification in .nvmrc to get netlify up to date
    
    * Move avatars javascript to external file for better development experience
    
    Co-authored-by: Peter Müller <munter@fumle.dk>
    boneskull and Munter authored May 22, 2020
    Copy the full SHA
    12b130b View commit details

Commits on May 23, 2020

  1. Copy the full SHA
    1a2e693 View commit details
  2. Release v7.2.0

    craigtaub committed May 23, 2020
    Copy the full SHA
    283b11e View commit details

Commits on May 26, 2020

  1. renamed smoke test

    - add notes about what it is intended to do, and what it cannot do
    
    Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
    boneskull committed May 26, 2020
    Copy the full SHA
    6d60eb0 View commit details

Commits on Jun 1, 2020

  1. add support for running tests in parallel mode

    * add support for running tests in parallel mode
    
    > (this PR depends on most other PRs linked to #4198, so they should be merged first; documentation will be in another PR)
    
    This PR adds support for running test files in parallel via `--parallel`.  For many cases, this should "just work."
    
    When the `--parallel` flag is supplied, Mocha will swap out the default `Runner` (`lib/nodejs/runner.js`) for `ParallelBufferedRunner` (`lib/nodejs/parallel-buffered-runner.js`).
    
    `ParallelBufferedRunner` _extends_ `Runner`.  `ParallelBufferedRunner#run()` is the main point of extension.  Instead of executing the tests in serial, it will create a pool of worker processes (not worker _threads_) based on the maximum job count (`--jobs`; defaults to `<number of CPU cores> - 1`).  Both `ParallelBufferedRunner` and the `worker` module consume the abstraction layer, [workerpool](https://npm.im/workerpool).
    
    `ParallelBufferedRunner#run()` does _not_ load the test files, unlike `Runner#run()`.  Instead, it has a list of test files, and puts these into an async queue.  The `EVENT_RUN_BEGIN` event is then emitted.  As files enter the queue, `ParallelBufferedRunner#run()` tells `workerpool` to execute the `run()` function of the pool.  `workerpool` then launches as many worker processes are needed--up to the maximum--and executes the `run()` function with a single filepath and any options for a `Mocha` instance.
    
    The first time `lib/nodejs/worker.js` is invoked, it will "bootstrap" itself, by handling `--require`'d modules and validating the UI.  Note that _reporter validation_ does not occur.  Once bootstrapped, it instantiate `Mocha`, add the single file, swap any reporter out for the `ParallelBuffered` reporter (`lib/nodejs/reporters/parallel-buffered.js`) then execute `Mocha#run()`, which invokes `Runner#run()`.
    
    The `ParallelBuffered` reporter listens for events emitting from the `Runner` instance, like a reporter usually does.  But instead of outputting to the console, it buffers the events in a queue.  Once the file has completed running, the queue is drained: the events collected are (trivially) serialized for transmission back to the main process.  `ParallelBufferedRunner#run()` receives the list of events, trivially _deserializes_ them, and re-emits the events to whatever the chosen reporter is (e.g., the `spec` reporter).  In this way, the reporters don't know that the tests were run in parallel.  Practically, the user will see reporter output in "chunks" instead of the "stream" of results they usually expect.  This method ensures that while the test files run in a nondeterministic order, the reporter output will be deterministic for any given test file.
    
    Once the result (the queue of events) has been returned to the main process, the worker process stays open, but waits for further instruction.  If there are more files in `ParallelBufferedRunner#run()`'s queue, `workerpool` will instruct the worker to take the next file from the list, and so on, and so forth.  When all files have executed, the pool terminates, the `EVENT_RUN_END` event is emitted, and the reporter handles it.
    
    Note that exclusive tests ("only") cannot work in parallel mode, because we do not load all files up-front.
    
    > (this section is pasted from the documentation with minimal edits)
    
    ### Caveats: Reporters
    
    Due to the nature of the following reporters, they cannot work when running tests in parallel:
    
    - `markdown`
    - `progress`
    - `json-stream`
    
    These reporters expect Mocha to know _how many tests it plans to run_ before execution. This information is unavailable in parallel mode, as test files are loaded only when they are about to be run.
    
    ### Caveats: Buffered Output
    
    In serial mode, tests results will "stream" as they occur. In parallel mode, reporter output is _buffered_; reporting will occur after each file is completed. In practice, the reporter output will appear in "chunks" (but will otherwise be identical).
    
    ### Caveats: Nondeterminism
    
    In parallel mode, we have no guarantees about the order in which test files will be run--or what process runs them--as it depends on the execution times of the test files.
    
    Because of this, the following options _cannot be used_ in parallel mode:
    
    - `--file`
    - `--sort`
    - `--delay`
    
    Because running tests in parallel mode uses more system resources at once, the OS may take extra time to schedule and complete some operations. For this reason, test timeouts may need to be increased either globally or otherwise.
    
    ### Caveats: Other Impacted Options
    
    When used with `--bail` (or `this.bail()`) to exit after the first failure, it's likely other tests will be running at the same time. Mocha must shut down its worker processes before exiting.
    
    Likewise, subprocesses may throw uncaught exceptions. When used with `--allow-uncaught`, Mocha will "bubble" this exception to the main process, but still must shut down its processes.
    
    `--forbid-only` does not work in parallel mode, for a similar reason to the unsupported reporters.
    
    > _NOTE: This only applies to test files run parallel mode_.
    
    ### Caveats: Root Hooks
    
    A _root hook_ is a hook in a test file which is _not defined_ within a suite. An example using the `bdd` interface:
    
    ```js
    // test/setup.js
    beforeEach(function() {
      doMySetup();
    });
    
    afterEach(function() {
      doMyTeardown();
    });
    ```
    
    When run (in the default "serial" mode) via `mocha --file "./test/setup.js" "./test/**/*.spec.js"`, `setup.js` will be executed _first_, and install the two hooks shown above for every test found in `./test/**/*.spec.js`.
    
    **When Mocha runs in parallel mode, test files do not share the same process.** Consequently, a root hook defined in test file _A_ won't be present in test file _B_.
    
    There are a (minimum of) two workarounds for this:
    
    1. `require('./setup.js')` or `import './setup.js'` at the top of every test file. Best avoided for those averse to boilerplate.
    1. _Recommended_: Define root-level hooks in a required file, using the new (also as of VERSION) Root Hook Plugin system.
    
    ### Caveats: Node.js Only, For Now
    
    Parallel mode is only available in Node.js.
    
    ### Migration Checklist
    
    If you find your tests don't work properly when run with `--parallel`, either shrug and move on, or use this handy-dandy checklist to get things working:
    
    - ✅ Ensure you are using a supported reporter.
    - ✅ Ensure you are not using other unsupported flags.
    - ✅ Double-check your config file; options set in config files will be merged with any command-line option.
    - ✅ Look for root-level hooks in your tests. Move them into a root hook plugin.
    - ✅ Do any assertion, mock, or other test libraries you're consuming use root hooks? They may need to be migrated for compatibility with parallel mode.
    - ✅ If tests are unexpectedly timing out, you may need to increase the default test timeout (via `--timeout`)
    - ✅ Ensure your tests do not depend on being run in a specific order.
    - ✅ Ensure your tests clean up after themselves; remove temp files, handles, sockets, etc. Don't try to share state or resources between test files.
    
    ### About Parallelism
    
    Some types of tests are _not_ so well-suited to run in parallel. For example, extremely timing-sensitive tests, or tests which make I/O requests to a limited pool of resources (such as opening ports, or automating browser windows, hitting a test DB, or remote server, etc.).
    
    Free-tier cloud CI services may not provide a suitable multi-core container or VM for their build agents. Regarding expected performance gains in CI: your mileage may vary. It may help to use a conditional in a `.mocharc.js` to check for `process.env.CI`, and adjust the job count as appropriate.
    
    It's unlikely (but not impossible) to see a performance gain from a job count _greater than_ the number of available CPU cores. That said, _play around with the job count_--there's no one-size-fits all, and the unique characteristics of your tests will determine the optimal number of jobs; it may even be that fewer is faster!
    
    ### Change Details
    
    - updated signal handling in `bin/mocha` to a) better work with Windows, and b) work properly with `--parallel` to avoid leaving zombie workers
    - docstrings in `lib/nodejs/cli/collect-files.js`
    - refactors in `lib/nodejs/cli/run-helpers.js` and `lib/nodejs/cli/watch-run.js`.  We now have four methods:
        - `watchRun()` - serial + watch
        - `singleRun()` - serial
        - `parallelWatchRun()` - parallel + watch
        - `parallelRun()` - parallel
    - `lib/nodejs/cli/run.js` and `lib/nodejs/cli/run-option-metadata.js`: additions for new options and checks for incompatibility
    - add `lib/nodejs/reporters/buffered.js` (`ParallelBuffered`); this reporter is _not_ re-exported in `Mocha.reporters`, since it should only be invoked internally.
    - tweak `landing` reporter to avoid referencing `Runner#total`, which is incompatible with parallel mode.  It didn't need to do so in the first place!
    - the `tap` reporter now outputs the plan at the _end_ instead of at the beginning (avoiding a call to `Runner#grepTotal()`, which is incompatible with parallel mode).  This is within spec, so should not be a breaking change.
    - add `lib/nodejs/parallel-buffered-runner.js` (`ParallelBufferedRunner`); subclass of `Runner` which overrides the `run()` method.
        - There's a little custom finite state machine in here.  didn't want to pull in a third-party module, but we should consider doing so if we use FSM's elsewhere.
        - when `DEBUG=mocha:parallel*` is in the env, this module will output statistics about the worker pool every 5s
        - the `run()` method looks a little weird because I wanted to use `async/await`, but the method it is overriding (`Runner#run`) is _not_ `async`
        - traps `SIGINT` to gracefully terminate the pool
        - pulls in [promise.allsettled](https://npm.im/promise.allsettled) polyfill to handle workers that may have rejected with uncaught exceptions
        - "bail" support is best-effort.
        - the `ABORTING` state is only for interruption via `SIGINT` or if `allowUncaught` is true and we get an uncaught exception
    - `Hook`, `Suite`, `Test`: add a `serialize()` method.  This pulls out the most relevant information about the object for transmission over IPC.  It's called by worker processes for each event received by its `Runner`; event arguments (e.g., `test` or `suite`) are serialized in this manner.  Note that this _limits what reporters have access to_, which may break compatibility with third-party reporters that may use information that is missing from the serialized object.  As those cases arise, we can add more information to the serialized objects (in some cases).  The `$$` convention tells the _deserializer_ to turn the property into a function which returns the passed value, e.g., `test.fullTitle()`.
    - `lib/nodejs/mocha.js`:
        - refactor `Mocha#reporter` for nicer parameter & variable names
        - rename `loadAsync` to `lazyLoadFiles`, which is more descriptive, IMO.  It's a private property, so should not be a breaking change.
        - Constructor will dynamically choose the appropriate `Runner`
    - `lib/nodejs/runner.js`: `ParallelBufferedRunner` needs the options from `Mocha#options`, so I updated the parent method to define the parameter.  It is unused here.
    - add `lib/nodejs/serializer.js`: on the worker process side, manages event queue serialization; manages deserialization of the event queue in the main process.
        - I spent a long time trying to get this working.  We need to account for things like `Error` instances, with their stack traces, since those can be event arguments (e.g., `EVENT_TEST_FAIL` sends both a `Test` and the `Error`).  It's impossible to serialize circular (self-referential) objects, so we need to account for those as well.
        - Not super happy with the deserialization algorithm, since it's recursive, but it shouldn't be too much of an issue because the serializer won't output circular structures.
        - Attempted to avoid prototype pollution issues
        - Much of this works by mutating objects, mostly because it can be more performant.  The code can be changed to be "more immutable", as that's likely to be easier to understand, if it doesn't impact performance too much.  We're serializing potentially very large arrays of stuff.
        - The `__type` prop is a hint for the deserializer.  This convention allows us to re-expand plain objects back into `Error` instances, for example.  You can't send an `Error` instance over IPC!
    - add `lib/nodejs/worker.js`:
        - registers its `run()` function with `workerpool` to be called by main process
        - if `DEBUG=mocha:parallel*` is set, will output information (on an interval) about long-running test files
        - afaik the only way `run()` can reject is if `allowUncaught` is true or serialization fails
        - any user-supplied `reporter` value is replaced with the `ParallelBuffered` reporter.  thus, reporters are not validated.
        - the worker uses `Runner`, like usual.
    - tests:
        - see `test/integration/options/parallel.spec.js` for the interesting stuff
        - upgrade `unexpected` for "to have readonly property" assertion
        - upgrade `unexpected-eventemitter` for support async function support
        - integration test helpers allow Mocha's developers to use `--bail` and `--parallel`, but will default to `--no-bail` and `--no-parallel`.
        - split some node-specific tests out of `test/unit/mocha.spec.js` into `test/node-unit/mocha.spec.js`
        - add some missing coverage in `test/node-unit/worker.spec.js`
    - etc:
        - update `.eslintrc.yml` for new Node-only files
        - increase default timeout to `1000` (also seen in another PR) and use `parallel` mode by default in `.mocharc.yml`
        - run node unit tests _in serial_ as sort of a smoke test, as otherwise all our tests would be run in parallel
        - karma, browserify: ignore files for parallel support
        - force color output in CI. this is nice on travis, but ugly on appveyor.  either way, it's easier to read than having no color
        - move non-CLI-related node-specific files into `lib/nodejs/nodejs/`
        - correct some issues with APIs not marked `@private`
        - add some istanbul directives to ignore some debug statements
        - add `utils.isBrowser()` for easier mocking of a `process.browser === true` situation
        - add `createForbiddenExclusivityError()`
    
    Ref: #4198
    
    Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
    boneskull committed Jun 1, 2020
    Copy the full SHA
    2078c32 View commit details
  2. Support --require of ESM; closes #4281 (#4304)

    * Support --require of ESM; closes #4281
    Allow files/modules specified in `--require` to be ESM.
    
    CommonJS loading is still supported and the default.
    
    * Conditionally generate url for import
    Windows compatible
    
    * Add tests for --require ESM
    As both .mjs and type=module (combined with cjs for good measure).
    
    Updated linter to allow tests to use spread operator (ecmaVersion 2018)
    
    Allow --require'd module to be an object, or "module"
    
    * Revert change to eslintrc, use mocha to pass experimental flag
    
    * Replace type() -> typeof
    Add truthy check to handle null edge case
    
    type(ES Module) => "module", but we treat it the same as an object
    
    * Remove doc limitation for --require ESM
    
    * Add note to --require docs about ESM support
    JacobLey authored Jun 1, 2020
    Copy the full SHA
    273dbbb View commit details

Commits on Jun 2, 2020

  1. add docs for parallel and root hooks

    > this PR needs the changes from the `boneskull/issue/2839-11ty-changes` branch
    boneskull committed Jun 2, 2020
    Copy the full SHA
    63eb80b View commit details

Commits on Jun 5, 2020

  1. fix bad error message when incorrectly using ESM

    - re-enable parallel-mode root hook plugin tests
    - refactor root hook plugin tests to avoid flake
    
    Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
    boneskull committed Jun 5, 2020
    Copy the full SHA
    9881ace View commit details
Showing 356 changed files with 58,454 additions and 21,853 deletions.
11 changes: 11 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node >= 14
last 2 Chrome versions
last 2 Edge versions
last 2 Firefox versions
last 2 Safari versions
last 2 Opera versions
unreleased Chrome versions
unreleased Edge versions
unreleased Firefox versions
unreleased Safari versions
unreleased Opera versions
22 changes: 18 additions & 4 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
'use strict';

module.exports = function(eleventyConfig) {
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(
require('@11ty/eleventy-plugin-inclusive-language'),
{
words:
'simply,obviously,basically,of course,clearly,everyone knows,however,easy'
}
);

eleventyConfig.addPassthroughCopy('docs/css');
eleventyConfig.addPassthroughCopy('docs/js');
eleventyConfig.addPassthroughCopy('docs/images');
eleventyConfig.addPassthroughCopy('docs/CNAME');
eleventyConfig.addPassthroughCopy('docs/_headers');
eleventyConfig.addPassthroughCopy('docs/favicon.ico');

eleventyConfig.addPassthroughCopy('docs/example');
eleventyConfig.addPassthroughCopy('docs/api/images');
eleventyConfig.addPassthroughCopy('docs/api/scripts');
eleventyConfig.addPassthroughCopy('docs/api/styles');

/* Markdown Plugins */
const markdown = require('markdown-it')({
html: true,
linkify: true
linkify: true,
typographer: true
});

markdown.use(require('markdown-it-anchor'), {
@@ -31,13 +42,16 @@ module.exports = function(eleventyConfig) {

markdown.use(require('markdown-it-prism'));

markdown.use(require('markdown-it-emoji'));

eleventyConfig.setLibrary('md', markdown);

eleventyConfig.setUseGitIgnore(false);

return {
passthroughFileCopy: true,
dir: {
input: 'docs',
includes: '_includes',
output: 'docs/_site'
}
};
8 changes: 7 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
coverage/
mocha.js
mocha.js.map
*.fixture.js
docs/
docs/_site
docs/api
docs/_dist
docs/example
out/
!bin/mocha.js
!lib/mocha.js
test/integration/fixtures
!.*.js
*.min.js
42 changes: 24 additions & 18 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -5,38 +5,45 @@ extends:
env:
node: true
browser: true
es6: true
parserOptions:
ecmaVersion: 5
ecmaVersion: 2018
ecmaFeatures:
jsx: false
sourceType: script
rules:
no-var: 0
strict:
- error
- safe
overrides:
- files:
- scripts/**/*.js
- package-scripts.js
- karma.conf.js
- .wallaby.js
- .eleventy.js
- bin/*
- lib/cli/**/*.js
- test/node-unit/**/*.js
- test/integration/options/watch.spec.js
- test/integration/helpers.js
- lib/growl.js
parserOptions:
ecmaVersion: 2017
- 'docs/js/**/*.js'
env:
node: false
- files:
- '.eleventy.js'
- '.wallaby.js'
- 'package-scripts.js'
- 'karma.conf.js'
- 'bin/*'
- 'docs/_data/**/*.js'
- 'lib/cli/**/*.js'
- 'lib/nodejs/**/*.js'
- 'scripts/**/*.js'
- 'test/**/*.js'
- 'test/node-unit/**/*.js'
env:
browser: false
- files:
- esm-utils.js
- lib/nodejs/esm-utils.js
- rollup.config.js
- scripts/pick-from-package-json.js
parserOptions:
ecmaVersion: 2018
sourceType: module
parser: babel-eslint
requireConfigFile: false # for @babel/eslint-parser
parser: '@babel/eslint-parser'
env:
browser: false
- files:
@@ -79,11 +86,10 @@ overrides:
# disallow property access of `global.<timer>.*`
- selector: '*[object.object.name=global][object.property.name=/(Date|(set|clear)(Timeout|Immediate|Interval))/]:expression'
message: *GH-237

- files:
- test/**/*.mjs
parserOptions:
ecmaVersion: 2017
ecmaVersion: 2018
sourceType: module

- files:
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -91,4 +91,4 @@ For reporting issues in spaces managed by the OpenJS Foundation, for example, re
The OpenJS Foundation maintains a Code of Conduct Panel (CoCP). This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled. In order to escalate to the CoCP send an email to `"coc-escalation@lists.openjsf.org`.

For more information, refer to the full
[Code of Conduct governance document](https://github.com/openjs-foundation/bootstrap/blob/master/proposals/stage-1/CODE_OF_CONDUCT/FOUNDATION_CODE_OF_CONDUCT_REQUIREMENTS.md).
[Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/master/FOUNDATION_CODE_OF_CONDUCT_REQUIREMENTS.md).
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ Follow these steps to get going. If you are having trouble, don't be afraid to [

> PRO TIP: After `npm install`, run `npm start` to see a list of commands which can be run with `npm start <command>` (powered by [nps](https://npm.im/nps)).
1. [Install Node.js 8.x or newer](https://nodejs.org/en/download/).
1. [Install Node.js 14 LTS or newer with npm@7+](https://nodejs.org/en/download/).
- If you're new to installing Node, a tool like [nvm](https://github.com/creationix/nvm#install-script) can help you manage multiple version installations.
- You will need [Google Chrome](https://www.google.com/chrome/) to run browser-based tests locally.
1. Follow [Github's documentation](https://help.github.com/articles/fork-a-repo/) on setting up Git, forking and cloning.
@@ -58,7 +58,7 @@ Follow these steps to get going. If you are having trouble, don't be afraid to [
- Keep your PR focused. Don't fix two things at once; don't upgrade dependencies unless necessary.
1. Before committing, run `npm start test`.
- This will run both Node.js-based and browser-based tests.
- Ultimately, your pull request will be built on our continuous integration servers ([Travis CI](https://travis-ci.org/mochajs/mocha) and [AppVeyor](https://ci.appveyor.com/project/boneskull/mocha)). The first step to ensuring these checks pass is to test on your own machine.
- Ultimately, your pull request will be built on our continuous integration servers ([GitHub Actions](https://github.com/mochajs/mocha/actions?query=workflow%3A%22Tests%22)). The first step to ensuring these checks pass is to test on your own machine.
- A coverage check will be sent to [Coveralls](https://coveralls.io/github/mochajs/mocha). **A drop in code coverage % is considered a failed check**.
1. Commit your changes.
- Use a brief message on the first line, referencing a relevant issue (e.g. `closes #12345`).
@@ -91,7 +91,7 @@ _Excellent._ Here's how:
- **Can you write ~~good~~ well?** The [documentation](https://mochajs.org) almost always needs some love. See the [doc-related issues](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3Adocumentation).
- **Design your thing?** [Our site](https://mochajs.org) needs your magic touch.
- **Familiar with Mocha's codebase?** We could use your help triaging issues and/or reviewing pull requests. Please contact an [org member](https://github.com/orgs/mochajs/people), and we'll chat.
- **Want to build our community?** Mocha has a _lot_ of users. We could use your help bringing everyone together in peace and harmony. Please contact an [org member](https://github.com/mochajs/people).
- **Want to build our community?** Mocha has a _lot_ of users. We could use your help bringing everyone together in peace and harmony. Please contact an [org member](https://github.com/orgs/mochajs/people).
- **You can sell dirt to worms?** Let's raise Mocha's profile in the JavaScript and OSS communities. Please contact an [org member](https://github.com/orgs/mochajs/people)!
- **Wait--you write unit tests for _fun_?** A PR which increases coverage is unlikely to be turned down.
- **Are you experienced?** :guitar: If you're a seasoned Mocha user, why not help answer some questions in the [main chat room](https://gitter.im/mochajs/mocha)?
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ Place an `x` between the square brackets on the lines below for every satisfied
- [ ] Checked that your issue hasn't already been filed by cross-referencing [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20)
- [ ] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- [ ] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- [ ] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: `node node_modules/.bin/mocha --version`(Local) and `mocha --version`(Global). We recommend that you _not_ install Mocha globally.
- [ ] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: `node_modules/.bin/mocha --version`(Local) and `mocha --version`(Global). We recommend that you _not_ install Mocha globally.

### Description

@@ -51,7 +51,7 @@ Scrub if needed so as not to reveal passwords, etc.

<!-- If applicable, please specify: -->

- The output of `mocha --version` and `node node_modules/.bin/mocha --version`:
- The output of `mocha --version` and `node_modules/.bin/mocha --version`:
- The output of `node --version`:
- Your operating system
- name and version:
36 changes: 0 additions & 36 deletions .github/stale.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/browser-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Browser Tests for forked PRs
'on':
pull_request_target:
types:
- labeled

jobs:
test-browser:
# TODO: configure to retain build artifacts in `.karma/` dir
name: 'Browser Tests'
timeout-minutes: 20
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'run-browser-test')
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: 'Cache node_modules'
uses: actions/cache@v3
with:
path: '~/.npm'
key: "ubuntu-latest-node-full-v16-${{ hashFiles('**/package-lock.json') }}"
restore-keys: |
ubuntu-latest-node-full-v16-
- name: Install Dependencies
run: npm ci
- name: Run Browser Tests
run: npm start test.browser
env:
SAUCE_USERNAME: '${{secrets.SAUCE_USERNAME}}'
SAUCE_ACCESS_KEY: '${{secrets.SAUCE_ACCESS_KEY}}'
- name: remove 'run-browser-test' label
uses: buildsville/add-remove-label@v1
if: ${{ always() }}
with:
token: ${{secrets.GITHUB_TOKEN}}
label: run-browser-test
type: remove
20 changes: 20 additions & 0 deletions .github/workflows/delete-runs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Delete workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days'
required: true
default: 180

jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: 10
Loading