|
1 | 1 | import { relative, resolve } from 'pathe' |
2 | 2 | import { expect, test } from 'vitest' |
3 | 3 | import { DefaultReporter } from 'vitest/node' |
4 | | -import { runInlineTests, runVitest } from '../../test-utils' |
| 4 | +import { runInlineTests, runVitest, ts } from '../../test-utils' |
5 | 5 |
|
6 | 6 | test('can run custom pools with Vitest', async () => { |
7 | 7 | const reporter = new DefaultReporter() |
@@ -152,3 +152,45 @@ test('onConsoleLog receives the entity', async () => { |
152 | 152 | ] |
153 | 153 | `) |
154 | 154 | }) |
| 155 | + |
| 156 | +// https://github.com/vitest-dev/vitest/issues/11153 |
| 157 | +test('console log sent while the worker closes is not reported as an error', async () => { |
| 158 | + const { stderr, testTree } = await runInlineTests( |
| 159 | + { |
| 160 | + 'late-log.test.ts': ts` |
| 161 | + import { test } from 'vitest' |
| 162 | +
|
| 163 | + test('logs and leaks an interval', () => { |
| 164 | + console.log('log inside the test') |
| 165 | + let ticks = 0 |
| 166 | + const interval = setInterval(() => { |
| 167 | + console.log('log after the test') |
| 168 | + if (++ticks === 50) { |
| 169 | + clearInterval(interval) |
| 170 | + } |
| 171 | + }, 2) |
| 172 | + }) |
| 173 | + `, |
| 174 | + }, |
| 175 | + { |
| 176 | + reporters: [ |
| 177 | + 'verbose', |
| 178 | + { |
| 179 | + async onUserConsoleLog() { |
| 180 | + // keep every log pending, so the worker closes while the late logs wait for an answer |
| 181 | + await new Promise((resolve) => setTimeout(resolve, 20)) |
| 182 | + }, |
| 183 | + }, |
| 184 | + ], |
| 185 | + }, |
| 186 | + ) |
| 187 | + |
| 188 | + expect(stderr).toBe('') |
| 189 | + expect(testTree()).toMatchInlineSnapshot(` |
| 190 | + { |
| 191 | + "late-log.test.ts": { |
| 192 | + "logs and leaks an interval": "passed", |
| 193 | + }, |
| 194 | + } |
| 195 | + `) |
| 196 | +}) |
0 commit comments