Skip to content

Commit

Permalink
add missing integration tests to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Feb 8, 2019
1 parent 619ef49 commit 1e92bfc
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package-scripts.js
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion test/integration/helpers.js
Expand Up @@ -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
}
};

/**
Expand Down
37 changes: 37 additions & 0 deletions 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();
});
});
});
25 changes: 25 additions & 0 deletions 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'
);
});
});
});
40 changes: 40 additions & 0 deletions 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();
});
});
});
76 changes: 0 additions & 76 deletions test/integration/show-plugins.spec.js

This file was deleted.

0 comments on commit 1e92bfc

Please sign in to comment.