diff --git a/package-scripts.js b/package-scripts.js index 391b28be92..30e4294be1 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -115,7 +115,7 @@ module.exports = { integration: { script: test( 'integration', - '--timeout 10000 --slow 3750 "test/integration/*.spec.js"' + '--timeout 10000 --slow 3750 "test/integration/**/*.spec.js"' ), description: 'Run Node.js integration tests', hiddenFromHelp: true diff --git a/test/integration/helpers.js b/test/integration/helpers.js index b2e98434c7..af7490f7c4 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -167,7 +167,16 @@ module.exports = { */ resolveFixturePath: resolveFixturePath, - toJSONRunResult: toJSONRunResult + toJSONRunResult: toJSONRunResult, + + /** + * Given a regexp-like string, escape it so it can be used with the `RegExp` constructor + * @param {string} str - string to be escaped + * @returns {string} Escaped string + */ + escapeRegExp: function escapeRegExp(str) { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string + } }; /** diff --git a/test/integration/options/interfaces.spec.js b/test/integration/options/interfaces.spec.js new file mode 100644 index 0000000000..7c58b89d6f --- /dev/null +++ b/test/integration/options/interfaces.spec.js @@ -0,0 +1,37 @@ +'use strict'; + +var helpers = require('../helpers'); +var invokeMocha = helpers.invokeMocha; +var escapeRegExp = helpers.escapeRegExp; +var interfaces = require('../../../lib/mocha').interfaces; + +describe('--interfaces', function() { + it('should dump a list of all interfaces with descriptions', function(done) { + var expected = Object.keys(interfaces) + .filter(function(name) { + return /^[a-z]/.test(name); + }) + .map(function(name) { + return { + name: escapeRegExp(name), + description: escapeRegExp(interfaces[name].description) + }; + }); + + invokeMocha(['--interfaces'], function(err, result) { + if (err) { + return done(err); + } + + expect(result.code, 'to be', 0); + expected.forEach(function(ui) { + expect( + result.output, + 'to match', + new RegExp(ui.name + '\\s*-\\s*' + ui.description) + ); + }); + done(); + }); + }); +}); diff --git a/test/integration/options/reporter-option.spec.js b/test/integration/options/reporter-option.spec.js new file mode 100644 index 0000000000..50d84ca597 --- /dev/null +++ b/test/integration/options/reporter-option.spec.js @@ -0,0 +1,25 @@ +'use strict'; + +var runMocha = require('../helpers').runMocha; + +describe('--reporter-option', function() { + describe('when given options w/ invalid format', function() { + it('should display an error', function(done) { + runMocha( + 'passing.fixture.js', + ['--reporter-option', 'foo=bar=baz'], + function(err, res) { + if (err) { + return done(err); + } + expect(res, 'to have failed').and( + 'to contain output', + /invalid reporter option/i + ); + done(); + }, + 'pipe' + ); + }); + }); +}); diff --git a/test/integration/options/reporters.spec.js b/test/integration/options/reporters.spec.js new file mode 100644 index 0000000000..650c65edcd --- /dev/null +++ b/test/integration/options/reporters.spec.js @@ -0,0 +1,40 @@ +'use strict'; + +var helpers = require('../helpers'); +var invokeMocha = helpers.invokeMocha; +var escapeRegExp = helpers.escapeRegExp; +var reporters = require('../../../lib/mocha').reporters; + +describe('--reporters', function() { + it('should dump a list of all reporters with descriptions', function(done) { + var expected = Object.keys(reporters) + .filter(function(name) { + return ( + /^[a-z]/.test(name) && + !(reporters[name].abstract || reporters[name].browserOnly) + ); + }) + .map(function(name) { + return { + name: escapeRegExp(name), + description: escapeRegExp(reporters[name].description) + }; + }); + + invokeMocha(['--reporters'], function(err, result) { + if (err) { + return done(err); + } + + expect(result.code, 'to be', 0); + expected.forEach(function(reporter) { + expect( + result.output, + 'to match', + new RegExp(reporter.name + '\\s*-\\s*' + reporter.description) + ); + }); + done(); + }); + }); +}); diff --git a/test/integration/show-plugins.spec.js b/test/integration/show-plugins.spec.js deleted file mode 100644 index 54a56f7d76..0000000000 --- a/test/integration/show-plugins.spec.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict'; - -var invokeMocha = require('./helpers').invokeMocha; -var Mocha = require('../../lib/mocha'); -var reporters = Mocha.reporters; -var interfaces = Mocha.interfaces; - -// thanks MDN -function escapeRegExp(str) { - return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string -} - -describe('--reporters', function() { - it('should dump a list of all reporters with descriptions', function(done) { - var expected = Object.keys(reporters) - .filter(function(name) { - return ( - /^[a-z]/.test(name) && - !(reporters[name].abstract || reporters[name].browserOnly) - ); - }) - .map(function(name) { - return { - name: escapeRegExp(name), - description: escapeRegExp(reporters[name].description) - }; - }); - - invokeMocha(['--reporters'], function(err, result) { - if (err) { - return done(err); - } - - expect(result.code, 'to be', 0); - expected.forEach(function(reporter) { - expect( - result.output, - 'to match', - new RegExp(reporter.name + '\\s*-\\s*' + reporter.description) - ); - }); - done(); - }); - }); -}); - -describe('--interfaces', function() { - it('should dump a list of all interfaces with descriptions', function(done) { - var expected = Object.keys(interfaces) - .filter(function(name) { - return /^[a-z]/.test(name); - }) - .map(function(name) { - return { - name: escapeRegExp(name), - description: escapeRegExp(interfaces[name].description) - }; - }); - - invokeMocha(['--interfaces'], function(err, result) { - if (err) { - return done(err); - } - - expect(result.code, 'to be', 0); - expected.forEach(function(ui) { - expect( - result.output, - 'to match', - new RegExp(ui.name + '\\s*-\\s*' + ui.description) - ); - }); - done(); - }); - }); -});