fix(reporter): guard against non-finite slowTestThreshold in summary … · vitest-dev/vitest@f362f96 (original) (raw)

File tree

Original file line number Diff line number Diff line change
@@ -146,6 +146,10 @@ export class SummaryReporter implements Reporter {
146 146 stats.hook?.onFinish?.()
147 147 stats.hook = hook
148 148
149 +if (!Number.isFinite(this.ctx.config.slowTestThreshold)) {
150 +return
151 +}
152 +
149 153 const timeout = setTimeout(() => {
150 154 hook.visible = true
151 155 }, this.ctx.config.slowTestThreshold).unref()
@@ -183,9 +187,11 @@ export class SummaryReporter implements Reporter {
183 187 onFinish: () => {},
184 188 }
185 189
186 -const timeout = setTimeout(() => {
187 -slowTest.visible = true
188 -}, this.ctx.config.slowTestThreshold).unref()
190 +const timeout = Number.isFinite(this.ctx.config.slowTestThreshold)
191 + ? setTimeout(() => {
192 +slowTest.visible = true
193 +}, this.ctx.config.slowTestThreshold).unref()
194 + : undefined
189 195
190 196 slowTest.onFinish = () => {
191 197 slowTest.hook?.onFinish()
Original file line number Diff line number Diff line change
@@ -185,6 +185,15 @@ test('hides skipped tests when --hideSkippedTests and in non-TTY', async () => {
185 185 `)
186 186 })
187 187
188 +test('slowTestThreshold: Infinity does not trigger TimeoutOverflowWarning', async () => {
189 +const { stderr } = await runVitest({
190 +root: 'fixtures/reporters/duration',
191 +reporters: [['verbose', { isTTY: true, summary: true }]],
192 +slowTestThreshold: Infinity,
193 +})
194 +expect(stderr).not.toContain('TimeoutOverflowWarning')
195 +})
196 +
188 197 function trimReporterOutput(report: string) {
189 198 const rows = report.replace(/\d+ms/g, '[...]ms').split('\n')
190 199