-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add color to displayName in project configuration. #8025
Changes from all commits
e3bf4a3
eefc4ff
e0f09e2
ec8b7c9
7bb02fc
a810c31
789cb8b
0903cd5
e369ca5
01d8d97
94caad6
dc7b046
f75bb90
2a56599
d42b2a3
81fc522
65aa738
041a81d
01fd4aa
44429c8
ec0d0d0
68a6ae4
d1fe278
87dc8cf
f1dbd72
aada1fb
bea007a
8928a2e
c1e5a38
4462019
21b99bb
3665d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import micromatch from 'micromatch'; | |
import {sync as realpath} from 'realpath-native'; | ||
import Resolver from 'jest-resolve'; | ||
import {replacePathSepForRegex} from 'jest-regex-util'; | ||
import getType from 'jest-get-type'; | ||
import validatePattern from './validatePattern'; | ||
import getMaxWorkers from './getMaxWorkers'; | ||
import { | ||
|
@@ -738,6 +739,50 @@ export default function normalize( | |
} | ||
break; | ||
} | ||
case 'displayName': { | ||
const displayName = oldOptions[key] as Config.DisplayName; | ||
if (typeof displayName === 'string') { | ||
value = displayName; | ||
break; | ||
} | ||
/** | ||
* Ensuring that displayName shape is correct here so that the | ||
* reporters can trust the shape of the data | ||
* TODO: Normalize "displayName" such that given a config option | ||
* { | ||
* "displayName": "Test" | ||
* } | ||
* becomes | ||
* { | ||
* displayName: { | ||
* name: "Test", | ||
* color: "white" | ||
* } | ||
* } | ||
* | ||
* This can't be done now since this will be a breaking change | ||
* for custom reporters | ||
*/ | ||
if (getType(displayName) === 'object') { | ||
const errorMessage = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opting to do a custom error here. Didn't want to overcomplicate it. Open for suggestions here |
||
` Option "${chalk.bold('displayName')}" must be of type:\n\n` + | ||
' {\n' + | ||
' name: string;\n' + | ||
' color: string;\n' + | ||
' }\n'; | ||
const {name, color} = displayName; | ||
if ( | ||
!name || | ||
!color || | ||
typeof name !== 'string' || | ||
typeof color !== 'string' | ||
) { | ||
throw createConfigError(errorMessage); | ||
} | ||
} | ||
value = oldOptions[key]; | ||
break; | ||
} | ||
case 'automock': | ||
case 'browser': | ||
case 'cache': | ||
|
@@ -749,7 +794,6 @@ export default function normalize( | |
case 'coverageThreshold': | ||
case 'detectLeaks': | ||
case 'detectOpenHandles': | ||
case 'displayName': | ||
case 'errorOnDeprecated': | ||
case 'expand': | ||
case 'extraGlobals': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,13 @@ export type DefaultOptions = { | |
watchman: boolean; | ||
}; | ||
|
||
export type DisplayName = | ||
| string | ||
| { | ||
name: string; | ||
color: DisplayNameColor; | ||
}; | ||
|
||
export type InitialOptions = { | ||
automock?: boolean; | ||
bail?: boolean | number; | ||
|
@@ -129,7 +136,7 @@ export type InitialOptions = { | |
dependencyExtractor?: string; | ||
detectLeaks?: boolean; | ||
detectOpenHandles?: boolean; | ||
displayName?: string; | ||
displayName?: DisplayName; | ||
expand?: boolean; | ||
extraGlobals?: Array<string>; | ||
filter?: Path; | ||
|
@@ -223,6 +230,47 @@ type NotifyMode = | |
| 'success-change' | ||
| 'failure-change'; | ||
|
||
/** | ||
* Hard coding this until | ||
* https://github.com/chalk/chalk/pull/336 | ||
* gets merged | ||
*/ | ||
type DisplayNameColor = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to extract these from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I was hard coding this because of what I mentioned about not being sure if we should curate the colors that we should allow or if we should allow everything. Hence the early PR 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've taken a look at the types provided by chalk and they don't expose the colors. https://github.com/chalk/chalk/blob/master/index.d.ts#L231 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just as an FYI, opened up this PR. Hopefully this gets merged and we won't have to hardcode colors here. chalk/chalk#336 |
||
| 'black' | ||
| 'red' | ||
| 'green' | ||
| 'yellow' | ||
| 'blue' | ||
| 'magenta' | ||
| 'cyan' | ||
| 'white' | ||
| 'gray' | ||
| 'grey' | ||
| 'blackBright' | ||
| 'redBright' | ||
| 'greenBright' | ||
| 'yellowBright' | ||
| 'blueBright' | ||
| 'magentaBright' | ||
| 'cyanBright' | ||
| 'whiteBright' | ||
| 'bgBlack' | ||
| 'bgRed' | ||
| 'bgGreen' | ||
| 'bgYellow' | ||
| 'bgBlue' | ||
| 'bgMagenta' | ||
| 'bgCyan' | ||
| 'bgWhite' | ||
| 'bgBlackBright' | ||
| 'bgRedBright' | ||
| 'bgGreenBright' | ||
| 'bgYellowBright' | ||
| 'bgBlueBright' | ||
| 'bgMagentaBright' | ||
| 'bgCyanBright' | ||
| 'bgWhiteBright'; | ||
|
||
type CoverageThreshold = { | ||
[path: string]: { | ||
[key: string]: number; | ||
|
@@ -318,7 +366,7 @@ export type ProjectConfig = { | |
dependencyExtractor?: string; | ||
detectLeaks: boolean; | ||
detectOpenHandles: boolean; | ||
displayName: string | null | undefined; | ||
displayName?: DisplayName; | ||
errorOnDeprecated: boolean; | ||
extraGlobals: Array<keyof NodeJS.Global>; | ||
filter: Path | null | undefined; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to cast this. Typescript was complaining alot