The tests in this directory are integration or end-to-end tests. Most of them spawn a mocha
process and inspect the result of STDOUT
and/or STDERR
.
cli
: Related to general CLI behavior; not necessarily command-line-flag specificfixtures
: Test file fixtures intended to be run via these tests. Usually have.fixture.js
extensionplugins
: Tests related to plugins (e.g., root hook plugins, global fixtures, etc.)options
: Tests for specific command-line flags
The helpers.js
module contains many functions to handle the common cases of spawning a Mocha process and other utilities. The important ones:
runMocha
/runMochaAsync
: spawns Mocha to run a fixture with the default reporter. Returns a parsedSummarizedResult
object containing information parsed from the reporter's epiloguerunMochaJSON
/runMochaJSONAsync
: spawns Mocha to run a fixture with ajson
reporter and parses the output; good for assertions about specific numbers and types of test results. Returns aJSONResult
objectinvokeMocha
/invokeMochaAsync
: spawns Mocha with the default reporter but does not parse its output; good for testing errors of the non-test-failure variety. Does not expect a fixture file path, but one can manually be provided. Preferred to test Mocha's output toSTDERR
. Returns aRawSummarizedResultObject
with the raw output and exit code, etc.resolveFixurePath
: a handy way to get the path to a fixture file. Required when usinginvokeMocha*
runMochaWatch*
: similar torunMocha*
, but runs Mocha in "watch" mode. Accepts a function which should trigger a rerun; the function should touch a file or perform some other filesystem operation. Forks instead of spawns on WindowsinvokeNode
: spawnsnode
instead ofmocha
; good for testing programmatic usage of Mocha by running a script which does this
RawResult
: an object containing propsargs
,code
,output
andcommand
SummarizedResult
: aRawResult
+ propspassing
,failing
andpending
JSONResult
: aRawResult
+ parsed output ofjson
reporter
By default, all of these helpers run with the following options:
--no-color
: it's easier to make assertions about output w/o having to deal w/ ANSI escape codes--no-bail
: overrides a configuration file w/bail: true
; providing--bail
to the arguments list will supress this (useful when testing--bail
!)--no-parallel
: overrides a configuration file w/parallel: true
; providing--parallel
to the arguments list will suppress this
DEBUG=mocha:test*
: will show debug output from tests & helpers, if anyMOCHA_TEST_KEEP_TEMP_DIRS=1
: does not automatically remove any temporary directories and files created by thecreateTempDir
helper. Use to manually debug problems when running fixtures in temp directories