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

Allow projects in TypeScript Config to be an array of ProjectConfig #11285

Merged
merged 13 commits into from Apr 12, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -70,6 +70,7 @@
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
- `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753))
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options ([#10834](https://github.com/facebook/jest/pull/10834))
- `[jest-types]` Fix `Config.ts` `projects` types ([#11285](https://github.com/facebook/jest/pull/11285))
- `[jest-worker]` [**BREAKING**] Use named exports ([#10623](https://github.com/facebook/jest/pull/10623))
- `[jest-worker]` Do not swallow errors during serialization ([#10984](https://github.com/facebook/jest/pull/10984))
- `[jest-worker]` Handle `ERR_IPC_CHANNEL_CLOSED` errors properly ([#11143](https://github.com/facebook/jest/pull/11143))
Expand Down
21 changes: 13 additions & 8 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -821,14 +821,19 @@ export default async function normalize(
? _replaceRootDirTags(options.rootDir, project)
: project,
)
.reduce<Array<string>>((projects, project) => {
// Project can be specified as globs. If a glob matches any files,
// We expand it to these paths. If not, we keep the original path
// for the future resolution.
const globMatches =
typeof project === 'string' ? glob(project) : [];
return projects.concat(globMatches.length ? globMatches : project);
}, []);
.reduce<Array<string | Config.InitialProjectOptions>>(
(projects, project) => {
// Project can be specified as globs. If a glob matches any files,
// We expand it to these paths. If not, we keep the original path
// for the future resolution.
const globMatches =
typeof project === 'string' ? glob(project) : [];
return projects.concat(
globMatches.length ? globMatches : project,
);
},
[],
);
break;
case 'moduleDirectories':
case 'testMatch':
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-types/src/Config.ts
Expand Up @@ -124,6 +124,11 @@ export type DisplayName = {
export type InitialOptionsWithRootDir = InitialOptions &
Required<Pick<InitialOptions, 'rootDir'>>;

export type InitialProjectOptions = Pick<
InitialOptions & {cwd?: string},
keyof ProjectConfig
>;

export type InitialOptions = Partial<{
automock: boolean;
bail: boolean | number;
Expand Down Expand Up @@ -184,7 +189,7 @@ export type InitialOptions = Partial<{
preprocessorIgnorePatterns: Array<Glob>;
preset: string | null | undefined;
prettierPath: string | null | undefined;
projects: Array<Glob>;
projects: Array<Glob | InitialProjectOptions>;
replname: string | null | undefined;
resetMocks: boolean;
resetModules: boolean;
Expand Down
8 changes: 8 additions & 0 deletions test-types/top-level-config.test.ts
Expand Up @@ -32,4 +32,12 @@ expectAssignable<Config.InitialOptions>({
statements: 50,
},
},
projects: [
// projects can be globs or objects
'./src/**',
{
displayName: 'A Project',
rootDir: './src/components',
},
],
});