Skip to content

Commit

Permalink
Try using the helpers to invoke Mocha; this will require using the cu…
Browse files Browse the repository at this point in the history
…rrent working directory, so make test/mocha.opts be available if necessary without overwriting existing one if any
  • Loading branch information
ScottFreeCode authored and Zarel committed Oct 17, 2017
1 parent cb6b159 commit 8621eb0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
19 changes: 18 additions & 1 deletion test/integration/helpers.js
Expand Up @@ -110,7 +110,24 @@ 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.
*
* 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
*/
invokeMocha: invokeMocha
};

function invokeMocha (args, fn) {
Expand Down
41 changes: 22 additions & 19 deletions test/integration/options.spec.js
@@ -1,10 +1,9 @@
'use strict';

var assert = require('assert');
var childProcess = require('child_process');
var fs = require('fs');
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 @@ -392,25 +391,29 @@ describe('options', function () {

describe('--help', function () {
before(function () {
fs.mkdirSync(path.resolve(__dirname, 'test-env'));
fs.mkdirSync(path.resolve(__dirname, 'test-env/test'));
fs.writeFileSync(path.resolve(__dirname, 'test-env/test/mocha.opts'), 'foo');
try {
fs.mkdirSync('test');
} catch (ignore) {}
try {
fs.writeFileSync('test/mocha.opts', 'foo', { flag: 'wx' });
} catch (ignore) {}
});
it('works despite the presence of mocha.opts', function () {
var mochaLoc = path.resolve(__dirname, '../../bin/mocha');
var output = '' + childProcess.execSync(mochaLoc + ' -h', {cwd: path.resolve(__dirname, 'test-env')});
expect(output).to.contain('Usage:');

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();
});
});

after(function () {
try {
fs.unlinkSync(path.resolve(__dirname, 'test-env/test/mocha.opts'));
} catch (e) {}
try {
fs.rmdirSync(path.resolve(__dirname, 'test-env/test'));
} catch (e) {}
try {
fs.rmdirSync(path.resolve(__dirname, 'test-env'));
} catch (e) {}
if (fs.readFileSync('test/mocha.opts').toString() === 'foo') {
fs.unlinkSync('test/mocha.opts');
try {
fs.rmdirSync('test');
} catch (ignore) {}
}
});
});
});

0 comments on commit 8621eb0

Please sign in to comment.