@sentry/wizard
Version:
Sentry wizard helping you to configure your project
306 lines (249 loc) • 11.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const templates_1 = require("../../src/sveltekit/templates");
vitest_1.vi.mock('../../src/utils/clack/mcp-config', () => ({
offerProjectScopedMcpConfig: vitest_1.vi.fn().mockResolvedValue(undefined),
}));
(0, vitest_1.describe)('getClientHooksTemplate', () => {
(0, vitest_1.it)('generates client hooks template with all features enabled', () => {
const result = (0, templates_1.getClientHooksTemplate)('https://sentry.io/123', {
performance: true,
replay: true,
logs: true,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
tracesSampleRate: 1.0,
// Enable logs to be sent to Sentry
enableLogs: true,
// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,
// If the entire session is not sampled, use the below sample rate to sample
// sessions when an error occurs.
replaysOnErrorSampleRate: 1.0,
// If you don't want to use Session Replay, just remove the line below:
integrations: [replayIntegration()],
});
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates client hooks template when performance disabled', () => {
const result = (0, templates_1.getClientHooksTemplate)('https://sentry.io/123', {
performance: false,
replay: true,
logs: false,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,
// If the entire session is not sampled, use the below sample rate to sample
// sessions when an error occurs.
replaysOnErrorSampleRate: 1.0,
// If you don't want to use Session Replay, just remove the line below:
integrations: [replayIntegration()],
});
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates client hooks template when replay disabled', () => {
const result = (0, templates_1.getClientHooksTemplate)('https://sentry.io/123', {
performance: true,
replay: false,
logs: false,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
tracesSampleRate: 1.0,
});
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates client hooks template with only logs enabled', () => {
const result = (0, templates_1.getClientHooksTemplate)('https://sentry.io/123', {
performance: false,
replay: false,
logs: true,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// Enable logs to be sent to Sentry
enableLogs: true,
});
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
});
(0, vitest_1.describe)('getServerHooksTemplate', () => {
(0, vitest_1.it)('generates server hooks template with all features enabled', () => {
const result = (0, templates_1.getServerHooksTemplate)('https://sentry.io/123', {
performance: true,
replay: true,
logs: true,
}, true);
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { sequence } from "@sveltejs/kit/hooks";
import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
tracesSampleRate: 1.0,
// Enable logs to be sent to Sentry
enableLogs: true,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});
// If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
export const handle = sequence(sentryHandle());
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates server hooks template when performance disabled', () => {
const result = (0, templates_1.getServerHooksTemplate)('https://sentry.io/123', {
performance: false,
replay: true,
logs: false,
}, true);
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { sequence } from "@sveltejs/kit/hooks";
import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});
// If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
export const handle = sequence(sentryHandle());
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates server hooks template with only logs enabled', () => {
const result = (0, templates_1.getServerHooksTemplate)('https://sentry.io/123', {
performance: false,
replay: false,
logs: true,
}, true);
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { sequence } from "@sveltejs/kit/hooks";
import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// Enable logs to be sent to Sentry
enableLogs: true,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});
// If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
export const handle = sequence(sentryHandle());
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
(0, vitest_1.it)('generates server hooks template without Sentry.init if includeSentryInit is false', () => {
const result = (0, templates_1.getServerHooksTemplate)('https://sentry.io/123', {
performance: false,
replay: false,
logs: true,
}, false);
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import { sequence } from "@sveltejs/kit/hooks";
import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
// If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
export const handle = sequence(sentryHandle());
// If you have a custom error handler, pass it to \`handleErrorWithSentry\`
export const handleError = handleErrorWithSentry();
"
`);
});
});
(0, vitest_1.describe)('getInstrumentationServerTemplate', () => {
(0, vitest_1.it)('generates instrumentation.server template with all features enabled', () => {
const result = (0, templates_1.getInstrumentationServerTemplate)('https://sentry.io/123', {
performance: true,
logs: true,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
tracesSampleRate: 1.0,
// Enable logs to be sent to Sentry
enableLogs: true,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});"`);
});
(0, vitest_1.it)('generates instrumentation.server template with only logs enabled', () => {
const result = (0, templates_1.getInstrumentationServerTemplate)('https://sentry.io/123', {
performance: false,
logs: true,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// Enable logs to be sent to Sentry
enableLogs: true,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});"`);
});
(0, vitest_1.it)('generates instrumentation.server template with only tracesSampleRate enabled', () => {
const result = (0, templates_1.getInstrumentationServerTemplate)('https://sentry.io/123', {
performance: true,
logs: false,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
tracesSampleRate: 1.0,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});"`);
});
(0, vitest_1.it)('generates instrumentation.server template without any extra features enabled', () => {
const result = (0, templates_1.getInstrumentationServerTemplate)('https://sentry.io/123', {
performance: false,
logs: false,
});
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/sveltekit';
Sentry.init({
dsn: 'https://sentry.io/123',
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});"`);
});
});
//# sourceMappingURL=templates.test.js.map
;