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

Refactor names and delimiters of complex values in pretty-format #3986

Merged
merged 2 commits into from
Jul 8, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class HasteMap extends EventEmitter {
if (!match) {
return true;
}

const filePathInPackage = filePath.substr(matchEndIndex);
return filePathInPackage.startsWith(NODE_MODULES);
}
Expand Down
136 changes: 36 additions & 100 deletions packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ function printBasicValue(
}
return regExpToString.call(val);
}
if (toStringed === '[object Arguments]' && val.length === 0) {
return 'Arguments []';
}
if (isToStringedArrayType(toStringed) && val.length === 0) {
return val.constructor.name + ' []';
}

if (val instanceof Error) {
return printError(val);
Expand Down Expand Up @@ -229,81 +223,7 @@ function printList(
body += (min ? '' : ',') + edgeSpacing + prevIndent;
}

return '[' + body + ']';
}

function printArguments(
val: any,
indent: string,
prevIndent: string,
spacing: string,
edgeSpacing: string,
refs: Refs,
maxDepth: number,
currentDepth: number,
plugins: Plugins,
min: boolean,
callToJSON: boolean,
printFunctionName: boolean,
escapeRegex: boolean,
colors: Colors,
): string {
return (
(min ? '' : 'Arguments ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors,
)
);
}

function printArray(
val: any,
indent: string,
prevIndent: string,
spacing: string,
edgeSpacing: string,
refs: Refs,
maxDepth: number,
currentDepth: number,
plugins: Plugins,
min: boolean,
callToJSON: boolean,
printFunctionName: boolean,
escapeRegex: boolean,
colors: Colors,
): string {
return (
(min ? '' : val.constructor.name + ' ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors,
)
);
return body;
}

function printMap(
Expand All @@ -322,7 +242,7 @@ function printMap(
escapeRegex: boolean,
colors: Colors,
): string {
let result = 'Map {';
let result = '';
const iterator = val.entries();
let current = iterator.next();

Expand Down Expand Up @@ -377,7 +297,7 @@ function printMap(
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}

return result + '}';
return result;
}

function printObject(
Expand All @@ -396,10 +316,7 @@ function printObject(
escapeRegex: boolean,
colors: Colors,
): string {
const constructor = min
? ''
: val.constructor ? val.constructor.name + ' ' : 'Object ';
let result = constructor + '{';
let result = '';
let keys = Object.keys(val).sort();
const symbols = getSymbols(val);

Expand Down Expand Up @@ -457,7 +374,7 @@ function printObject(
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}

return result + '}';
return result;
}

function printSet(
Expand All @@ -476,7 +393,7 @@ function printSet(
escapeRegex: boolean,
colors: Colors,
): string {
let result = 'Set {';
let result = '';
const iterator = val.entries();
let current = iterator.next();

Expand Down Expand Up @@ -515,7 +432,7 @@ function printSet(
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}

return result + '}';
return result;
}

function printComplexValue(
Expand Down Expand Up @@ -571,9 +488,14 @@ function printComplexValue(

const toStringed = toString.call(val);
if (toStringed === '[object Arguments]') {
if (val.length === 0) {
return 'Arguments []';
}
return hitMaxDepth
? '[Arguments]'
: printArguments(
: (min ? '' : 'Arguments ') +
'[' +
printList(
val,
indent,
prevIndent,
Expand All @@ -588,11 +510,17 @@ function printComplexValue(
printFunctionName,
escapeRegex,
colors,
);
) +
']';
} else if (isToStringedArrayType(toStringed)) {
if (val.length === 0) {
return val.constructor.name + ' []';
}
return hitMaxDepth
? '[Array]'
: printArray(
: (min ? '' : val.constructor.name + ' ') +
'[' +
printList(
val,
indent,
prevIndent,
Expand All @@ -607,11 +535,13 @@ function printComplexValue(
printFunctionName,
escapeRegex,
colors,
);
) +
']';
} else if (toStringed === '[object Map]') {
return hitMaxDepth
? '[Map]'
: printMap(
: 'Map {' +
printMap(
val,
indent,
prevIndent,
Expand All @@ -626,11 +556,13 @@ function printComplexValue(
printFunctionName,
escapeRegex,
colors,
);
) +
'}';
} else if (toStringed === '[object Set]') {
return hitMaxDepth
? '[Set]'
: printSet(
: 'Set {' +
printSet(
val,
indent,
prevIndent,
Expand All @@ -645,12 +577,15 @@ function printComplexValue(
printFunctionName,
escapeRegex,
colors,
);
) +
'}';
}

return hitMaxDepth
? '[Object]'
: printObject(
: (min ? '' : val.constructor ? val.constructor.name + ' ' : 'Object ') +
'{' +
printObject(
val,
indent,
prevIndent,
Expand All @@ -665,7 +600,8 @@ function printComplexValue(
printFunctionName,
escapeRegex,
colors,
);
) +
'}';
}

function printPlugin(
Expand Down