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 @@ -59,6 +59,7 @@
- `[jest-jasmine2]` Fixed the issue of `beforeAll` & `afterAll` hooks getting executed even if it is inside a skipped `describe` block when it has child `tests` marked as either `only` or `todo` [#10451](https://github.com/facebook/jest/issues/10451)
- `[jest-jasmine2]` Fixed the issues of child `tests` marked with `only` or `todo` getting executed even if it is inside a skipped parent `describe` block [#10451](https://github.com/facebook/jest/issues/10451)
- `[jest-reporter]` Handle empty files when reporting code coverage with V8 ([#10819](https://github.com/facebook/jest/pull/10819))
- `[jest-reporters]` Fix `Config.ts` `projects` types and better handle `displayName` ([#11285](https://github.com/facebook/jest/pull/11285))
- `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781))
- `[jest-resolve]` Disable `jest-pnp-resolver` for Yarn 2 ([#10847](https://github.com/facebook/jest/pull/10847))
- `[jest-runtime]` [**BREAKING**] Do not inject `global` variable into module wrapper ([#10644](https://github.com/facebook/jest/pull/10644))
Expand Down
Expand Up @@ -6,6 +6,8 @@ exports[`printDisplayName should default displayName color to white when color i

exports[`printDisplayName should default displayName color to white when displayName is a string 1`] = `"</><inverse><white> hello </></></>"`;

exports[`printDisplayName should correctly print the displayName when given just a string 1`] = `"</><inverse><white> hello </></></>"`;

exports[`trimAndFormatPath() does not trim anything 1`] = `"<dim>1234567890/1234567890/</><bold>1234.js</>"`;

exports[`trimAndFormatPath() split at the path.sep index 1`] = `"<dim>.../</><bold>1234.js</>"`;
Expand Down
10 changes: 10 additions & 0 deletions packages/jest-reporters/src/__tests__/utils.test.ts
Expand Up @@ -152,4 +152,14 @@ describe('printDisplayName', () => {
),
).toMatchSnapshot();
});

it('should correctly print the displayName when given just a string', () => {
expect(
printDisplayName(
makeProjectConfig({
displayName: 'hello',
}),
),
).toMatchSnapshot();
});
});
6 changes: 6 additions & 0 deletions packages/jest-reporters/src/utils.ts
Expand Up @@ -22,6 +22,12 @@ export const printDisplayName = (config: Config.ProjectConfig): string => {
return '';
}

// given just a string, default to white
if (typeof displayName === 'string') {
return white(` ${displayName} `);
}

// given name and a color
const {name, color} = displayName;
const chosenColor = chalk.reset.inverse[color]
? chalk.reset.inverse[color]
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-types/src/Config.ts
Expand Up @@ -330,7 +330,7 @@ export type ProjectConfig = {
dependencyExtractor?: string;
detectLeaks: boolean;
detectOpenHandles: boolean;
displayName?: DisplayName;
displayName?: DisplayName | string;
TranquilMarmot marked this conversation as resolved.
Show resolved Hide resolved
errorOnDeprecated: boolean;
extensionsToTreatAsEsm: Array<Path>;
extraGlobals: Array<keyof NodeJS.Global>;
Expand All @@ -344,7 +344,7 @@ export type ProjectConfig = {
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleLoader?: Path;
moduleNameMapper: Array<[string, string]>;
moduleNameMapper: Record<string, string | Array<string>>;
TranquilMarmot marked this conversation as resolved.
Show resolved Hide resolved
modulePathIgnorePatterns: Array<string>;
modulePaths?: Array<string>;
name: string;
Expand Down Expand Up @@ -428,7 +428,7 @@ export type Argv = Arguments<
onlyFailures: boolean;
outputFile: string;
preset: string | null | undefined;
projects: Array<string>;
projects: Array<string> | Array<Partial<ProjectConfig>>;
TranquilMarmot marked this conversation as resolved.
Show resolved Hide resolved
TranquilMarmot marked this conversation as resolved.
Show resolved Hide resolved
prettierPath: string | null | undefined;
resetMocks: boolean;
resetModules: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/config.ts
Expand Up @@ -87,7 +87,7 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
moduleDirectories: [],
moduleFileExtensions: ['js'],
moduleLoader: '/test_module_loader_path',
moduleNameMapper: [],
moduleNameMapper: {},
modulePathIgnorePatterns: [],
modulePaths: [],
name: 'test_name',
Expand Down