UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

126 lines (124 loc) 5.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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)('NextJS-14', () => { const integration = Constants_1.Integration.nextjs; let wizardExitCode; const { projectDir, cleanup } = (0, utils_1.createIsolatedTestEnv)('nextjs-14-test-app'); (0, vitest_1.beforeAll)(async () => { wizardExitCode = await (0, clifty_1.withEnv)({ cwd: projectDir, }) .defineInteraction() .whenAsked('Please select your package manager.') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // Select yarn .expectOutput('Installing @sentry/nextjs') .whenAsked('Do you want to route Sentry requests in the browser through your Next.js server', { timeout: 240000, // package installation can take a while in CI }) .respondWith(clifty_1.KEYS.ENTER) .whenAsked('to track the performance of your application?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('to get a video-like reproduction of errors during a user session?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('to send your application logs to Sentry?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Do you want to create an example page') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Are you using a CI/CD tool') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // Select No .whenAsked('Optionally add a project-scoped MCP server configuration for the Sentry MCP?') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // Decline MCP config .expectOutput('Successfully installed the Sentry Next.js SDK!') .run((0, utils_1.getWizardCommand)(integration)); }); (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/nextjs'); }); (0, vitest_1.test)('.env-sentry-build-plugin is created and contains the auth token', () => { (0, utils_1.checkEnvBuildPlugin)(projectDir); }); (0, vitest_1.test)('example page exists', () => { (0, utils_1.checkFileExists)(`${projectDir}/src/app/layout.tsx`); (0, utils_1.checkFileExists)(`${projectDir}/src/app/sentry-example-page/page.tsx`); (0, utils_1.checkFileExists)(`${projectDir}/src/app/api/sentry-example-api/route.ts`); }); (0, vitest_1.test)('config files created', () => { (0, utils_1.checkFileExists)(`${projectDir}/sentry.server.config.ts`); (0, utils_1.checkFileExists)(`${projectDir}/sentry.edge.config.ts`); }); (0, vitest_1.test)('global error file exists', () => { (0, utils_1.checkFileExists)(`${projectDir}/src/app/global-error.tsx`); }); (0, vitest_1.test)('instrumentation files exists', () => { (0, utils_1.checkFileExists)(`${projectDir}/src/instrumentation.ts`); (0, utils_1.checkFileExists)(`${projectDir}/src/instrumentation-client.ts`); }); (0, vitest_1.test)('instrumentation file contains Sentry initialization', () => { (0, utils_1.checkFileContents)(`${projectDir}/src/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_1.checkFileContents)(`${projectDir}/next.config.mjs`, [ "import { withSentryConfig } from '@sentry/nextjs'", 'export default withSentryConfig(nextConfig, {', ]); }); (0, vitest_1.test)('runs on dev mode correctly', async () => { await (0, utils_1.checkIfRunsOnDevMode)(projectDir, 'Ready in'); }); (0, vitest_1.test)('builds correctly', async () => { await (0, utils_1.checkIfBuilds)(projectDir); }); (0, vitest_1.test)('runs on prod mode correctly', async () => { await (0, utils_1.checkIfRunsOnProdMode)(projectDir, 'Ready in'); }); (0, vitest_1.test)('root layout contains generateMetadata function', () => { (0, utils_1.checkFileContents)(`${projectDir}/src/app/layout.tsx`, [ "// This file was generated by the Sentry wizard because we couldn't find a root layout file.", "import * as Sentry from '@sentry/nextjs';", "import type { Metadata } from 'next';", '', 'export function generateMetadata(): Metadata {', ' return {', ' other: {', ' ...Sentry.getTraceData(),', ' }', ' }', '};', '', 'export default function RootLayout({', ' children,', '}: {', ' children: React.ReactNode', '}) {', ' return (', ' <html lang="en">', ' <body>{children}</body>', ' </html>', ' )', '}', ]); }); }); //# sourceMappingURL=nextjs-14.test.js.map