Skip to content

Commit e3064ca

Browse files
committed
test: added unit test for the warning
1 parent 1b175fd commit e3064ca

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import type { NitroConfig } from 'nitropack/types';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import type { SentryNuxtModuleOptions } from '../../src/common/types';
4+
import { addDatabaseInstrumentation } from '../../src/vite/databaseConfig';
5+
6+
vi.mock('@sentry/core', () => ({
7+
consoleSandbox: (callback: () => void) => callback(),
8+
}));
9+
10+
vi.mock('@nuxt/kit', () => ({
11+
addServerPlugin: vi.fn(),
12+
createResolver: vi.fn(() => ({
13+
resolve: vi.fn((path: string) => path),
14+
})),
15+
}));
16+
17+
vi.mock('../../src/vendor/server-template', () => ({
18+
addServerTemplate: vi.fn(),
19+
}));
20+
21+
describe('addDatabaseInstrumentation', () => {
22+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
23+
24+
beforeEach(() => {
25+
consoleLogSpy.mockClear();
26+
});
27+
28+
afterEach(() => {
29+
vi.clearAllMocks();
30+
});
31+
32+
describe('debug logging when no database configuration', () => {
33+
it('should log debug message when debug is enabled and no database config', () => {
34+
const nitroConfig: NitroConfig = {};
35+
const moduleOptions: SentryNuxtModuleOptions = { debug: true };
36+
37+
addDatabaseInstrumentation(nitroConfig, moduleOptions);
38+
39+
expect(consoleLogSpy).toHaveBeenCalledWith(
40+
'[Sentry] [Nitro Database Plugin]: No database configuration found. Skipping database instrumentation.',
41+
);
42+
});
43+
44+
it('should not log debug message when debug is disabled and no database config', () => {
45+
const nitroConfig: NitroConfig = {};
46+
const moduleOptions: SentryNuxtModuleOptions = { debug: false };
47+
48+
addDatabaseInstrumentation(nitroConfig, moduleOptions);
49+
50+
expect(consoleLogSpy).not.toHaveBeenCalled();
51+
});
52+
53+
it('should not log debug message when moduleOptions is undefined', () => {
54+
const nitroConfig: NitroConfig = {};
55+
56+
addDatabaseInstrumentation(nitroConfig, undefined);
57+
58+
expect(consoleLogSpy).not.toHaveBeenCalled();
59+
});
60+
61+
it('should not log debug message when debug is not set in moduleOptions', () => {
62+
const nitroConfig: NitroConfig = {};
63+
const moduleOptions: SentryNuxtModuleOptions = {};
64+
65+
addDatabaseInstrumentation(nitroConfig, moduleOptions);
66+
67+
expect(consoleLogSpy).not.toHaveBeenCalled();
68+
});
69+
70+
it('should not log debug message when experimental.database is set to false but debug is true', () => {
71+
const nitroConfig: NitroConfig = { experimental: { database: false } };
72+
const moduleOptions: SentryNuxtModuleOptions = { debug: true };
73+
74+
addDatabaseInstrumentation(nitroConfig, moduleOptions);
75+
76+
expect(consoleLogSpy).toHaveBeenCalledWith(
77+
'[Sentry] [Nitro Database Plugin]: No database configuration found. Skipping database instrumentation.',
78+
);
79+
});
80+
});
81+
});

0 commit comments

Comments
 (0)