Skip to content

Commit

Permalink
Cleanup displayName type (#10049)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick95 committed May 19, 2020
1 parent 6cef23b commit 2460c05
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@

- `[docs]` Correct confusing filename in `enableAutomock` example ([#10055](https://github.com/facebook/jest/pull/10055))
- `[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

0 comments on commit 2460c05

Please sign in to comment.