UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

120 lines (118 loc) 6.28 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 fs = __importStar(require("node:fs")); const path = __importStar(require("node:path")); const Constants_1 = require("../../lib/Constants"); const utils_1 = require("../utils"); const utils_2 = require("../utils"); const utils_3 = require("../utils"); const vitest_1 = require("vitest"); (0, vitest_1.describe)('NextJS-16 with Prettier, Biome, and ESLint', () => { const integration = Constants_1.Integration.nextjs; const projectDir = path.resolve(__dirname, '../test-applications/nextjs-16-test-app'); (0, vitest_1.beforeAll)(async () => { const wizardInstance = (0, utils_2.startWizardInstance)(integration, projectDir); // Wait for package manager selection and select npm const packageManagerPrompted = await wizardInstance.waitForOutput('Please select your package manager', { timeout: 300000, }); // Select npm (first option) const routingPrompted = packageManagerPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'Do you want to route Sentry requests in the browser through your Next.js server', { timeout: 300000 })); const tracingOptionPrompted = routingPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'to track the performance of your application?')); const replayOptionPrompted = tracingOptionPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'to get a video-like reproduction of errors during a user session?')); const logOptionPrompted = replayOptionPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'to send your application logs to Sentry?')); // Skip example page creation const ciCdPrompted = logOptionPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Are you using a CI/CD tool', { optional: true, })); // Selecting `No` for CI/CD tool // Should prompt for BOTH Prettier and Biome const formattersPrompted = ciCdPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Looks like you have Prettier and Biome in your project', { optional: true })); // Accept formatter run (default is Yes) const mcpPrompted = formattersPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'Optionally add a project-scoped MCP server configuration for the Sentry MCP?', { optional: true })); // Skip MCP config mcpPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Successfully installed the Sentry Next.js SDK!', { optional: true })); wizardInstance.kill(); }); (0, vitest_1.afterAll)(() => { (0, utils_1.revertLocalChanges)(projectDir); (0, utils_1.cleanupGit)(projectDir); }); (0, vitest_1.test)('package.json is updated correctly', () => { (0, utils_3.checkPackageJson)(projectDir, integration); }); (0, vitest_1.test)('config files created', () => { (0, utils_3.checkFileExists)(`${projectDir}/sentry.server.config.ts`); (0, utils_3.checkFileExists)(`${projectDir}/sentry.edge.config.ts`); }); (0, vitest_1.test)('global error file exists', () => { (0, utils_3.checkFileExists)(`${projectDir}/app/global-error.tsx`); }); (0, vitest_1.test)('instrumentation files exist', () => { (0, utils_3.checkFileExists)(`${projectDir}/instrumentation.ts`); (0, utils_3.checkFileExists)(`${projectDir}/instrumentation-client.ts`); }); (0, vitest_1.test)('instrumentation file contains Sentry initialization', () => { (0, utils_3.checkFileContents)(`${projectDir}/instrumentation.ts`, [ 'import * as Sentry from "@sentry/nextjs";', `export async function register() { if (process.env.NEXT_RUNTIME === "nodejs") { await import("./sentry.server.config"); } if (process.env.NEXT_RUNTIME === "edge") { await import("./sentry.edge.config"); } } export const onRequestError = Sentry.captureRequestError;`, ]); }); (0, vitest_1.test)('next.config file contains Sentry wrapper', () => { (0, utils_3.checkFileContents)(`${projectDir}/next.config.ts`, [ 'import { withSentryConfig } from "@sentry/nextjs"', 'withSentryConfig(nextConfig, {', ]); }); (0, vitest_1.test)('Generated code has proper import formatting', () => { const configContent = fs.readFileSync(`${projectDir}/next.config.ts`, 'utf-8'); // Verify proper spacing: import { withSentryConfig } from (0, vitest_1.expect)(configContent).toMatch(/import\s+{\s+\w+\s+}\s+from/); }); (0, vitest_1.test)('builds correctly', async () => { await (0, utils_3.checkIfBuilds)(projectDir); }); (0, vitest_1.test)('lints correctly', async () => { await (0, utils_3.checkIfLints)(projectDir); }); }); //# sourceMappingURL=nextjs-16.test.js.map