UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

208 lines (190 loc) 9.73 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("node:path")); const fs = __importStar(require("node:fs")); const Constants_1 = require("../../lib/Constants"); const utils_1 = require("../utils"); const vitest_1 = require("vitest"); //@ts-expect-error - clifty is ESM only const clifty_1 = require("clifty"); (0, vitest_1.describe)('Sveltekit with instrumentation and tracing', () => { (0, vitest_1.describe)('without existing files', () => { const projectDir = path.resolve(__dirname, '../test-applications/sveltekit-tracing-test-app'); const integration = Constants_1.Integration.sveltekit; let wizardExitCode; (0, vitest_1.beforeAll)(async () => { (0, utils_1.initGit)(projectDir); (0, utils_1.revertLocalChanges)(projectDir); wizardExitCode = await (0, clifty_1.withEnv)({ cwd: projectDir, }) .defineInteraction() .expectOutput('The Sentry SvelteKit Wizard will help you set up Sentry for your application') .step('package installation', ({ expectOutput, whenAsked }) => { whenAsked('Please select your package manager.').respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER); expectOutput('Installing @sentry/sveltekit'); }) .step('SDK setup', ({ whenAsked }) => { whenAsked('Do you want to enable Tracing', { timeout: 90000, // package installation can take a while in CI }).respondWith(clifty_1.KEYS.ENTER); whenAsked('Do you want to enable Session Replay').respondWith(clifty_1.KEYS.ENTER); whenAsked('Do you want to enable Logs').respondWith(clifty_1.KEYS.ENTER); }) .whenAsked('Do you want to create an example page') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Optionally add a project-scoped MCP server configuration for the Sentry MCP?') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) .expectOutput('Successfully installed the Sentry SvelteKit SDK!') .run((0, utils_1.getWizardCommand)(integration)); }); (0, vitest_1.afterAll)(() => { (0, utils_1.revertLocalChanges)(projectDir); (0, utils_1.cleanupGit)(projectDir); }); (0, vitest_1.it)('exits with exit code 0', () => { (0, vitest_1.expect)(wizardExitCode).toBe(0); }); (0, vitest_1.it)('adds the SDK dependency to package.json', () => { (0, utils_1.checkPackageJson)(projectDir, integration); }); (0, vitest_1.it)('adds the .env.sentry-build-plugin', () => { (0, utils_1.checkEnvBuildPlugin)(projectDir); }); (0, vitest_1.it)('adds the example page', () => { (0, utils_1.checkFileExists)(path.resolve(projectDir, 'src/routes/sentry-example-page/+page.svelte')); (0, utils_1.checkFileExists)(path.resolve(projectDir, 'src/routes/sentry-example-page/+server.js')); (0, utils_1.checkFileContents)(path.resolve(projectDir, 'src/routes/sentry-example-page/+page.svelte'), // svelte 5 specific syntax ['let hasSentError = $state(false);', 'onclick={getSentryData}']); }); (0, vitest_1.it)('adds the sentry plugin to vite.config.ts', () => { const viteConfig = fs.readFileSync(path.resolve(projectDir, 'vite.config.ts')); (0, vitest_1.expect)(viteConfig.toString()).toMatchInlineSnapshot(` "import { sentrySvelteKit } from "@sentry/sveltekit"; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [sentrySvelteKit({ org: "${utils_1.TEST_ARGS.ORG_SLUG}", project: "${utils_1.TEST_ARGS.PROJECT_SLUG}" }), sveltekit()] });" `); }); (0, vitest_1.it)('creates the hook files', () => { const clientHooks = fs.readFileSync(path.resolve(projectDir, 'src/hooks.client.ts')); const serverHooks = fs.readFileSync(path.resolve(projectDir, 'src/hooks.server.ts')); (0, vitest_1.expect)(clientHooks.toString()).toMatchInlineSnapshot(` "import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit"; import * as Sentry from '@sentry/sveltekit'; Sentry.init({ dsn: '${utils_1.TEST_ARGS.PROJECT_DSN}', 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()], // Enable sending user PII (Personally Identifiable Information) // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` export const handleError = handleErrorWithSentry(); " `); (0, vitest_1.expect)(serverHooks.toString()).toMatchInlineSnapshot(` "import {sequence} from "@sveltejs/kit/hooks"; import * as Sentry from "@sentry/sveltekit"; export const handle = sequence(Sentry.sentryHandle(), async ({ event, resolve }) => { const response = await resolve(event); return response; }); export const handleError = Sentry.handleErrorWithSentry();" `); }); (0, vitest_1.it)('creates the insturmentation.server file', () => { const instrumentationServer = fs.readFileSync(path.resolve(projectDir, 'src/instrumentation.server.ts')); (0, vitest_1.expect)(instrumentationServer.toString()).toMatchInlineSnapshot(` "import * as Sentry from '@sentry/sveltekit'; Sentry.init({ dsn: '${utils_1.TEST_ARGS.PROJECT_DSN}', 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)('enables tracing and instrumentation in svelte.config.js', () => { const svelteConfig = fs.readFileSync(path.resolve(projectDir, 'svelte.config.js')); (0, vitest_1.expect)(svelteConfig.toString()).toMatchInlineSnapshot(` "import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */ const config = { // Consult https://svelte.dev/docs/kit/integrations#preprocessors // for more information about preprocessors preprocess: vitePreprocess(), kit: { // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. // If your environment is not supported, or you settled on a specific environment, switch out the adapter. // See https://svelte.dev/docs/kit/adapters for more information about adapters. adapter: adapter(), experimental: { remoteFunctions: true, tracing: { server: true, }, instrumentation: { server: true, }, }, }, }; export default config;" `); }); // checkSvelteKitProject(projectDir, integration); (0, vitest_1.it)('builds successfully', async () => { await (0, utils_1.checkIfBuilds)(projectDir); }); (0, vitest_1.it)('runs on dev mode correctly', async () => { await (0, utils_1.checkIfRunsOnDevMode)(projectDir, 'ready in'); }); (0, vitest_1.it)('runs on prod mode correctly', async () => { await (0, utils_1.checkIfRunsOnProdMode)(projectDir, 'to expose', 'preview'); }); }); }); //# sourceMappingURL=sveltekit-tracing.test.js.map