From ce135d28c33e8bb68f32c6a2ac73e382a0d5aea3 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sat, 25 Oct 2025 11:20:37 -0400 Subject: [PATCH] chore: run all tests in pre-commit hook to avoid 'No tests found' error --- .gitignore | 1 + lint-staged.config.js | 15 +++++++++++++++ tests/jest.config.dom.js | 4 +++- tests/jest.config.node.js | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lint-staged.config.js diff --git a/.gitignore b/.gitignore index 8e0c70cb..f7a99610 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist # when working with contributors package-lock.json yarn.lock +.jest-cache/ diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 00000000..085411b0 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,15 @@ +const {resolveKcdScripts, resolveBin} = require('kcd-scripts/dist/utils') + +const kcdScripts = resolveKcdScripts() +const doctoc = resolveBin('doctoc') + +// Custom lint-staged config to work around Jest --findRelatedTests unreliability: +// https://github.com/facebook/jest/issues/11527 +module.exports = { + 'README.md': [`${doctoc} --maxlevel 3 --notitle`], + '*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue)': [ + `${kcdScripts} format`, + `${kcdScripts} lint`, + () => `${kcdScripts} test`, + ], +} diff --git a/tests/jest.config.dom.js b/tests/jest.config.dom.js index e3c4c598..d2cc9ef6 100644 --- a/tests/jest.config.dom.js +++ b/tests/jest.config.dom.js @@ -1,8 +1,10 @@ const path = require('path') const config = require('kcd-scripts/jest') +const {watchPlugins, ...configWithoutWatchPlugins} = config + module.exports = { - ...config, + ...configWithoutWatchPlugins, rootDir: path.resolve(__dirname, '..'), displayName: 'jsdom', testEnvironment: 'jsdom', diff --git a/tests/jest.config.node.js b/tests/jest.config.node.js index 0c3f3894..edb3aa6f 100644 --- a/tests/jest.config.node.js +++ b/tests/jest.config.node.js @@ -1,8 +1,10 @@ const path = require('path') const config = require('kcd-scripts/jest') +const {watchPlugins, ...configWithoutWatchPlugins} = config + module.exports = { - ...config, + ...configWithoutWatchPlugins, rootDir: path.resolve(__dirname, '..'), displayName: 'node', testEnvironment: 'node',