-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathconflictingDebugOptions.test.ts
More file actions
82 lines (62 loc) · 3.1 KB
/
conflictingDebugOptions.test.ts
File metadata and controls
82 lines (62 loc) · 3.1 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
78
79
80
81
82
import { JSDOM } from 'jsdom';
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
const TEST_DSN = 'https://public@dsn.ingest.sentry.io/1337';
function didWarnAboutDebugRemoved(warnSpy: ReturnType<typeof vi.spyOn>): boolean {
return warnSpy.mock.calls.some(call =>
call.some(
arg =>
typeof arg === 'string' &&
arg.includes('You have enabled `debug: true`') &&
arg.includes('debug logging was removed from your bundle'),
),
);
}
describe('debug: true + removeDebugLogging warning', () => {
let dom: JSDOM;
let originalDocument: unknown;
let originalLocation: unknown;
let originalAddEventListener: unknown;
beforeAll(() => {
dom = new JSDOM('<!doctype html><html><head></head><body></body></html>', { url: 'https://example.com/' });
originalDocument = (globalThis as any).document;
originalLocation = (globalThis as any).location;
originalAddEventListener = (globalThis as any).addEventListener;
Object.defineProperty(globalThis, 'document', { value: dom.window.document, writable: true });
Object.defineProperty(globalThis, 'location', { value: dom.window.location, writable: true });
Object.defineProperty(globalThis, 'addEventListener', { value: () => undefined, writable: true });
});
afterAll(() => {
Object.defineProperty(globalThis, 'document', { value: originalDocument, writable: true });
Object.defineProperty(globalThis, 'location', { value: originalLocation, writable: true });
Object.defineProperty(globalThis, 'addEventListener', { value: originalAddEventListener, writable: true });
});
afterEach(() => {
vi.restoreAllMocks();
vi.resetModules();
vi.unmock('../../src/common/debug-build.js');
delete process.env.NEXT_OTEL_FETCH_DISABLED;
delete process.env.NEXT_PHASE;
});
it('warns on client/server/edge when debug is true but DEBUG_BUILD is false', async () => {
vi.doMock('../../src/common/debug-build.js', () => ({ DEBUG_BUILD: false }));
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const client = await import('../../src/client/index.js');
client.init({ dsn: TEST_DSN, debug: true } as any);
const server = await import('../../src/server/index.js');
server.init({ dsn: TEST_DSN, debug: true } as any);
const edge = await import('../../src/edge/index.js');
edge.init({ dsn: TEST_DSN, debug: true } as any);
expect(didWarnAboutDebugRemoved(warnSpy)).toBe(true);
});
it('does not emit that warning when DEBUG_BUILD is true', async () => {
vi.doMock('../../src/common/debug-build.js', () => ({ DEBUG_BUILD: true }));
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const client = await import('../../src/client/index.js');
client.init({ dsn: TEST_DSN, debug: true } as any);
const server = await import('../../src/server/index.js');
server.init({ dsn: TEST_DSN, debug: true } as any);
const edge = await import('../../src/edge/index.js');
edge.init({ dsn: TEST_DSN, debug: true } as any);
expect(didWarnAboutDebugRemoved(warnSpy)).toBe(false);
});
});