diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ed064057cf..c62ad76c6881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - `[expect]` Extract names of async and generator functions ([#8362](https://github.com/facebook/jest/pull/8362)) - `[jest-runtime]` Fix virtual mocks not being unmockable after previously being mocked ([#8396](https://github.com/facebook/jest/pull/8396)) - `[jest-transform]` Replace special characters in transform cache filenames to support Windows ([#8353](https://github.com/facebook/jest/pull/8353)) +- `[jest-config]` Allow exactly one project ([#7498](https://github.com/facebook/jest/pull/7498)) ### Chore & Maintenance diff --git a/e2e/__tests__/multiProjectRunner.test.ts b/e2e/__tests__/multiProjectRunner.test.ts index 47abab2d968a..a610f2cb6e63 100644 --- a/e2e/__tests__/multiProjectRunner.test.ts +++ b/e2e/__tests__/multiProjectRunner.test.ts @@ -170,6 +170,42 @@ test('"No tests found" message for projects', () => { ); }); +test.each([{projectPath: 'packages/somepackage'}, {projectPath: 'packages/*'}])( + 'allows a single non-root project', + ({projectPath}: {projectPath: string}) => { + writeFiles(DIR, { + 'package.json': ` + { + "jest": { + "testMatch": ["/packages/somepackage/test.js"], + "projects": [ + "${projectPath}" + ] + } + } + `, + 'packages/somepackage/package.json': ` + { + "jest": { + "displayName": "somepackage" + } + } + `, + 'packages/somepackage/test.js': ` + test('1+1', () => { + expect(1).toBe(1); + }); + `, + }); + + const {stdout, stderr, status} = runJest(DIR, ['--no-watchman']); + expect(stderr).toContain('PASS packages/somepackage/test.js'); + expect(stderr).toContain('Test Suites: 1 passed, 1 total'); + expect(stdout).toEqual(''); + expect(status).toEqual(0); + }, +); + test('projects can be workspaces with non-JS/JSON files', () => { writeFiles(DIR, { 'package.json': JSON.stringify({ diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index 9f929864554b..337e7ab47c81 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -218,6 +218,10 @@ const ensureNoDuplicateConfigs = ( parsedConfigs: Array, projects: Config.GlobalConfig['projects'], ) => { + if (projects.length <= 1) { + return; + } + const configPathMap = new Map(); for (const config of parsedConfigs) { @@ -289,7 +293,10 @@ export function readConfigs( } } - if (projects.length > 1) { + if ( + projects.length > 1 || + (projects.length && typeof projects[0] === 'object') + ) { const parsedConfigs = projects .filter(root => { // Ignore globbed files that cannot be `require`d.