|
| 1 | +import { dirname, join } from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { describe, expect, it } from '@rstest/core'; |
| 4 | +import { runRstestCli } from '../scripts'; |
| 5 | + |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = dirname(__filename); |
| 8 | + |
| 9 | +// Regression test for https://github.com/web-infra-dev/rstest/issues/1367. |
| 10 | +// `a.test.ts` captures a `console` reference and flushes it from `setTimeout`s |
| 11 | +// that outlive the file. With `isolate: false` every file shares one worker, so |
| 12 | +// the late logs fire after the host has disposed a's birpc channel (and, later, |
| 13 | +// after the worker has closed it). Forwarding such a log used to leave a pending |
| 14 | +// birpc request that `$close()` rejected as `[birpc] rpc is closed`, failing the |
| 15 | +// run and misattributing it to `b.test.ts`. |
| 16 | +// |
| 17 | +// `onConsoleLog` is now a one-way event and forwarding is best-effort, so a late |
| 18 | +// log can neither crash the run nor leak past the `onConsoleLog: () => false` |
| 19 | +// suppression filter. Assert this across both pools and both isolate modes: with |
| 20 | +// `isolate: true` each file gets a fresh worker so the bug cannot occur, which |
| 21 | +// guards against a regression that only fixes one mode. |
| 22 | +describe('late console log (issue #1367)', () => { |
| 23 | + for (const pool of ['forks', 'threads'] as const) { |
| 24 | + for (const isolate of [true, false] as const) { |
| 25 | + it(`should not fail the run when a console call outlives its test file (${pool} pool, isolate: ${isolate})`, async () => { |
| 26 | + const { cli, expectExecSuccess } = await runRstestCli({ |
| 27 | + command: 'rstest', |
| 28 | + args: ['run', '--pool', pool, '--isolate', String(isolate)], |
| 29 | + options: { |
| 30 | + nodeOptions: { |
| 31 | + cwd: join(__dirname, 'fixtures/late-console'), |
| 32 | + }, |
| 33 | + }, |
| 34 | + }); |
| 35 | + |
| 36 | + await expectExecSuccess(); |
| 37 | + |
| 38 | + // The late log must not crash the run via a closed/disposed channel... |
| 39 | + expect(cli.log).not.toContain('rpc is closed'); |
| 40 | + // ...and it must stay suppressed, not leak to the raw worker stream. |
| 41 | + expect(cli.log).not.toContain('late log from a.test.ts'); |
| 42 | + }); |
| 43 | + } |
| 44 | + } |
| 45 | +}); |
0 commit comments