|
1 | | -import { expect, it, vi } from 'vitest' |
| 1 | +import { beforeAll, describe, expect, it, onTestFinished, vi } from 'vitest' |
2 | 2 |
|
3 | | -vi.stubGlobal('process', { badMock: true }) |
| 3 | +describe('undefined process', () => { |
| 4 | + // This has to be first test of the file to trigger rpc withSafeTimers race |
| 5 | + it('undefined process when importing file outside root', async () => { |
| 6 | + const realProcess = globalThis.process |
4 | 7 |
|
5 | | -it('should not hang', () => { |
6 | | - expect(1).toBe(1) |
7 | | -}) |
| 8 | + onTestFinished(async () => { |
| 9 | + globalThis.process = realProcess |
| 10 | + }) |
| 11 | + |
| 12 | + globalThis.process = undefined as any |
8 | 13 |
|
9 | | -it('should not crash (#9173)', async () => { |
10 | | - await import('./fixtures/increment') |
| 14 | + const mod = await import('../../test-utils/fixtures/external-math') |
| 15 | + expect(mod.sum(2, 3)).toBe(5) |
| 16 | + }) |
11 | 17 | }) |
12 | 18 |
|
13 | | -it('should not hang', () => { |
14 | | - vi.unstubAllGlobals() |
| 19 | +describe('stubbed process', () => { |
| 20 | + beforeAll(() => { |
| 21 | + vi.stubGlobal('process', { badMock: true }) |
| 22 | + |
| 23 | + return () => { |
| 24 | + vi.unstubAllGlobals() |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + it('should not hang', () => { |
| 29 | + expect(1).toBe(1) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should not crash (#9173)', async () => { |
| 33 | + await import('./fixtures/increment') |
| 34 | + }) |
| 35 | + |
| 36 | + it('should not hang', () => { |
| 37 | + vi.unstubAllGlobals() |
15 | 38 |
|
16 | | - process.stdout.write = () => true |
| 39 | + process.stdout.write = () => true |
| 40 | + }) |
17 | 41 | }) |
0 commit comments