-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathdefault.test.ts
75 lines (62 loc) · 2.36 KB
/
default.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { describe, afterAll, beforeAll, beforeEach, test, expect } from 'vitest'
import type { Browser } from 'playwright-chromium'
import sentryTestkit from 'sentry-testkit'
import { setup, url } from '@nuxtjs/module-test-utils'
import type { Nuxt } from '../src/kit-shim'
import { $$, createBrowser, loadConfig } from './utils'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const { testkit, localServer } = sentryTestkit.default()
const TEST_DSN = 'http://[email protected]/000001'
describe('Smoke test (default)', () => {
let nuxt: Nuxt
let browser: Browser
beforeAll(async () => {
await localServer.start(TEST_DSN)
const dsn = localServer.getDsn() ?? undefined
nuxt = (await setup(loadConfig(__dirname, 'default', { sentry: { dsn } }, { merge: true }))).nuxt
browser = await createBrowser()
})
afterAll(async () => {
if (browser) {
await browser.close()
}
await nuxt.close()
await localServer.stop()
})
beforeEach(() => {
testkit.reset()
})
test('builds and runs', async () => {
const page = await browser.newPage()
const errors: string[] = []
page.on('pageerror', (error) => {
errors.push(error.message)
})
await page.goto(url('/'))
// process.sentry is not initialized in webpack context in tests.
// expect(await $$('#server-side', page)).toBe('Works!')
expect(await $$('#client-side', page)).toBe('Works!')
expect(errors).toEqual([])
})
test('catches a server crash', async () => {
const page = await browser.newPage()
const response = await page.goto(url('/?crashOnLoad=1'))
expect(response!.status()).toBe(500)
const reports = testkit.reports()
expect(reports).toHaveLength(1)
expect(reports[0].error?.message).toContain('crashOnLoad is not defined')
})
test('catches a client crash', async () => {
const page = await browser.newPage()
await page.goto(url('/'))
expect(await $$('#client-side', page)).toBe('Works!')
await page.click('#crash-button')
const reports = testkit.reports()
expect(reports).toHaveLength(1)
expect(reports[0].error?.message).toContain('crash_me is not a function')
})
// TODO: Add tests for custom integration. Blocked by various sentry-kit bugs reported in its repo.
})