Skip to content

Commit

Permalink
use yargs for option parsing and support config files
Browse files Browse the repository at this point in the history
- `-d` is no longer an alias for `--debug`
- `--grep` and `--fgrep` are now mutually exclusive
- The option formerly known as `--compilers` is now removed from Mocha
- `lib/template.html` moved to `lib/browser/template.html`
- An error is thrown if a path to `mocha.opts` is specified by the user and the file was not found

- `-gc` users should use `--gc-global`

- Public API method `getOptions()` in `bin/options.js` is deprecated and currently has no alternative
- Users of the `enableTimeouts` option of the `Mocha` constructor should use `timeout` instead.  Specify `false` for no timeout
- Users of the `useColors` option of the `Mocha` constructor should use `color` instead

- Mocha now supports JS, JSON, YAML, or `package.json`-based config.
- Any/all configuration, including `mocha.opts` can be used in addition to command-line arguments, and everything will be merged as applicable
- Node/V8 flag support:
  - Support of all available `node` flags on a *per-version* basis
  - Support of any V8 flag by prepending `--v8-` to the option
  - These are supported within `mocha.opts` or config files
- More flexible command-line parsing including negation of any boolean flag by prepending `--no-` to the name
- Better `--help`
- Descriptions of interfaces in `--help` text
- A useful `Mocha` constructor
- Debug-related flags (e.g., `--inspect`) now *imply* `--no-timeouts`

- Many bug fixes around CLI option handling, e.g., closes #3475
- Fixes #3363, #2576, #3570
- `--no-timeouts` works

- Added new, updated, or rewrote documentation for all non-self-explanatory options
- Updated usage text, TOC
- Added section on configuration
- Added example configuration files in `example/config/`

- Updated many dev deps, mostly within existing semver ranges
- Removed `commander`
- Added production deps:
  - ansi-colors - color terminal output
  - findup-sync - find package.json and other config files
  - js-yaml - parse YAML
  - log-symbols - visual symbols for success/fail etc.
  - node-environment-flags - per-version allowed Node.js env flags
  - object.assign - for IE11
  - strip-json-comments - allow comments in JSON config files
  - wide-align - terminal formatting
  - yargs - option parser
  - yargs-parser - for compatible, lightweight parsing of config files
  - yargs-unparser - for passing config to `bin/_mocha` from `bin/mocha`
  • Loading branch information
boneskull committed Dec 10, 2018
1 parent 924e63c commit 8673e02
Show file tree
Hide file tree
Showing 88 changed files with 7,959 additions and 8,067 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ overrides:
- karma.conf.js
- .wallaby.js
- bin/*
- lib/cli/**/*.js
- test/node-unit/**/*.js
parserOptions:
ecmaVersion: 6
env:
browser: no
- files:
- test/**/*.js
- test/**/*.{js,mjs}
env:
mocha: yes
globals:
Expand All @@ -37,4 +39,9 @@ overrides:
- doc/**/*.js
env:
node: no
- files:
- test/**/*.mjs
parserOptions:
ecmaVersion: 6
sourceType: module

7 changes: 7 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require: test/setup
ui: bdd
global:
- okGlobalA,okGlobalB
- okGlobalC
- callback*
timeout: 200
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ jobs:
env: null
before_install: true
install: npm install --production
# `--opts /dev/null` means "ignore test/mocha.opts"
script: ./bin/mocha --opts /dev/null --reporter spec test/sanity/sanity.spec.js

script: ./bin/mocha --no-config --reporter spec test/sanity/sanity.spec.js
cache:
directories:
- ~/.npm
Expand Down
25 changes: 17 additions & 8 deletions .wallaby.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@
module.exports = () => {
return {
files: [
'index.js', 'lib/**/*.js', 'test/setup.js', 'test/assertions.js',
'index.js',
'lib/**/*.{js,json}',
'test/setup.js',
'test/assertions.js',
{
pattern: 'test/node-unit/**/*.fixture.js',
instrument: false
}, {
},
{
pattern: 'test/unit/**/*.fixture.js',
instrument: false
}
},
'package.json',
'test/opts/mocha.opts',
'mocharc.yml'
],
filesWithNoCoverageCalculated: ['test/**/*.fixture.js'],
tests: [
'test/unit/**/*.spec.js', 'test/node-unit/**/*.spec.js'
filesWithNoCoverageCalculated: [
'test/**/*.fixture.js',
'test/setup.js',
'test/assertions.js'
],
tests: ['test/unit/**/*.spec.js', 'test/node-unit/**/*.spec.js'],
env: {
type: 'node',
runner: 'node'
},
workers: {recycle: true},
testFramework: {type: 'mocha', path: __dirname},
setup (wallaby) {
setup(wallaby) {
// running mocha instance is not the same as mocha under test,
// running mocha is the project's source code mocha, mocha under test is instrumented version of the source code
const runningMocha = wallaby.testFramework;
Expand All @@ -33,7 +42,7 @@ module.exports = () => {
// to make test/node-unit/color.spec.js pass, we need to run mocha in the project's folder context
const childProcess = require('child_process');
const execFile = childProcess.execFile;
childProcess.execFile = function () {
childProcess.execFile = function() {
let opts = arguments[2];
if (typeof opts === 'function') {
opts = {};
Expand Down
Loading

0 comments on commit 8673e02

Please sign in to comment.