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 init when there is one project in projects config. #8409

Closed
wants to merge 3 commits into from
Closed
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
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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is actually a deeper issue here that will require more than this quick fix, since the types seem convinced it's a string when my understanding (from it's use at FB) is that it can be a string or a config.

However, this solves the immediate issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, from #5176

) {
const parsedConfigs = projects
.filter(root => {
// Ignore globbed files that cannot be `require`d.
Expand Down