Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created November 19, 2014 19:45
Show Gist options
  • Save kentcdodds/b368e1a0e932f78eaccf to your computer and use it in GitHub Desktop.
Save kentcdodds/b368e1a0e932f78eaccf to your computer and use it in GitHub Desktop.
make sure you're not checking .only describes or its in your tests
/* jshint node:true */
'use strict';
var glob = require('glob');
var async = require('async');
var fs = require('fs');
var chalk = require('chalk');
glob('app/components/**/*.test.js', function(err, files) {
if (err) {
throw err;
}
async.map(files, getFileReader(), function(err, results) {
if (err) {
throw err;
}
var badFiles = [];
var badMatch = /describe\.only|it\.only/gmi;
results.forEach(function(fileContents, index) {
if (badMatch.test(fileContents)) {
badFiles.push(files[index]);
}
});
var p = badFiles.length > 1;
if (badFiles.length) {
var message = chalk.bold.red('There ' + (p ? 'are' : 'is') + ' ' + badFiles.length + ' ' +
(p ? 'files' : 'file') + ' with a `.only` so not all tests will be run:');
var badFilesPart = chalk.red(badFiles.join('\n\t'));
console.warn([message, badFilesPart].join('\n\t'));
throw new Error('only-check failed');
}
});
});
function getFileReader() {
return function readFileUTF8(filepath, callback) {
return fs.readFile(filepath, 'utf8', callback);
};
}
@kentcdodds
Copy link
Author

Combine this with ghooks and it's golden :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment