From 18469522768181119ca91293ba09a2c4da046151 Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Mon, 17 Oct 2022 09:37:51 +0100 Subject: [PATCH] build: switch eslint-factory to use __testUtils__ instead of __tests__ Signed-off-by: MT Lewis --- .changeset/great-crews-own.md | 14 ++++++++------ packages/cli/config/eslint-factory.js | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.changeset/great-crews-own.md b/.changeset/great-crews-own.md index 96633bc857..676eb7cf3d 100644 --- a/.changeset/great-crews-own.md +++ b/.changeset/great-crews-own.md @@ -2,13 +2,15 @@ '@backstage/cli': minor --- -Treat files in `__tests__` and `__mocks__` directories as test files for linting +Treat files in `__testUtils__` and `__mocks__` directories as test files for linting purposes. Updates the parts of the eslint configuration generator that specify which files -should be treated as test code to include any files under directories named -`__tests__` or `__mocks__`, to match the default file locations used in Jest. +should be treated as test code to include any files under two additional +directories: -cf. -https://jestjs.io/docs/configuration/#testmatch-arraystring -https://jestjs.io/docs/manual-mocks#mocking-user-modules +- `__mocks__`: this is the directory used by Jest[0] for mock code. +- `__testUtils__`: a suggested location for utility code executed only when + running tests. + +[0]: https://jestjs.io/docs/manual-mocks#mocking-user-modules diff --git a/packages/cli/config/eslint-factory.js b/packages/cli/config/eslint-factory.js index d764edb2b5..e213f58e4e 100644 --- a/packages/cli/config/eslint-factory.js +++ b/packages/cli/config/eslint-factory.js @@ -96,7 +96,7 @@ function createConfig(dir, extraConfig = {}) { `!${joinPath(dir, 'src/**')}`, joinPath(dir, 'src/**/*.test.*'), joinPath(dir, 'src/**/*.stories.*'), - joinPath(dir, 'src/**/__tests__/**'), + joinPath(dir, 'src/**/__testUtils__/**'), joinPath(dir, 'src/**/__mocks__/**'), joinPath(dir, 'src/setupTests.*'), ] @@ -104,7 +104,7 @@ function createConfig(dir, extraConfig = {}) { // Legacy config for packages that don't provide a dir '**/*.test.*', '**/*.stories.*', - '**/__tests__/**', + '**/__testUtils__/**', '**/__mocks__/**', '**/src/setupTests.*', '**/dev/**', @@ -141,7 +141,7 @@ function createConfig(dir, extraConfig = {}) { // Prevent imports of stories or tests '*.stories*', '*.test*', - '**/__tests__/**', + '**/__testUtils__/**', '**/__mocks__/**', ], }, @@ -168,7 +168,7 @@ function createConfig(dir, extraConfig = {}) { files: [ '**/*.test.*', '**/*.stories.*', - '**/__tests__/**', + '**/__testUtils__/**', '**/__mocks__/**', 'src/setupTests.*', '!src/**',