UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

123 lines (121 loc) 6.13 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 }); /* eslint-disable jest/expect-expect */ 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"); describe('NextJS', () => { const integration = Constants_1.Integration.nextjs; const projectDir = path.resolve(__dirname, '../test-applications/nextjs-test-app'); beforeAll(async () => { const wizardInstance = (0, utils_2.startWizardInstance)(integration, projectDir); const packageManagerPrompted = await wizardInstance.waitForOutput('Please select your package manager.'); const routeThroughNextJsPrompted = packageManagerPrompted && (await wizardInstance.sendStdinAndWaitForOutput( // Selecting `yarn` as the package manager [utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Do you want to route Sentry requests in the browser through your Next.js server', { timeout: 240000, })); const reactComponentAnnotationsPrompted = routeThroughNextJsPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'Do you want to enable React component annotations')); const tracingOptionPrompted = reactComponentAnnotationsPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], // "Do you want to enable Tracing", sometimes doesn't work as `Tracing` can be printed in bold. 'to track the performance of your application?')); const replayOptionPrompted = tracingOptionPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], // "Do you want to enable Sentry Session Replay", sometimes doesn't work as `Sentry Session Replay` can be printed in bold. 'to get a video-like reproduction of errors during a user session?')); const examplePagePrompted = replayOptionPrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'Do you want to create an example page', { optional: true, })); const ciCdPrompted = examplePagePrompted && (await wizardInstance.sendStdinAndWaitForOutput([utils_1.KEYS.ENTER], 'Are you using a CI/CD tool')); ciCdPrompted && (await wizardInstance.sendStdinAndWaitForOutput( // Selecting `No` for CI/CD tool [utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Successfully installed the Sentry Next.js SDK!')); wizardInstance.kill(); }); afterAll(() => { (0, utils_1.revertLocalChanges)(projectDir); (0, utils_1.cleanupGit)(projectDir); }); test('package.json is updated correctly', () => { (0, utils_3.checkPackageJson)(projectDir, integration); }); test('.env-sentry-build-plugin is created and contains the auth token', () => { (0, utils_1.checkEnvBuildPlugin)(projectDir); }); test('example page exists', () => { (0, utils_3.checkFileExists)(`${projectDir}/src/app/sentry-example-page/page.tsx`); (0, utils_3.checkFileExists)(`${projectDir}/src/app/api/sentry-example-api/route.ts`); }); test('config files created', () => { (0, utils_3.checkFileExists)(`${projectDir}/sentry.server.config.ts`); (0, utils_3.checkFileExists)(`${projectDir}/sentry.client.config.ts`); (0, utils_3.checkFileExists)(`${projectDir}/sentry.edge.config.ts`); }); test('global error file exists', () => { (0, utils_3.checkFileExists)(`${projectDir}/src/app/global-error.tsx`); }); test('instrumentation file exists', () => { (0, utils_3.checkFileExists)(`${projectDir}/src/instrumentation.ts`); }); test('instrumentation file contains Sentry initialization', () => { (0, utils_3.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;`, ]); }); test('next.config file contains Sentry wrapper', () => { (0, utils_3.checkFileContents)(`${projectDir}/next.config.mjs`, [ "import {withSentryConfig} from '@sentry/nextjs'", 'export default withSentryConfig(nextConfig, {', ]); }); test('runs on dev mode correctly', async () => { await (0, utils_3.checkIfRunsOnDevMode)(projectDir, 'Ready in'); }); test('builds correctly', async () => { await (0, utils_3.checkIfBuilds)(projectDir); }); test('runs on prod mode correctly', async () => { await (0, utils_3.checkIfRunsOnProdMode)(projectDir, 'Ready in'); }); }); //# sourceMappingURL=nextjs.test.js.map