-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathtypescript.test.ts
116 lines (98 loc) · 3.8 KB
/
typescript.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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 type { NuxtConfig } from '@nuxt/types'
import { generatePort, 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 (typescript)', () => {
let nuxt: Nuxt
let browser: Browser
beforeAll(async () => {
await localServer.start(TEST_DSN)
const dsn = localServer.getDsn()!
const port = await generatePort()
const overrides: NuxtConfig = {
sentry: { dsn },
server: { port },
publicRuntimeConfig: { baseURL: url('') },
}
const config = loadConfig(__dirname, 'typescript', overrides, { merge: true })
nuxt = (await setup(config)).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('reads serverConfig from external file', 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')
// Coming from `serverConfig` file-based configuration
expect(reports[0].extra).toBeDefined()
expect(reports[0].extra!.foo).toBe('1')
})
test('catches a server crash in server middleware', async () => {
const page = await browser.newPage()
const response = await page.goto(url('/?crashOnLoadInApi=1'))
expect(response!.status()).toBe(200)
const reports = testkit.reports()
expect(reports).toHaveLength(1)
expect(reports[0].error?.message).toContain('apiCrash is not defined')
expect(reports[0].error?.stacktrace).toMatchObject({
frames: expect.arrayContaining([
expect.objectContaining({
filename: 'app:///api/index.ts',
}),
]),
})
})
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')
})
test('can disable integrations that SDK enables by default', async () => {
const page = await browser.newPage()
await page.goto(url('/disabled-integrations'))
const clientParagraph = await $$('#client', page)
expect(clientParagraph).not.toBeNull()
expect(clientParagraph!.trim()).toBe('Dedupe: DISABLED')
const serverParagraph = await $$('#server', page)
expect(serverParagraph).not.toBeNull()
expect(serverParagraph!.trim()).toBe('Modules: DISABLED')
})
// TODO: Add tests for custom integration. Blocked by various sentry-kit bugs reported in its repo.
})