Skip to content
Merged
Changes from 1 commit
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
28 changes: 16 additions & 12 deletions addons/jest/src/components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const StackTrace = glamorous(({ trace, className }) => (
.join('')
.trim()
.split(/\n/)
.map(i => <div>{i.trim()}</div>)}
.map(traceLine, traceLineIndex => <div key={traceLineIndex}>{traceLine.trim()}</div>)}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a chance we can use something other than index as a key? Otherwise, I think you can suppress the corresponding eslint rule for this line

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'd like to use something else for the key prop but can't find any reasonable alternatives. I will add the ESLint rule.

</details>
))({
background: 'silver',
Expand Down Expand Up @@ -80,6 +80,10 @@ const createSubgroup = (acc, item, i, list) => {
if (!acc.grouped) {
acc.grouped = [];
}
if (!('grouperIndex' in acc))
acc.grouperIndex = 0;
else
acc.grouperIndex++;

// start or stop extraction
if (acc.startTrigger(item)) {
Expand All @@ -104,11 +108,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 +135,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 +165,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 trace={list} />,
});

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