Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hswolff committed Jan 4, 2018
1 parent 29cb2fb commit a12c310
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
24 changes: 10 additions & 14 deletions bin/_mocha
Expand Up @@ -78,6 +78,14 @@ const exit = code => {
*/
const list = str => str.split(/ *, */);

/**
* Parse multiple flag.
*/
const collect = (val, memo) => {
memo.push(val);
return memo;
};

/**
* Hide the cursor.
*/
Expand Down Expand Up @@ -120,12 +128,6 @@ const play = (arr, interval) => {

let files = [];

/**
* File args.
*/

let fileArgs = [];

/**
* Globals.
*/
Expand Down Expand Up @@ -206,7 +208,7 @@ program
.option('--allow-uncaught', 'enable uncaught errors to propagate')
.option('--forbid-only', 'causes test marked with only to fail the suite')
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
.option('--file <file>', 'include a file to be ran during the suite', list, []);
.option('--file [file]', 'include a file to be ran during the suite', collect, []);

program._name = 'mocha';

Expand Down Expand Up @@ -278,12 +280,6 @@ program.on('option:require', mod => {
requires.push(mod);
});

// --file

program.on('option:file', mod => {
fileArgs.push(mod);
});

// If not already done, load mocha.opts
if (!process.env.LOADED_MOCHA_OPTS) {
getOptions();
Expand Down Expand Up @@ -510,7 +506,7 @@ if (!files.length) {
}

// resolve
fileArgs = fileArgs.map(path => resolve(path));
let fileArgs = program.file.map(path => resolve(path));
files = files.map(path => resolve(path));

if (program.sort) {
Expand Down
21 changes: 13 additions & 8 deletions docs/index.md
Expand Up @@ -25,17 +25,17 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js](https://n
- [maps uncaught exceptions to the correct test case](#browser-specific-methods)
- [async test timeout support](#delayed-root-suite)
- [test retry support](#retry-tests)
- [test-specific timeouts](#test-level)
- [test-specific timeouts](#test-level)
- [growl notification support](#mochaopts)
- [reports test durations](#test-duration)
- [highlights slow tests](#dot-matrix)
- [file watcher support](#min)
- [global variable leak detection](#--check-leaks)
- [optionally run tests that match a regexp](#-g---grep-pattern)
- [file watcher support](#min)
- [global variable leak detection](#--check-leaks)
- [optionally run tests that match a regexp](#-g---grep-pattern)
- [auto-exit to prevent "hanging" with an active loop](#--exit----no-exit)
- [easily meta-generate suites](#markdown) & [test-cases](#list)
- [mocha.opts file support](#mochaopts)
- clickable suite titles to filter test execution
- clickable suite titles to filter test execution
- [node debugger support](#-d---debug)
- detects multiple calls to `done()`
- [use any assertion library you want](#assertions)
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('hooks', function() {
});
```

> Tests can appear before, after, or interspersed with your hooks. Hooks will run in the order they are defined, as appropriate; all `before()` hooks run (once), then any `beforeEach()` hooks, tests, any `afterEach()` hooks, and finally `after()` hooks (once).
> Tests can appear before, after, or interspersed with your hooks. Hooks will run in the order they are defined, as appropriate; all `before()` hooks run (once), then any `beforeEach()` hooks, tests, any `afterEach()` hooks, and finally `after()` hooks (once).
### Describing Hooks

Expand Down Expand Up @@ -529,9 +529,9 @@ it('should only test in the correct environment', function() {
});
```

The above test will be reported as [pending](#pending-tests). It's also important to note that calling `this.skip()` will effectively *abort* the test.
The above test will be reported as [pending](#pending-tests). It's also important to note that calling `this.skip()` will effectively *abort* the test.

> *Best practice*: To avoid confusion, do not execute further instructions in a test or hook after calling `this.skip()`.
> *Best practice*: To avoid confusion, do not execute further instructions in a test or hook after calling `this.skip()`.
Contrast the above test with the following code:

Expand Down Expand Up @@ -737,6 +737,7 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass
--debug-brk enable node's debugger breaking on the first line
--globals <names> allow the given comma-delimited global [names]
--es_staging enable all staged features
--file <file> include a file to be ran during the suite [file]
--harmony<_classes,_generators,...> all node --harmony* flags are available
--preserve-symlinks Instructs the module loader to preserve symbolic links when resolving and caching modules
--icu-data-dir include ICU data
Expand Down Expand Up @@ -850,6 +851,10 @@ Specifies the test-case timeout, defaulting to 2 seconds. To override you may pa

Specify the "slow" test threshold, defaulting to 75ms. Mocha uses this to highlight test-cases that are taking too long.

### `--file <file>`

Add a file you want included first in a test suite. This is useful if you have some generic setup code that must be included within the test suite. The file passed is not effected by any other flags (`--recursive` or `--sort` have no effect). Accepts multiple `--file` flags to include multiple files.

### `-g, --grep <pattern>`

The `--grep` option when specified will trigger mocha to only run tests matching the given `pattern` which is internally compiled to a `RegExp`.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fixtures/options/file-alpha.fixture.js
Expand Up @@ -2,7 +2,7 @@

describe('alpha', function () {
it('should be executed first', function () {
if (global.beta) {
if (global.beta !== undefined) {
throw new Error('alpha was not executed first');
}
});
Expand Down
11 changes: 6 additions & 5 deletions test/integration/options.spec.js
Expand Up @@ -2,9 +2,10 @@

var path = require('path');
var assert = require('assert');
var run = require('./helpers').runMochaJSON;
var directInvoke = require('./helpers').invokeMocha;
var resolvePath = require('./helpers').resolveFixturePath;
var helpers = require('./helpers');
var run = helpers.runMochaJSON;
var directInvoke = helpers.invokeMocha;
var resolvePath = helpers.resolveFixturePath;
var args = [];

describe('options', function () {
Expand Down Expand Up @@ -92,8 +93,8 @@ describe('options', function () {
});
});

describe.only('--file', function () {
before(function () {
describe('--file', function () {
beforeEach(function () {
args = ['--file', resolvePath('options/file-alpha.fixture.js')];
});

Expand Down

0 comments on commit a12c310

Please sign in to comment.