UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

96 lines 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const Constants_1 = require("../../lib/Constants"); const utils_1 = require("../utils"); //@ts-expect-error - clifty is ESM only const clifty_1 = require("clifty"); // Expects React Router >= 7.9.5 async function runWizardWithInstrumentationAPI(projectDir) { const wizardInteraction = (0, clifty_1.withEnv)({ cwd: projectDir, }).defineInteraction(); wizardInteraction .whenAsked('Please select your package manager.') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) .expectOutput('Installing @sentry/react-router') .expectOutput('Installed @sentry/react-router', { timeout: 240000, }) .whenAsked('Do you want to enable Tracing') .respondWith(clifty_1.KEYS.ENTER) // Yes .whenAsked('Do you want to enable Session Replay') .respondWith(clifty_1.KEYS.ENTER) // Yes .whenAsked('Do you want to enable Logs') .respondWith(clifty_1.KEYS.ENTER) // Yes .whenAsked('Do you want to enable Profiling') .respondWith(clifty_1.KEYS.ENTER) // Yes .whenAsked('Do you want to use the Instrumentation API') .respondWith(clifty_1.KEYS.ENTER) // Yes .expectOutput('Installing @sentry/profiling-node') .expectOutput('Installed @sentry/profiling-node', { timeout: 240000, }) .whenAsked('Do you want to create an example page') .respondWith(clifty_1.KEYS.ENTER); // Yes return wizardInteraction .whenAsked('Optionally add a project-scoped MCP server configuration for the Sentry MCP?') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // No .expectOutput('Successfully installed the Sentry React Router SDK!') .run((0, utils_1.getWizardCommand)(Constants_1.Integration.reactRouter)); } (0, vitest_1.describe)('React Router Instrumentation API', () => { (0, vitest_1.describe)('with Instrumentation API enabled', () => { let wizardExitCode; const { projectDir, cleanup } = (0, utils_1.createIsolatedTestEnv)('react-router-test-app'); (0, vitest_1.beforeAll)(async () => { wizardExitCode = await runWizardWithInstrumentationAPI(projectDir); }); (0, vitest_1.afterAll)(() => { cleanup(); }); (0, vitest_1.test)('exits with exit code 0', () => { (0, vitest_1.expect)(wizardExitCode).toBe(0); }); (0, vitest_1.test)('package.json is updated correctly', () => { (0, utils_1.checkPackageJson)(projectDir, '@sentry/react-router'); }); (0, vitest_1.test)('.env.sentry-build-plugin is created and contains the auth token', () => { (0, utils_1.checkEnvBuildPlugin)(projectDir); }); (0, vitest_1.test)('entry.client file contains Instrumentation API setup', () => { (0, utils_1.checkFileContents)(`${projectDir}/app/entry.client.tsx`, [ 'import * as Sentry from', '@sentry/react-router', 'const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });', 'integrations: [tracing', 'unstable_instrumentations={[tracing.clientInstrumentation]}', ]); }); (0, vitest_1.test)('entry.server file contains Sentry server hooks', () => { (0, utils_1.checkFileContents)(`${projectDir}/app/entry.server.tsx`, [ 'import * as Sentry from', '@sentry/react-router', 'Sentry.wrapSentryHandleRequest(', 'export const handleError = Sentry.createSentryHandleError(', 'export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()]', ]); }); (0, vitest_1.test)('instrument.server file exists', () => { (0, utils_1.checkFileExists)(`${projectDir}/instrument.server.mjs`); }); (0, vitest_1.test)('example page exists', () => { (0, utils_1.checkFileExists)(`${projectDir}/app/routes/sentry-example-page.tsx`); }); (0, vitest_1.test)('builds successfully', async () => { await (0, utils_1.checkIfBuilds)(projectDir); }, 60000); (0, vitest_1.test)('runs on dev mode correctly', async () => { await (0, utils_1.checkIfRunsOnDevMode)(projectDir, 'to expose'); }, 30000); (0, vitest_1.test)('runs on prod mode correctly', async () => { await (0, utils_1.checkIfRunsOnProdMode)(projectDir, 'react-router-serve'); }, 30000); }); }); //# sourceMappingURL=react-router-instrumentation-api.test.js.map