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

Add color to displayName in project configuration. #8025

Merged
merged 32 commits into from Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e3bf4a3
WIP
natealcedo Feb 24, 2019
eefc4ff
Update jest-types to have displayNameColor
natealcedo Feb 28, 2019
e0f09e2
Update default value to white
natealcedo Feb 28, 2019
ec8b7c9
Add displayNameColor to Initial Options
natealcedo Feb 28, 2019
7bb02fc
Merge remote-tracking branch 'origin/master' into feature/support-dis…
natealcedo Mar 23, 2019
a810c31
Delete Config.js
natealcedo Mar 23, 2019
789cb8b
Remove displayNameColor
natealcedo Mar 23, 2019
0903cd5
Eslint fix
natealcedo Mar 23, 2019
e369ca5
Update implementation of displayName
natealcedo Mar 23, 2019
01d8d97
Update DisplayName type
natealcedo Mar 23, 2019
94caad6
NormalizedisplayName
natealcedo Mar 23, 2019
dc7b046
Add validation for when displayName is an object
natealcedo Mar 23, 2019
f75bb90
Add test cases for normalizing of displayName when the value is an ob…
natealcedo Mar 23, 2019
2a56599
Remove validation logic from utils
natealcedo Mar 23, 2019
d42b2a3
Add all colors
natealcedo Mar 24, 2019
81fc522
Use jest-get-type
natealcedo Mar 24, 2019
65aa738
Add tests to displayName
natealcedo Mar 25, 2019
041a81d
Update ProjectConfig
natealcedo Mar 25, 2019
01fd4aa
Run lint fix
natealcedo Mar 25, 2019
44429c8
Revert typing error
natealcedo Mar 25, 2019
ec0d0d0
Merge branch 'master' into feature/support-displayNameColor
natealcedo Mar 26, 2019
68a6ae4
Remove test scenario which will never happen
natealcedo Mar 26, 2019
d1fe278
Merge remote-tracking branch 'origin/master' into feature/support-dis…
natealcedo Mar 26, 2019
87dc8cf
Update docs with new displayName behavior
natealcedo Mar 26, 2019
f1dbd72
Update versioned docs
natealcedo Mar 26, 2019
aada1fb
Update changelog
natealcedo Mar 26, 2019
bea007a
Update snapshot
natealcedo Mar 26, 2019
8928a2e
Lint fix
natealcedo Mar 26, 2019
c1e5a38
Lint md fix
natealcedo Mar 26, 2019
4462019
Respond to feedback
natealcedo Mar 26, 2019
21b99bb
Add new line
natealcedo Mar 26, 2019
3665d38
Update snapshot
natealcedo Mar 26, 2019
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 packages/jest-config/src/ValidConfig.ts
Expand Up @@ -42,6 +42,7 @@ const initialOptions: Config.InitialOptions = {
cwd: '/root',
dependencyExtractor: '<rootDir>/dependencyExtractor.js',
displayName: 'project-name',
displayNameColor: 'white',
errorOnDeprecated: false,
expand: false,
extraGlobals: [],
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Expand Up @@ -168,6 +168,7 @@ const groupOptions = (
detectLeaks: options.detectLeaks,
detectOpenHandles: options.detectOpenHandles,
displayName: options.displayName,
displayNameColor: options.displayNameColor,
errorOnDeprecated: options.errorOnDeprecated,
extraGlobals: options.extraGlobals,
filter: options.filter,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -757,6 +757,7 @@ export default function normalize(
case 'detectLeaks':
case 'detectOpenHandles':
case 'displayName':
case 'displayNameColor':
case 'errorOnDeprecated':
case 'expand':
case 'extraGlobals':
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-reporters/src/utils.js
Expand Up @@ -24,12 +24,13 @@ type SummaryOptions = {|
const PROGRESS_BAR_WIDTH = 40;

export const printDisplayName = (config: ProjectConfig) => {
const {displayName} = config;
const {displayName, displayNameColor} = config;
const color = displayNameColor
? chalk.reset.inverse[displayNameColor]
: chalk.reset.inverse.white;

if (displayName) {
return chalk.supportsColor
? chalk.reset.inverse.white(` ${displayName} `)
: displayName;
return chalk.supportsColor ? color(` ${displayName} `) : displayName;
}

return '';
Expand Down
23 changes: 22 additions & 1 deletion packages/jest-types/src/Config.ts
Expand Up @@ -130,6 +130,7 @@ export type InitialOptions = {
detectLeaks?: boolean;
detectOpenHandles?: boolean;
displayName?: string;
displayNameColor?: DisplayNameColor;
expand?: boolean;
extraGlobals?: Array<string>;
filter?: Path;
Expand Down Expand Up @@ -223,6 +224,25 @@ type NotifyMode =
| 'success-change'
| 'failure-change';

type DisplayNameColor =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to extract these from chalk instead of hard coding them

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'
| 'blue '
| 'blueBright'
| 'cyan'
| 'cyanBright'
| 'gray '
| 'green'
| 'greenBright'
| 'magenta'
| 'magentaBright'
| 'red'
| 'redBright'
| 'white'
| 'whiteBright'
| 'yellow'
| 'yellowBright'


export type GlobalConfig = {
bail: number;
changedSince: string;
Expand Down Expand Up @@ -313,7 +333,8 @@ export type ProjectConfig = {
dependencyExtractor?: string;
detectLeaks: boolean;
detectOpenHandles: boolean;
displayName: string | null | undefined;
displayName?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should do displayName?: string | {name: string; color: DisplayNameColor} instead of adding a new option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I like this implementation better actually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the API that @SimenB is suggesting.

displayNameColor?: DisplayNameColor;
errorOnDeprecated: boolean;
extraGlobals: Array<keyof NodeJS.Global>;
filter: Path | null | undefined;
Expand Down
3 changes: 3 additions & 0 deletions types/Config.js
Expand Up @@ -109,6 +109,7 @@ export type InitialOptions = {
detectLeaks?: boolean,
detectOpenHandles?: boolean,
displayName?: string,
displayNameColor?: DisplayNameColor,
expand?: boolean,
extraGlobals?: Array<string>,
filter?: Path,
Expand Down Expand Up @@ -189,6 +190,7 @@ export type InitialOptions = {
};

export type SnapshotUpdateState = 'all' | 'new' | 'none';
export type DisplayNameColor = 'white' | 'blue';

export type GlobalConfig = {|
bail: number,
Expand Down Expand Up @@ -259,6 +261,7 @@ export type ProjectConfig = {|
detectLeaks: boolean,
detectOpenHandles: boolean,
displayName: ?string,
displayNameColor: ?DisplayNameColor,
errorOnDeprecated: boolean,
extraGlobals: Array<string>,
filter: ?Path,
Expand Down