From 2460c059ad1dbf124466ac25c8d5ccfd74ae9f25 Mon Sep 17 00:00:00 2001 From: Kenrick Date: Wed, 20 May 2020 05:13:54 +0800 Subject: [PATCH] Cleanup `displayName` type (#10049) --- CHANGELOG.md | 1 + packages/jest-core/src/getProjectDisplayName.ts | 8 +------- packages/jest-reporters/src/__tests__/utils.test.ts | 5 ++++- packages/jest-reporters/src/utils.ts | 4 ---- packages/jest-test-result/src/helpers.ts | 2 +- packages/jest-types/src/Config.ts | 12 +++++------- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b9ce319eda7..e061d9be64c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-core/src/getProjectDisplayName.ts b/packages/jest-core/src/getProjectDisplayName.ts index 24f55d6746ea..d9e8271c622a 100644 --- a/packages/jest-core/src/getProjectDisplayName.ts +++ b/packages/jest-core/src/getProjectDisplayName.ts @@ -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; } diff --git a/packages/jest-reporters/src/__tests__/utils.test.ts b/packages/jest-reporters/src/__tests__/utils.test.ts index b23fcc2e63b9..8e1887daf7f5 100644 --- a/packages/jest-reporters/src/__tests__/utils.test.ts +++ b/packages/jest-reporters/src/__tests__/utils.test.ts @@ -118,7 +118,10 @@ describe('printDisplayName', () => { expect( printDisplayName( makeProjectConfig({ - displayName: 'hello', + displayName: { + color: 'white', + name: 'hello', + }, }), ), ).toMatchSnapshot(); diff --git a/packages/jest-reporters/src/utils.ts b/packages/jest-reporters/src/utils.ts index fdeb1814e3fc..752e7c9f60f2 100644 --- a/packages/jest-reporters/src/utils.ts +++ b/packages/jest-reporters/src/utils.ts @@ -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] diff --git a/packages/jest-test-result/src/helpers.ts b/packages/jest-test-result/src/helpers.ts index 9076b2127fae..1e56aecebb23 100644 --- a/packages/jest-test-result/src/helpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -48,7 +48,7 @@ export const buildFailureTestResult = ( err: SerializableError, ): TestResult => ({ console: undefined, - displayName: '', + displayName: undefined, failureMessage: null, leaks: false, numFailingTests: 0, diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 8bfc411710f7..76a7b33a8f77 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -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>; @@ -119,7 +117,7 @@ export type InitialOptions = Partial<{ dependencyExtractor: string; detectLeaks: boolean; detectOpenHandles: boolean; - displayName: DisplayName; + displayName: string | DisplayName; expand: boolean; extraGlobals: Array; filter: Path;