Skip to content

Instantly share code, notes, and snippets.

@tracker1
Created January 25, 2017 01:27
Show Gist options
  • Save tracker1/d6ad53e3cd9f17515d920f9f863b2949 to your computer and use it in GitHub Desktop.
Save tracker1/d6ad53e3cd9f17515d920f9f863b2949 to your computer and use it in GitHub Desktop.
Node.js PreTest script
const path = require('path');
const glob = require('glob');
const base = path.resolve(__dirname, '../');
const allScripts = glob.sync(path.join(__dirname, '../src') + '/**/*.js');
const tests = allScripts.filter(s => (/\.test\.js$/).test(s));
const scripts = allScripts.filter(s => !(/\.(test|disabled|unsafe)\./).test(s));
const untested = scripts.filter(s => !tests.includes(s.replace(/\.js$/,'.test.js')));
if (untested.length) {
console.error('\n\nThe following scripts do not have a test file.');
untested
.map(s => path.resolve(s).replace(base, '').substr(1))
.forEach(s => console.error(` ${s}`));
process.nextTick(() => process.exit(1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment