Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure mocha -h consistently shows help #2746

Merged
merged 6 commits into from Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/options.js
Expand Up @@ -17,6 +17,10 @@ module.exports = getOptions;
*/

function getOptions () {
if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
return;
}

var optsPath = process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
Expand Down
1 change: 1 addition & 0 deletions test/integration/fixtures/options/help/test/mocha.opts
@@ -0,0 +1 @@
foo
27 changes: 23 additions & 4 deletions test/integration/helpers.js
Expand Up @@ -110,15 +110,34 @@ module.exports = {
/**
* regular expression used for splitting lines based on new line / dot symbol.
*/
splitRegExp: new RegExp('[\\n' + baseReporter.symbols.dot + ']+')
splitRegExp: new RegExp('[\\n' + baseReporter.symbols.dot + ']+'),

/**
* Invokes the mocha binary. Accepts an array of additional command line args
* to pass. The callback is invoked with the exit code and output. Optional
* current working directory as final parameter.
*
* In most cases runMocha should be used instead.
*
* Example response:
* {
* code: 1,
* output: '...'
* }
*
* @param {Array<string>} args - Extra args to mocha executable
* @param {Function} done - Callback
* @param {string} cwd - Current working directory for mocha run, optional
*/
invokeMocha: invokeMocha
};

function invokeMocha (args, fn) {
function invokeMocha (args, fn, cwd) {
var output, mocha, listener;

output = '';
args = [path.join('bin', 'mocha')].concat(args);
mocha = spawn(process.execPath, args);
args = [path.join(__dirname, '..', '..', 'bin', 'mocha')].concat(args);
mocha = spawn(process.execPath, args, { cwd: cwd });

listener = function (data) {
output += data;
Expand Down
12 changes: 12 additions & 0 deletions test/integration/options.spec.js
@@ -1,7 +1,9 @@
'use strict';

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

describe('options', function () {
Expand Down Expand Up @@ -386,4 +388,14 @@ describe('options', function () {
it('should not force exit after root suite completion', runExit(false, 'disabled'));
});
});

describe('--help', function () {
it('works despite the presence of mocha.opts', function (done) {
directInvoke(['-h'], function (error, result) {
if (error) { return done(error); }
expect(result.output).to.contain('Usage:');
done();
}, path.join(__dirname, 'fixtures', 'options', 'help'));
});
});
});