Skip to content

Commit

Permalink
fix(jest-config): Allow exactly one project (#7498)
Browse files Browse the repository at this point in the history
  • Loading branch information
theneva authored and SimenB committed May 2, 2019
1 parent 9081612 commit 4941d12
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions e2e/__tests__/multiProjectRunner.test.ts
Expand Up @@ -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": ["<rootDir>/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({
Expand Down
9 changes: 8 additions & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -218,6 +218,10 @@ const ensureNoDuplicateConfigs = (
parsedConfigs: Array<ReadConfig>,
projects: Config.GlobalConfig['projects'],
) => {
if (projects.length <= 1) {
return;
}

const configPathMap = new Map();

for (const config of parsedConfigs) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4941d12

Please sign in to comment.