Skip to content

Instantly share code, notes, and snippets.

@mantoni
Created January 12, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mantoni/facc4b06f88379564bf9e8163669ef92 to your computer and use it in GitHub Desktop.
Save mantoni/facc4b06f88379564bf9e8163669ef92 to your computer and use it in GitHub Desktop.
'use strict';
const fs = require('fs');
module.exports = {
'*.js': [
'eslint --fix',
(files) => {
const tests = findTests(files);
return tests.length ? `npm run test:files -- ${tests.join(' ')}` : 'echo';
}
],
'*.{js,css,md}': 'prettier --write'
};
function findTests(files) {
const tests = new Set();
files.forEach((file) => {
if (file.endsWith('.test.js')) {
tests.add(file);
return;
}
const test = file.replace(/\.js$/, '.test.js');
try {
fs.accessSync(test); // eslint-disable-line node/no-sync
} catch (e) {
return;
}
tests.add(test);
});
return Array.from(tests);
}
@mantoni
Copy link
Author

mantoni commented Jan 12, 2021

{
  "scripts": {
    "test:files": "mocha -R dot -r ./test/fixture/assertions/*"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged --relative"
    }
  }
}

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