Skip to content

Commit 14f9ab7

Browse files
committed
fix: respect verbose config
Fixes #6
1 parent 3864113 commit 14f9ab7

File tree

3 files changed

+191
-32
lines changed

3 files changed

+191
-32
lines changed

src/Reporter.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SnapshotStatus } from './SnapshotStatus';
1010
import { Summary } from './Summary';
1111
import { DisplayName, FormattedPath, ResultHeader, Runs } from './shared';
1212
import { PostMessage } from './PostMessage';
13+
import { VerboseTestList } from './VerboseTests';
1314

1415
type ConsoleBuffer = NonNullable<TestResult['console']>;
1516
type LogType = ConsoleBuffer[0]['type'];
@@ -94,6 +95,10 @@ const CompletedTests: React.FC<{
9495
{completedTests.map(({ testResult, config }) => (
9596
<React.Fragment key={testResult.testFilePath + config.name}>
9697
<ResultHeader config={config} testResult={testResult} />
98+
<VerboseTestList
99+
testResult={testResult}
100+
globalConfig={globalConfig}
101+
/>
97102
<TestConsoleOutput
98103
console={testResult.console}
99104
verbose={globalConfig.verbose}

src/Summary.tsx

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ const SummaryHeading: React.FC = ({ children }) => (
1313
</Box>
1414
);
1515

16+
const RightPaddedWithComma: React.FC = ({ children }) => (
17+
<Box paddingRight={1}>
18+
<Text>{children},</Text>
19+
</Box>
20+
);
21+
1622
export const Summary: React.FC<{
1723
aggregatedResults: AggregatedResult;
1824
done: boolean;
@@ -90,12 +96,11 @@ export const Summary: React.FC<{
9096
<SummaryHeading>Tests</SummaryHeading>
9197
<Box>
9298
{testsFailed > 0 && (
93-
<>
99+
<RightPaddedWithComma>
94100
<Color bold red>
95101
{testsFailed} failed
96102
</Color>
97-
,{' '}
98-
</>
103+
</RightPaddedWithComma>
99104
)}
100105
{testsPending > 0 && (
101106
<>
@@ -106,20 +111,18 @@ export const Summary: React.FC<{
106111
</>
107112
)}
108113
{testsTodo > 0 && (
109-
<>
114+
<RightPaddedWithComma>
110115
<Color bold magenta>
111116
{testsTodo} todo
112117
</Color>
113-
,{' '}
114-
</>
118+
</RightPaddedWithComma>
115119
)}
116120
{testsPassed > 0 && (
117-
<>
121+
<RightPaddedWithComma>
118122
<Color bold green>
119123
{testsPassed} passed
120124
</Color>
121-
,{' '}
122-
</>
125+
</RightPaddedWithComma>
123126
)}
124127
{testsTotal} total
125128
</Box>
@@ -128,20 +131,18 @@ export const Summary: React.FC<{
128131
<SummaryHeading>Snapshots</SummaryHeading>
129132
<Box>
130133
{snapshotsFailed > 0 && (
131-
<>
134+
<RightPaddedWithComma>
132135
<Color bold red>
133136
{snapshotsFailed} failed
134137
</Color>
135-
,{' '}
136-
</>
138+
</RightPaddedWithComma>
137139
)}
138140
{snapshotsOutdated > 0 && !snapshotsDidUpdate && (
139-
<>
141+
<RightPaddedWithComma>
140142
<Color bold yellow>
141143
{snapshotsOutdated} obsolete
142144
</Color>
143-
,{' '}
144-
</>
145+
</RightPaddedWithComma>
145146
)}
146147
{snapshotsOutdated > 0 && snapshotsDidUpdate && (
147148
<>
@@ -152,54 +153,48 @@ export const Summary: React.FC<{
152153
</>
153154
)}
154155
{snapshotsFilesRemoved > 0 && !snapshotsDidUpdate && (
155-
<>
156+
<RightPaddedWithComma>
156157
<Color bold yellow>
157158
{pluralize('file', snapshotsFilesRemoved)} obsolete
158159
</Color>
159-
,{' '}
160-
</>
160+
</RightPaddedWithComma>
161161
)}
162162
{snapshotsFilesRemoved > 0 && snapshotsDidUpdate && (
163-
<>
163+
<RightPaddedWithComma>
164164
<Color bold green>
165165
{pluralize('file', snapshotsFilesRemoved)} removed
166166
</Color>
167-
,{' '}
168-
</>
167+
</RightPaddedWithComma>
169168
)}
170169
{snapshotsUpdated > 0 && (
171-
<>
170+
<RightPaddedWithComma>
172171
<Color bold green>
173172
{snapshotsUpdated} updated
174173
</Color>
175-
,{' '}
176-
</>
174+
</RightPaddedWithComma>
177175
)}
178176
{snapshotsAdded > 0 && (
179-
<>
177+
<RightPaddedWithComma>
180178
<Color bold green>
181179
{snapshotsAdded} written
182180
</Color>
183-
,{' '}
184-
</>
181+
</RightPaddedWithComma>
185182
)}
186183
{snapshotsPassed > 0 && (
187-
<>
184+
<RightPaddedWithComma>
188185
<Color bold green>
189186
{snapshotsPassed} passed
190187
</Color>
191-
,{' '}
192-
</>
188+
</RightPaddedWithComma>
193189
)}
194190
{snapshotsTotal} total
195191
</Box>
196192
</Box>
197-
198193
<Box>
199194
<SummaryHeading>Time</SummaryHeading>
200-
201195
<Time runTime={runTime} estimatedTime={estimatedTime} />
202196
</Box>
197+
203198
<ProgressBar
204199
done={done}
205200
runTime={runTime}

src/VerboseTests.tsx

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import * as React from 'react';
2+
import { Box, Color, Text } from 'ink';
3+
import { Config } from '@jest/types';
4+
import { AssertionResult, Suite, TestResult } from '@jest/test-result';
5+
import { VerboseReporter } from '@jest/reporters';
6+
import { specialChars } from 'jest-util';
7+
8+
const { ICONS } = specialChars;
9+
10+
const Status: React.FC<{ status: AssertionResult['status'] }> = ({
11+
status,
12+
}) => {
13+
if (status === 'failed') {
14+
return <Color red>{ICONS.failed}</Color>;
15+
}
16+
if (status === 'pending') {
17+
return <Color yellow>{ICONS.pending}</Color>;
18+
}
19+
if (status === 'todo') {
20+
return <Color magenta>{ICONS.todo}</Color>;
21+
}
22+
return <Color green>{ICONS.success}</Color>;
23+
};
24+
25+
const TestLine: React.FC<{ test: AssertionResult; indentation: number }> = ({
26+
test,
27+
indentation,
28+
}) => (
29+
<Box paddingLeft={indentation}>
30+
<Box paddingRight={1}>
31+
<Status status={test.status} />
32+
</Box>
33+
<Color dim>{test.title}</Color>
34+
{test.duration ? (
35+
<Box paddingLeft={1}>
36+
<Color dim>({test.duration.toFixed(0)}ms)</Color>
37+
</Box>
38+
) : null}
39+
</Box>
40+
);
41+
const NotExpandedTestLine: React.FC<{
42+
test: AssertionResult;
43+
indentation: number;
44+
}> = ({ test, indentation }) => (
45+
<Box paddingLeft={indentation}>
46+
<Box paddingRight={1}>
47+
<Status status={test.status} />
48+
</Box>
49+
<Color dim>
50+
{test.status === 'pending' ? 'skipped' : test.status} {test.title}
51+
</Color>
52+
</Box>
53+
);
54+
55+
const TestsLog: React.FC<{
56+
tests: Suite['tests'];
57+
indendation: number;
58+
expand: boolean;
59+
}> = ({ tests, expand, indendation }) => {
60+
if (expand) {
61+
return (
62+
<>
63+
{tests.map((test, i) => (
64+
<TestLine key={i} test={test} indentation={indendation} />
65+
))}
66+
</>
67+
);
68+
}
69+
70+
const summedTests = tests.reduce<{
71+
pending: Suite['tests'];
72+
todo: Suite['tests'];
73+
render: Suite['tests'];
74+
}>(
75+
(result, test) => {
76+
if (test.status === 'pending') {
77+
result.pending.push(test);
78+
} else if (test.status === 'todo') {
79+
result.todo.push(test);
80+
} else {
81+
result.render.push(test);
82+
}
83+
84+
return result;
85+
},
86+
{ pending: [], todo: [], render: [] },
87+
);
88+
89+
return (
90+
<Box flexDirection="column">
91+
{summedTests.render.map((test, i) => (
92+
<TestLine key={i} test={test} indentation={indendation} />
93+
))}
94+
{summedTests.pending.map((test, i) => (
95+
<NotExpandedTestLine
96+
key={`pending${i}`}
97+
test={test}
98+
indentation={indendation}
99+
/>
100+
))}
101+
{summedTests.todo.map((test, i) => (
102+
<NotExpandedTestLine
103+
key={`pending${i}`}
104+
test={test}
105+
indentation={indendation}
106+
/>
107+
))}
108+
</Box>
109+
);
110+
};
111+
112+
const SuiteLog: React.FC<{
113+
indendation: number;
114+
suite: Suite;
115+
globalConfig: Config.GlobalConfig;
116+
}> = ({ globalConfig, indendation, suite }) => {
117+
const newIndentation = indendation + 1;
118+
119+
return (
120+
<Box paddingLeft={indendation} flexDirection="column">
121+
{suite.title ? <Text>{suite.title}</Text> : null}
122+
123+
<TestsLog
124+
tests={suite.tests}
125+
indendation={newIndentation}
126+
expand={globalConfig.expand}
127+
/>
128+
{suite.suites.map((inner, i) => (
129+
<SuiteLog
130+
key={i}
131+
globalConfig={globalConfig}
132+
indendation={newIndentation}
133+
suite={inner}
134+
/>
135+
))}
136+
</Box>
137+
);
138+
};
139+
140+
export const VerboseTestList: React.FC<{
141+
testResult: TestResult;
142+
globalConfig: Config.GlobalConfig;
143+
}> = ({ testResult, globalConfig }) => {
144+
if (!globalConfig.verbose) {
145+
return null;
146+
}
147+
148+
const groupedTests = VerboseReporter.groupTestsBySuites(
149+
testResult.testResults,
150+
);
151+
152+
return (
153+
<SuiteLog
154+
suite={groupedTests}
155+
indendation={0}
156+
globalConfig={globalConfig}
157+
/>
158+
);
159+
};

0 commit comments

Comments
 (0)