Skip to content

Commit 08154cb

Browse files
committed
test
1 parent 8574543 commit 08154cb

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { JSDOM } from 'jsdom';
2+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
3+
4+
const TEST_DSN = 'https://public@dsn.ingest.sentry.io/1337';
5+
6+
function didWarnAboutDebugRemoved(warnSpy: ReturnType<typeof vi.spyOn>): boolean {
7+
return warnSpy.mock.calls.some(call =>
8+
call.some(
9+
arg =>
10+
typeof arg === 'string' &&
11+
arg.includes('You have enabled `debug: true`') &&
12+
arg.includes('debug logging was removed from your bundle'),
13+
),
14+
);
15+
}
16+
17+
describe('debug: true + removeDebugLogging warning', () => {
18+
let dom: JSDOM;
19+
let originalDocument: unknown;
20+
let originalLocation: unknown;
21+
let originalAddEventListener: unknown;
22+
23+
beforeAll(() => {
24+
dom = new JSDOM('<!doctype html><html><head></head><body></body></html>', { url: 'https://example.com/' });
25+
26+
originalDocument = (globalThis as any).document;
27+
originalLocation = (globalThis as any).location;
28+
originalAddEventListener = (globalThis as any).addEventListener;
29+
30+
Object.defineProperty(globalThis, 'document', { value: dom.window.document, writable: true });
31+
Object.defineProperty(globalThis, 'location', { value: dom.window.location, writable: true });
32+
Object.defineProperty(globalThis, 'addEventListener', { value: () => undefined, writable: true });
33+
});
34+
35+
afterAll(() => {
36+
Object.defineProperty(globalThis, 'document', { value: originalDocument, writable: true });
37+
Object.defineProperty(globalThis, 'location', { value: originalLocation, writable: true });
38+
Object.defineProperty(globalThis, 'addEventListener', { value: originalAddEventListener, writable: true });
39+
});
40+
41+
afterEach(() => {
42+
vi.restoreAllMocks();
43+
vi.resetModules();
44+
vi.unmock('../../src/common/debug-build.js');
45+
delete process.env.NEXT_OTEL_FETCH_DISABLED;
46+
delete process.env.NEXT_PHASE;
47+
});
48+
49+
it('warns on client/server/edge when debug is true but DEBUG_BUILD is false', async () => {
50+
vi.doMock('../../src/common/debug-build.js', () => ({ DEBUG_BUILD: false }));
51+
52+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
53+
54+
const client = await import('../../src/client/index.js');
55+
client.init({ dsn: TEST_DSN, debug: true } as any);
56+
57+
const server = await import('../../src/server/index.js');
58+
server.init({ dsn: TEST_DSN, debug: true } as any);
59+
60+
const edge = await import('../../src/edge/index.js');
61+
edge.init({ dsn: TEST_DSN, debug: true } as any);
62+
63+
expect(didWarnAboutDebugRemoved(warnSpy)).toBe(true);
64+
});
65+
66+
it('does not emit that warning when DEBUG_BUILD is true', async () => {
67+
vi.doMock('../../src/common/debug-build.js', () => ({ DEBUG_BUILD: true }));
68+
69+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
70+
71+
const client = await import('../../src/client/index.js');
72+
client.init({ dsn: TEST_DSN, debug: true } as any);
73+
74+
const server = await import('../../src/server/index.js');
75+
server.init({ dsn: TEST_DSN, debug: true } as any);
76+
77+
const edge = await import('../../src/edge/index.js');
78+
edge.init({ dsn: TEST_DSN, debug: true } as any);
79+
80+
expect(didWarnAboutDebugRemoved(warnSpy)).toBe(false);
81+
});
82+
});

0 commit comments

Comments
 (0)