UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

220 lines 15.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); // Mock makeCodeSnippet utility vitest_1.vi.mock('../../src/utils/clack', () => { return { __esModule: true, makeCodeSnippet: vitest_1.vi.fn((colors, callback) => { // Mock implementation that just calls the callback with simple string functions const unchanged = (str) => str; const plus = (str) => `+ ${str}`; const minus = (str) => `- ${str}`; return callback(unchanged, plus, minus); }), }; }); const templates_1 = require("../../src/react-router/templates"); (0, vitest_1.describe)('React Router Templates', () => { (0, vitest_1.beforeEach)(() => { vitest_1.vi.clearAllMocks(); }); (0, vitest_1.describe)('Template Constants', () => { (0, vitest_1.it)('should have correct ERROR_BOUNDARY_TEMPLATE content', () => { (0, vitest_1.expect)(templates_1.ERROR_BOUNDARY_TEMPLATE).toContain('function ErrorBoundary({ error })'); (0, vitest_1.expect)(templates_1.ERROR_BOUNDARY_TEMPLATE).toContain('isRouteErrorResponse(error)'); (0, vitest_1.expect)(templates_1.ERROR_BOUNDARY_TEMPLATE).toContain('Sentry.captureException(error)'); (0, vitest_1.expect)(templates_1.ERROR_BOUNDARY_TEMPLATE).toContain('error.status === 404'); (0, vitest_1.expect)(templates_1.ERROR_BOUNDARY_TEMPLATE).toContain('An unexpected error occurred'); }); (0, vitest_1.it)('should have correct EXAMPLE_PAGE_TEMPLATE_TSX content', () => { (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_TSX).toContain('import type { Route }'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_TSX).toContain('export async function loader()'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_TSX).toContain('throw new Error("some error thrown in a loader")'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_TSX).toContain('export default function SentryExamplePage()'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_TSX).toContain('Loading this page will throw an error'); }); (0, vitest_1.it)('should have correct EXAMPLE_PAGE_TEMPLATE_JSX content', () => { (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_JSX).not.toContain('import type { Route }'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_JSX).toContain('export async function loader()'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_JSX).toContain('throw new Error("some error thrown in a loader")'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_JSX).toContain('export default function SentryExamplePage()'); (0, vitest_1.expect)(templates_1.EXAMPLE_PAGE_TEMPLATE_JSX).toContain('Loading this page will throw an error'); }); }); (0, vitest_1.describe)('getManualClientEntryContent', () => { (0, vitest_1.it)('should generate manual client entry with all features enabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = true; const enableReplay = true; const enableLogs = true; const result = (0, templates_1.getManualClientEntryContent)(dsn, enableTracing, enableReplay, enableLogs); (0, vitest_1.expect)(result).toContain("+ import * as Sentry from '@sentry/react-router'"); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('sendDefaultPii: true'); (0, vitest_1.expect)(result).toContain('Sentry.reactRouterTracingIntegration()'); (0, vitest_1.expect)(result).toContain('Sentry.replayIntegration()'); (0, vitest_1.expect)(result).toContain('enableLogs: true'); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 1.0'); (0, vitest_1.expect)(result).toContain('replaysSessionSampleRate: 0.1'); (0, vitest_1.expect)(result).toContain('replaysOnErrorSampleRate: 1.0'); (0, vitest_1.expect)(result).toContain('tracePropagationTargets'); (0, vitest_1.expect)(result).toContain('<HydratedRouter />'); }); (0, vitest_1.it)('should generate manual client entry with tracing disabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = false; const enableReplay = true; const enableLogs = false; const result = (0, templates_1.getManualClientEntryContent)(dsn, enableTracing, enableReplay, enableLogs); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 0'); (0, vitest_1.expect)(result).not.toContain('Sentry.reactRouterTracingIntegration()'); (0, vitest_1.expect)(result).toContain('Sentry.replayIntegration()'); (0, vitest_1.expect)(result).not.toContain('enableLogs: true'); (0, vitest_1.expect)(result).not.toContain('tracePropagationTargets'); }); (0, vitest_1.it)('should generate manual client entry with replay disabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = true; const enableReplay = false; const enableLogs = true; const result = (0, templates_1.getManualClientEntryContent)(dsn, enableTracing, enableReplay, enableLogs); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 1.0'); (0, vitest_1.expect)(result).toContain('Sentry.reactRouterTracingIntegration()'); (0, vitest_1.expect)(result).not.toContain('Sentry.replayIntegration()'); (0, vitest_1.expect)(result).toContain('enableLogs: true'); (0, vitest_1.expect)(result).not.toContain('replaysSessionSampleRate'); (0, vitest_1.expect)(result).not.toContain('replaysOnErrorSampleRate'); }); (0, vitest_1.it)('should generate manual client entry with no integrations', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = false; const enableReplay = false; const enableLogs = false; const result = (0, templates_1.getManualClientEntryContent)(dsn, enableTracing, enableReplay, enableLogs); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 0'); (0, vitest_1.expect)(result).not.toContain('Sentry.reactRouterTracingIntegration()'); (0, vitest_1.expect)(result).not.toContain('Sentry.replayIntegration()'); (0, vitest_1.expect)(result).not.toContain('enableLogs: true'); (0, vitest_1.expect)(result).toContain('integrations: ['); }); }); (0, vitest_1.describe)('getManualServerEntryContent', () => { (0, vitest_1.it)('should generate manual server entry content', () => { const result = (0, templates_1.getManualServerEntryContent)(); (0, vitest_1.expect)(result).toContain("+ import * as Sentry from '@sentry/react-router'"); (0, vitest_1.expect)(result).toContain('createReadableStreamFromReadable'); (0, vitest_1.expect)(result).toContain('renderToPipeableStream'); (0, vitest_1.expect)(result).toContain('ServerRouter'); (0, vitest_1.expect)(result).toContain('+ const handleRequest = Sentry.createSentryHandleRequest({'); (0, vitest_1.expect)(result).toContain('+ export const handleError = Sentry.createSentryHandleError({'); (0, vitest_1.expect)(result).toContain('logErrors: false'); (0, vitest_1.expect)(result).toContain('export default handleRequest'); (0, vitest_1.expect)(result).toContain('rest of your server entry'); }); }); (0, vitest_1.describe)('getManualRootContent', () => { (0, vitest_1.it)('should generate manual root content for TypeScript', () => { const isTs = true; const result = (0, templates_1.getManualRootContent)(isTs); (0, vitest_1.expect)(result).toContain("+ import * as Sentry from '@sentry/react-router'"); (0, vitest_1.expect)(result).toContain('export function ErrorBoundary({ error }: Route.ErrorBoundaryProps)'); (0, vitest_1.expect)(result).toContain('let stack: string | undefined'); (0, vitest_1.expect)(result).toContain('isRouteErrorResponse(error)'); (0, vitest_1.expect)(result).toContain('+ Sentry.captureException(error)'); (0, vitest_1.expect)(result).toContain('details = error.message'); (0, vitest_1.expect)(result).toContain('error.status === 404'); }); (0, vitest_1.it)('should generate manual root content for JavaScript', () => { const isTs = false; const result = (0, templates_1.getManualRootContent)(isTs); (0, vitest_1.expect)(result).toContain("+ import * as Sentry from '@sentry/react-router'"); (0, vitest_1.expect)(result).toContain('export function ErrorBoundary({ error })'); (0, vitest_1.expect)(result).not.toContain(': Route.ErrorBoundaryProps'); (0, vitest_1.expect)(result).toContain('let stack'); (0, vitest_1.expect)(result).not.toContain(': string | undefined'); (0, vitest_1.expect)(result).toContain('isRouteErrorResponse(error)'); (0, vitest_1.expect)(result).toContain('+ Sentry.captureException(error)'); }); }); (0, vitest_1.describe)('getManualServerInstrumentContent', () => { (0, vitest_1.it)('should generate server instrumentation with all features enabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = true; const enableProfiling = true; const enableLogs = true; const result = (0, templates_1.getManualServerInstrumentContent)(dsn, enableTracing, enableProfiling, enableLogs); (0, vitest_1.expect)(result).toContain("+ import * as Sentry from '@sentry/react-router'"); (0, vitest_1.expect)(result).toContain("import { nodeProfilingIntegration } from '@sentry/profiling-node'"); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('sendDefaultPii: true'); (0, vitest_1.expect)(result).toContain('enableLogs: true'); (0, vitest_1.expect)(result).toContain('integrations: [nodeProfilingIntegration()]'); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 1.0'); (0, vitest_1.expect)(result).toContain('profilesSampleRate: 1.0'); (0, vitest_1.expect)(result).toContain('Capture 100% of the transactions'); (0, vitest_1.expect)(result).toContain('profile every transaction'); }); (0, vitest_1.it)('should generate server instrumentation with tracing disabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = false; const enableProfiling = false; const result = (0, templates_1.getManualServerInstrumentContent)(dsn, enableTracing, enableProfiling); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 0'); (0, vitest_1.expect)(result).not.toContain('nodeProfilingIntegration'); (0, vitest_1.expect)(result).not.toContain('profilesSampleRate'); (0, vitest_1.expect)(result).not.toContain('integrations: [nodeProfilingIntegration()]'); // When logs are not enabled, enableLogs should not appear (0, vitest_1.expect)(result).not.toContain('enableLogs: true'); }); (0, vitest_1.it)('should generate server instrumentation with profiling disabled but tracing enabled', () => { const dsn = 'https://test.sentry.io/123'; const enableTracing = true; const enableProfiling = false; const enableLogs = false; const result = (0, templates_1.getManualServerInstrumentContent)(dsn, enableTracing, enableProfiling, enableLogs); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); (0, vitest_1.expect)(result).toContain('tracesSampleRate: 1.0'); (0, vitest_1.expect)(result).not.toContain('nodeProfilingIntegration'); (0, vitest_1.expect)(result).not.toContain('profilesSampleRate'); (0, vitest_1.expect)(result).not.toContain('integrations:'); }); (0, vitest_1.it)('should handle special characters in DSN', () => { const dsn = 'https://test@example.com/sentry/123?param=value'; const enableTracing = true; const enableProfiling = false; const result = (0, templates_1.getManualServerInstrumentContent)(dsn, enableTracing, enableProfiling); (0, vitest_1.expect)(result).toContain(`dsn: "${dsn}"`); }); }); (0, vitest_1.describe)('getManualReactRouterConfigContent', () => { (0, vitest_1.it)('should generate TypeScript config snippet with type imports and satisfies', () => { const result = (0, templates_1.getManualReactRouterConfigContent)(true); (0, vitest_1.expect)(result).toContain('import type { Config }'); (0, vitest_1.expect)(result).toContain('} satisfies Config;'); (0, vitest_1.expect)(result).toContain('sentryOnBuildEnd'); (0, vitest_1.expect)(result).toContain('ssr: true'); }); (0, vitest_1.it)('should generate JavaScript config snippet without TS-only syntax', () => { const result = (0, templates_1.getManualReactRouterConfigContent)(false); // JS version should NOT have TypeScript-only syntax (0, vitest_1.expect)(result).not.toContain('import type'); (0, vitest_1.expect)(result).not.toContain('satisfies Config'); // JS version should have the standard import and export (0, vitest_1.expect)(result).toContain('import { sentryOnBuildEnd }'); (0, vitest_1.expect)(result).toContain('sentryOnBuildEnd'); (0, vitest_1.expect)(result).toContain('ssr: true'); (0, vitest_1.expect)(result).toContain('export default {'); }); (0, vitest_1.it)('should default to TypeScript when no parameter is passed', () => { const result = (0, templates_1.getManualReactRouterConfigContent)(); (0, vitest_1.expect)(result).toContain('import type { Config }'); (0, vitest_1.expect)(result).toContain('} satisfies Config;'); }); }); }); //# sourceMappingURL=templates.test.js.map