-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathenvironment.test.ts
More file actions
77 lines (59 loc) · 2.76 KB
/
environment.test.ts
File metadata and controls
77 lines (59 loc) · 2.76 KB
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
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
import { isDevMode } from './isDevMode';
test.describe('environment detection', async () => {
test('sets correct environment for client-side errors', async ({ page }) => {
const errorPromise = waitForError('nuxt-4', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-4 E2E test app';
});
// We have to wait for networkidle in dev mode because clicking the button is a no-op otherwise (network requests are blocked during page load)
await page.goto(`/client-error`, isDevMode ? { waitUntil: 'networkidle' } : {});
await page.locator('#errorBtn').click();
const error = await errorPromise;
if (isDevMode) {
expect(error.environment).toBe('development');
} else {
expect(error.environment).toBe('production');
}
});
test('sets correct environment for client-side transactions', async ({ page }) => {
const transactionPromise = waitForTransaction('nuxt-4', async transactionEvent => {
return transactionEvent.transaction === '/test-param/:param()';
});
await page.goto(`/test-param/1234`);
const transaction = await transactionPromise;
if (isDevMode) {
expect(transaction.environment).toBe('development');
} else {
expect(transaction.environment).toBe('production');
}
});
test('sets correct environment for server-side errors', async ({ page }) => {
const errorPromise = waitForError('nuxt-4', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 4 Server error';
});
await page.goto(`/fetch-server-routes`, isDevMode ? { waitUntil: 'networkidle' } : {});
await page.getByText('Fetch Server API Error', { exact: true }).click();
const error = await errorPromise;
expect(error.transaction).toBe('GET /api/server-error');
if (isDevMode) {
expect(error.environment).toBe('development');
} else {
expect(error.environment).toBe('production');
}
});
test('sets correct environment for server-side transactions', async ({ page }) => {
const transactionPromise = waitForTransaction('nuxt-4', async transactionEvent => {
return transactionEvent.transaction === 'GET /api/nitro-fetch';
});
await page.goto(`/fetch-server-routes`, isDevMode ? { waitUntil: 'networkidle' } : {});
await page.getByText('Fetch Nitro $fetch', { exact: true }).click();
const transaction = await transactionPromise;
expect(transaction.contexts.trace.op).toBe('http.server');
if (isDevMode) {
expect(transaction.environment).toBe('development');
} else {
expect(transaction.environment).toBe('production');
}
});
});