Skip to content

Commit

Permalink
Merge b6faee1 into 29b7615
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed May 31, 2019
2 parents 29b7615 + b6faee1 commit 175f886
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 184 deletions.
52 changes: 10 additions & 42 deletions bin/mocha
Expand Up @@ -9,7 +9,7 @@
* @private
*/

const {deprecate, warn} = require('../lib/utils');
const {deprecate} = require('../lib/utils');
const {spawn} = require('child_process');
const {loadOptions} = require('../lib/cli/options');
const {
Expand All @@ -20,7 +20,6 @@ const {
const unparse = require('yargs-unparser');
const debug = require('debug')('mocha:cli:mocha');
const {aliases} = require('../lib/cli/run-option-metadata');
const nodeEnv = require('node-environment-flags');

const mochaPath = require.resolve('./_mocha');
const mochaArgs = {};
Expand Down Expand Up @@ -64,51 +63,20 @@ Object.keys(opts).forEach(opt => {

// Native debugger handling
// see https://nodejs.org/api/debugger.html#debugger_debugger
// look for 'debug' or 'inspect' that would launch this debugger,
// look for 'inspect' or 'debug' that would launch this debugger,
// remove it from Mocha's opts and prepend it to Node's opts.
// also coerce depending on Node.js version.
// A deprecation warning will be printed by node, if applicable.
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
if (/^(debug|inspect)$/.test(mochaArgs._[0])) {
const command = mochaArgs._.shift();
disableTimeouts(command);
// don't conflict with inspector
['debug', 'inspect', 'debug-brk', 'inspect-brk']
.filter(opt => opt in nodeArgs || opt in mochaArgs)
.forEach(opt => {
warn(`command "${command}" provided; --${opt} ignored`);
delete nodeArgs[opt];
delete mochaArgs[opt];
});
nodeArgs._ = [
parseInt(
process.version
.slice(1)
.split('.')
.shift(),
10
) >= 8
? 'inspect'
: 'debug'
];
if (mochaArgs._) {
var i = mochaArgs._.indexOf('inspect');
i = i === -1 ? mochaArgs._.indexOf('debug') : i;
if (i > -1) {
const [command] = mochaArgs._.splice(i, 1);
disableTimeouts('inspect');
nodeArgs._ = [command];
}
}

// allow --debug to invoke --inspect on Node.js v8 or newer.
['debug', 'debug-brk']
.filter(opt => opt in nodeArgs && !nodeEnv.has(opt))
.forEach(opt => {
const newOpt = opt === 'debug' ? 'inspect' : 'inspect-brk';
warn(
`"--${opt}" is not available in Node.js ${
process.version
}; use "--${newOpt}" instead.`
);
nodeArgs[newOpt] = nodeArgs[opt];
mochaArgs.timeout = false;
debug(`--${opt} -> ${newOpt}`);
delete nodeArgs[opt];
});

// historical
if (nodeArgs.gc) {
deprecate(
Expand Down
14 changes: 7 additions & 7 deletions docs/index.md
Expand Up @@ -39,7 +39,7 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in
- [config file support](#-config-path)
- [mocha.opts file support](#-opts-path)
- clickable suite titles to filter test execution
- [node debugger support](#-debug-inspect-debug-brk-inspect-brk-debug-inspect)
- [node debugger support](#-inspect-inspect-brk-inspect)
- [detects multiple calls to `done()`](#detects-multiple-calls-to-done)
- [use any assertion library you want](#assertions)
- [extensible reporting, bundled with 9+ reporters](#reporters)
Expand Down Expand Up @@ -983,7 +983,7 @@ Note: A test that executes for _half_ of the "slow" time will be highlighted _in

### `--timeout <ms>, -t <ms>`

> _Update in v6.0.0: `--no-timeout` is implied when invoking Mocha using debug flags. It is equivalent to `--timeout 0`. `--timeout 99999999` is no longer needed._
> _Update in v6.0.0: `--no-timeout` is implied when invoking Mocha using inspect flags. It is equivalent to `--timeout 0`. `--timeout 99999999` is no longer needed._
Specifies the test case timeout, defaulting to two (2) seconds (2000 milliseconds). Tests taking longer than this amount of time will be marked as failed.

Expand Down Expand Up @@ -1174,15 +1174,15 @@ Use the _inverse_ of the match specified by `--grep` or `fgrep`.

Requires either `--grep` or `--fgrep` (but not both).

### `--debug, --inspect, --debug-brk, --inspect-brk, debug, inspect`
### `--inspect, --inspect-brk, inspect`

> _BREAKING CHANGE in v6.0.0; `-d` is no longer an alias for `--debug`._ > _Other updates in v6.0.0:_ > _In versions of Node.js implementing `--inspect` and `--inspect-brk`, `--debug` and `--debug-brk` are respectively aliases for these two options._ > _Likewise, `debug` (not `--debug`) is an alias for `inspect` (not `--inspect`) in Node.js versions where `debug` is deprecated._
> _BREAKING CHANGE in v7.0.0; `--debug` / `--debug-brk` are removed and `debug` is deprecated._
Enables Node.js' debugger or inspector.
Enables Node.js' inspector.

Use `--inspect` / `--inspect-brk` / `--debug` / `--debug-brk` to launch the V8 inspector for use with Chrome Dev Tools.
Use `--inspect` / `--inspect-brk` to launch the V8 inspector for use with Chrome Dev Tools.

Use `inspect` / `debug` to launch Node.js' internal debugger.
Use `inspect` to launch Node.js' internal debugger.

All of these options are mutually exclusive.

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/node-flags.js
Expand Up @@ -14,7 +14,7 @@ const unparse = require('yargs-unparser');
* @see {@link impliesNoTimeouts}
* @private
*/
const debugFlags = new Set(['debug', 'debug-brk', 'inspect', 'inspect-brk']);
const debugFlags = new Set(['inspect', 'inspect-brk']);

/**
* Mocha has historical support for various `node` and V8 flags which might not
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/run.js
Expand Up @@ -39,7 +39,7 @@ const GROUPS = {
CONFIG: 'Configuration'
};

exports.command = ['$0 [spec..]', 'debug [spec..]'];
exports.command = ['$0 [spec..]', 'inspect'];

exports.describe = 'Run tests with Mocha';

Expand Down
130 changes: 0 additions & 130 deletions test/integration/options/debug.spec.js

This file was deleted.

4 changes: 1 addition & 3 deletions test/node-unit/cli/node-flags.spec.js
Expand Up @@ -86,10 +86,8 @@ describe('node-flags', function() {
});

describe('impliesNoTimeouts()', function() {
it('should return true for debug/inspect flags', function() {
expect(impliesNoTimeouts('debug'), 'to be true');
it('should return true for inspect flags', function() {
expect(impliesNoTimeouts('inspect'), 'to be true');
expect(impliesNoTimeouts('debug-brk'), 'to be true');
expect(impliesNoTimeouts('inspect-brk'), 'to be true');
});
});
Expand Down

0 comments on commit 175f886

Please sign in to comment.