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

Added "key" prop to list items inside test failure message. #2867

Merged
merged 7 commits into from
Feb 18, 2018
30 changes: 18 additions & 12 deletions addons/jest/src/components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const StackTrace = glamorous(({ trace, className }) => (
.join('')
.trim()
.split(/\n/)
.map(i => <div>{i.trim()}</div>)}
// eslint-disable-next-line react/no-array-index-key
.map((traceLine, traceLineIndex) => <div key={traceLineIndex}>{traceLine.trim()}</div>)}
</details>
))({
background: 'silver',
Expand Down Expand Up @@ -80,6 +81,11 @@ const createSubgroup = (acc, item, i, list) => {
if (!acc.grouped) {
acc.grouped = [];
}
if (!('grouperIndex' in acc)) {
acc.grouperIndex = 0;
} else {
acc.grouperIndex += 1;
}

// start or stop extraction
if (acc.startTrigger(item)) {
Expand All @@ -104,11 +110,11 @@ const createSubgroup = (acc, item, i, list) => {
switch (true) {
case acc.injectionPoint === 0 && ei === 0: {
// at index 0, inject before
return eacc.concat(acc.grouper(acc.grouped)).concat(el);
return eacc.concat(acc.grouper(acc.grouped, acc.grouperIndex)).concat(el);
}
case acc.injectionPoint > 0 && acc.injectionPoint === ei + 1: {
// at index > 0, and next index WOULD BE injectionPoint, inject after
return eacc.concat(el).concat(acc.grouper(acc.grouped));
return eacc.concat(el).concat(acc.grouper(acc.grouped, acc.grouperIndex));
}
default: {
// do not inject
Expand All @@ -131,26 +137,26 @@ const Message = ({ msg }) => {
(item, li) =>
typeof item === 'string'
? item
.split(/\[32m(.*?)\[39m/)
// eslint-disable-next-line react/no-array-index-key
.map((i, index) => (index % 2 ? <Positive key={`p_${li}_${i}`}>{i}</Positive> : i))
.split(/\[32m(.*?)\[39m/)
// eslint-disable-next-line react/no-array-index-key
.map((i, index) => (index % 2 ? <Positive key={`p_${li}_${i}`}>{i}</Positive> : i))
: item
)
.reduce((acc, item) => acc.concat(item), [])
.map(
(item, li) =>
typeof item === 'string'
? item
.split(/\[31m(.*?)\[39m/)
// eslint-disable-next-line react/no-array-index-key
.map((i, index) => (index % 2 ? <Negative key={`n_${li}_${i}`}>{i}</Negative> : i))
.split(/\[31m(.*?)\[39m/)
// eslint-disable-next-line react/no-array-index-key
.map((i, index) => (index % 2 ? <Negative key={`n_${li}_${i}`}>{i}</Negative> : i))
: item
)
.reduce((acc, item) => acc.concat(item), [])
.reduce(createSubgroup, {
startTrigger: e => typeof e === 'string' && e.indexOf('Error: ') === 0,
endTrigger: e => typeof e === 'string' && e.match('Expected '),
grouper: list => <Main msg={list} />,
grouper: (list, key) => <Main key={key} msg={list} />,
})
.reduce(
(acc, it) =>
Expand All @@ -161,12 +167,12 @@ const Message = ({ msg }) => {
.reduce(createSubgroup, {
startTrigger: e => typeof e === 'string' && e.indexOf('Expected ') !== -1,
endTrigger: e => typeof e === 'string' && e.match(/^at/),
grouper: list => <Sub msg={list} />,
grouper: (list, key) => <Sub key={key} msg={list} />,
})
.reduce(createSubgroup, {
startTrigger: e => typeof e === 'string' && e.match(/at(.|\n)+\d+:\d+\)/),
endTrigger: () => false,
grouper: list => <StackTrace trace={list} />,
grouper: (list, key) => <StackTrace key={key} trace={list} />,
});

return <Pre>{data}</Pre>;
Expand Down