lib/cli

Contains CLI entry point and public API for programmatic usage in Node.js.

  • Option parsing is handled by yargs.
  • If executed via node, this module will run main().
Source:

Methods

(static) loadOptions(argvopt) → {external:yargsParser.Arguments}

Parses options read from .mocharc.* and package.json.

Source:

Priority list:

  1. Command-line args
  2. MOCHA_OPTIONS environment variable.
  3. RC file (.mocharc.c?js, .mocharc.ya?ml, mocharc.json)
  4. mocha prop of package.json
  5. default configuration (lib/mocharc.json)

If a "one-and-done" option is present in the argv array, no external config files will be read.

Parameters:
NameTypeAttributesDescription
argvstring | Array:.<string:><optional>

Arguments to parse

Returns:

Parsed args from everything

Type
external:yargsParser.Arguments

(static) loadPkgRc(argsopt) → {external:yargsParser.Arguments|void}

Source:

Given path to package.json in args.package, attempt to load config from mocha prop.

Parameters:
NameTypeAttributesDescription
argsObject<optional>

Arguments object

Properties
NameTypeAttributesDescription
configstring | boolean<optional>

Path to package.json or false to skip

Returns:

Parsed config, or nothing if args.package is false

Type
external:yargsParser.Arguments | void

(static) loadRc(argsopt) → {external:yargsParser.Arguments|void}

Source:

Given path to config file in args.config, attempt to load & parse config file.

Parameters:
NameTypeAttributesDescription
argsObject<optional>

Arguments object

Properties
NameTypeAttributesDescription
configstring | boolean<optional>

Path to config file or false to skip

Returns:

Parsed config, or nothing if args.config is false

Type
external:yargsParser.Arguments | void

(static) lookupFiles(filepath, extensionsopt, recursiveopt) → {Array:.<string:>}

Source:

Filenames are returned in traversal order by the OS/filesystem.
Make no assumption that the names will be sorted in any fashion.

Parameters:
NameTypeAttributesDefaultDescription
filepathstring

Base path to start searching from.

extensionsArray:.<string:><optional>
[]

File extensions to look for.

recursiveboolean<optional>
false

Whether to recurse into subdirectories.

Throws:
  • if no files match pattern.

    Type
    Error
  • if filepath is directory and extensions not provided.

    Type
    TypeError
Returns:

An array of paths.

Type
Array:.<string:>

(static) main(argv, mochaArgsopt)

Mocha's main command-line entry-point.

Source:
Parameters:
NameTypeAttributesDescription
argvArray:.<string:>

Array of arguments to parse, or by default the lovely process.argv.slice(2)

mochaArgsobject<optional>

Object of already parsed Mocha arguments (by bin/mocha)