Created
November 19, 2014 19:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Combine this with ghooks and it's golden :-)