|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { runInlineTests } from '../../test-utils' |
| 3 | + |
| 4 | +test('non-Error string thrown from env setup surfaces in stderr', async () => { |
| 5 | + const { stderr } = await runInlineTests({ |
| 6 | + 'throwing-env.js': ` |
| 7 | +export default { |
| 8 | + name: 'throwing-env', |
| 9 | + transformMode: 'ssr', |
| 10 | + async setup() { |
| 11 | + throw 'the real reason setup failed (a non-Error value)' |
| 12 | + }, |
| 13 | +} |
| 14 | + `, |
| 15 | + 'vitest.config.js': ` |
| 16 | +import { defineConfig } from 'vitest/config' |
| 17 | +export default defineConfig({ |
| 18 | + test: { |
| 19 | + environment: './throwing-env.js', |
| 20 | + }, |
| 21 | +}) |
| 22 | + `, |
| 23 | + 'example.test.js': ` |
| 24 | +import { test, expect } from 'vitest' |
| 25 | +test('noop', () => { expect(1).toBe(1) }) |
| 26 | + `, |
| 27 | + }) |
| 28 | + |
| 29 | + expect(stderr).toContain('Failed to start') |
| 30 | + expect(stderr).toContain('the real reason setup failed (a non-Error value)') |
| 31 | +}) |
| 32 | + |
| 33 | +test('non-Error plain object thrown from env setup surfaces in stderr', async () => { |
| 34 | + const { stderr } = await runInlineTests({ |
| 35 | + 'throwing-env.js': ` |
| 36 | +export default { |
| 37 | + name: 'throwing-env', |
| 38 | + transformMode: 'ssr', |
| 39 | + async setup() { |
| 40 | + throw { reason: 'wasm-init-failed', code: 42 } |
| 41 | + }, |
| 42 | +} |
| 43 | + `, |
| 44 | + 'vitest.config.js': ` |
| 45 | +import { defineConfig } from 'vitest/config' |
| 46 | +export default defineConfig({ |
| 47 | + test: { |
| 48 | + environment: './throwing-env.js', |
| 49 | + }, |
| 50 | +}) |
| 51 | + `, |
| 52 | + 'example.test.js': ` |
| 53 | +import { test, expect } from 'vitest' |
| 54 | +test('noop', () => { expect(1).toBe(1) }) |
| 55 | + `, |
| 56 | + }) |
| 57 | + |
| 58 | + expect(stderr).toContain('Failed to start') |
| 59 | + expect(stderr).toMatch(/wasm-init-failed|reason/) |
| 60 | +}) |
| 61 | + |
| 62 | +test('Error thrown from env setup still renders with Caused by prefix', async () => { |
| 63 | + const { stderr } = await runInlineTests({ |
| 64 | + 'throwing-env.js': ` |
| 65 | +export default { |
| 66 | + name: 'throwing-env', |
| 67 | + transformMode: 'ssr', |
| 68 | + async setup() { |
| 69 | + throw new Error('explicit error reason') |
| 70 | + }, |
| 71 | +} |
| 72 | + `, |
| 73 | + 'vitest.config.js': ` |
| 74 | +import { defineConfig } from 'vitest/config' |
| 75 | +export default defineConfig({ |
| 76 | + test: { |
| 77 | + environment: './throwing-env.js', |
| 78 | + }, |
| 79 | +}) |
| 80 | + `, |
| 81 | + 'example.test.js': ` |
| 82 | +import { test, expect } from 'vitest' |
| 83 | +test('noop', () => { expect(1).toBe(1) }) |
| 84 | + `, |
| 85 | + }) |
| 86 | + |
| 87 | + expect(stderr).toContain('Failed to start') |
| 88 | + expect(stderr).toContain('Caused by') |
| 89 | + expect(stderr).toContain('explicit error reason') |
| 90 | +}) |
0 commit comments