diff --git a/.changeset/great-crews-own.md b/.changeset/great-crews-own.md new file mode 100644 index 0000000000..dfe4d62da9 --- /dev/null +++ b/.changeset/great-crews-own.md @@ -0,0 +1,16 @@ +--- +'@backstage/cli': patch +--- + +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 two additional +directories: + +- `__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 6e2a510c4a..e213f58e4e 100644 --- a/packages/cli/config/eslint-factory.js +++ b/packages/cli/config/eslint-factory.js @@ -96,12 +96,16 @@ function createConfig(dir, extraConfig = {}) { `!${joinPath(dir, 'src/**')}`, joinPath(dir, 'src/**/*.test.*'), joinPath(dir, 'src/**/*.stories.*'), + joinPath(dir, 'src/**/__testUtils__/**'), + joinPath(dir, 'src/**/__mocks__/**'), joinPath(dir, 'src/setupTests.*'), ] : [ // Legacy config for packages that don't provide a dir '**/*.test.*', '**/*.stories.*', + '**/__testUtils__/**', + '**/__mocks__/**', '**/src/setupTests.*', '**/dev/**', ], @@ -137,6 +141,8 @@ function createConfig(dir, extraConfig = {}) { // Prevent imports of stories or tests '*.stories*', '*.test*', + '**/__testUtils__/**', + '**/__mocks__/**', ], }, ], @@ -159,7 +165,14 @@ function createConfig(dir, extraConfig = {}) { }, }, { - files: ['**/*.test.*', '**/*.stories.*', 'src/setupTests.*', '!src/**'], + files: [ + '**/*.test.*', + '**/*.stories.*', + '**/__testUtils__/**', + '**/__mocks__/**', + 'src/setupTests.*', + '!src/**', + ], rules: { ...testRules, 'no-restricted-syntax': [