Skip to content

Commit

Permalink
Add a verification step to fail the build when tests are filtered wit…
Browse files Browse the repository at this point in the history
…h `.only`
  • Loading branch information
marcioj committed May 27, 2015
1 parent 52d748d commit a9893c4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"isbinaryfile": "^2.0.3",
"mocha": "^2.2.1",
"mocha-jshint": "1.0.0",
"mocha-only-detector": "0.0.2",
"multiline": "^1.0.2",
"nock": "^1.2.1",
"node-require-timings": "1.0.0",
Expand Down
54 changes: 41 additions & 13 deletions tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,62 @@

var glob = require('glob');
var Mocha = require('mocha');
var RSVP = require('rsvp');
var mochaOnlyDetector = require('mocha-only-detector');

if (process.env.EOLNEWLINE) {
require('os').EOL = '\n';
}

var root = 'tests/{unit,acceptance}';
var _checkOnlyInTests = RSVP.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test,-slow}.js'));
var optionOrFile = process.argv[2];
var mocha = new Mocha({
timeout: 5000,
reporter: 'spec'
});

var arg = process.argv[2];
var root = 'tests/{unit,acceptance}';
if (optionOrFile === 'all') {
addFiles(mocha, '/**/*-test.js');
addFiles(mocha, '/**/*-slow.js');
} else if (optionOrFile) {
mocha.addFile(optionOrFile);
} else {
addFiles(mocha, '/**/*-test.js');
}

function addFiles(mocha, files) {
glob.sync(root + files).forEach(mocha.addFile.bind(mocha));
}

function checkOnlyInTests() {
console.log('Verifing `.only` in tests');
return _checkOnlyInTests().then(function() {
console.log('No `.only` found');
});
}

function runMocha() {
mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures);
});
});
}

if (arg === 'all') {
addFiles(mocha, '/**/*-test.js');
addFiles(mocha, '/**/*-slow.js');
} else if (arg) {
mocha.addFile(arg);
} else {
addFiles(mocha, '/**/*-test.js');
function ciVerificationStep() {
if (process.env.CI === 'true') {
return checkOnlyInTests();
} else {
return RSVP.resolve();
}
}

mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures);
ciVerificationStep()
.then(function() {
runMocha();
})
.catch(function(error) {
console.error(error);
process.exit(1);
});
});

0 comments on commit a9893c4

Please sign in to comment.