Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-config): Allow exactly one project #7498

Merged
merged 4 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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