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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup displayName type #10049

Merged
merged 1 commit into from May 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
### Chore & Maintenance

- `[jest-core]` 馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀 ([#10000](https://github.com/facebook/jest/pull/10000))
- `[jest-core, jest-reporters, jest-test-result, jest-types]` Cleanup `displayName` type ([#10049](https://github.com/facebook/jest/pull/10049))

### Performance

Expand Down
8 changes: 1 addition & 7 deletions packages/jest-core/src/getProjectDisplayName.ts
Expand Up @@ -14,11 +14,5 @@ export default function getProjectDisplayName(
if (!displayName) {
return undefined;
}
if (typeof displayName === 'string') {
return displayName;
}
if (typeof displayName === 'object') {
return displayName.name;
}
return undefined;
return displayName.name;
}
5 changes: 4 additions & 1 deletion packages/jest-reporters/src/__tests__/utils.test.ts
Expand Up @@ -118,7 +118,10 @@ describe('printDisplayName', () => {
expect(
printDisplayName(
makeProjectConfig({
displayName: 'hello',
displayName: {
color: 'white',
name: 'hello',
},
}),
),
).toMatchSnapshot();
Expand Down
4 changes: 0 additions & 4 deletions packages/jest-reporters/src/utils.ts
Expand Up @@ -22,10 +22,6 @@ export const printDisplayName = (config: Config.ProjectConfig): string => {
return '';
}

if (typeof displayName === 'string') {
return chalk.supportsColor ? white(` ${displayName} `) : displayName;
}

const {name, color} = displayName;
const chosenColor = chalk.reset.inverse[color]
? chalk.reset.inverse[color]
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-test-result/src/helpers.ts
Expand Up @@ -48,7 +48,7 @@ export const buildFailureTestResult = (
err: SerializableError,
): TestResult => ({
console: undefined,
displayName: '',
displayName: undefined,
failureMessage: null,
leaks: false,
numFailingTests: 0,
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-types/src/Config.ts
Expand Up @@ -84,12 +84,10 @@ export type DefaultOptions = {
watchman: boolean;
};

export type DisplayName =
| string
| {
name: string;
color: typeof chalk.Color;
};
export type DisplayName = {
name: string;
color: typeof chalk.Color;
};

export type InitialOptionsWithRootDir = InitialOptions &
Required<Pick<InitialOptions, 'rootDir'>>;
Expand Down Expand Up @@ -119,7 +117,7 @@ export type InitialOptions = Partial<{
dependencyExtractor: string;
detectLeaks: boolean;
detectOpenHandles: boolean;
displayName: DisplayName;
displayName: string | DisplayName;
expand: boolean;
extraGlobals: Array<string>;
filter: Path;
Expand Down