UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

203 lines 9.96 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 Constants_1 = require("../../lib/Constants"); const utils_1 = require("../utils"); const path = __importStar(require("path")); const utils_2 = require("../utils"); const vitest_1 = require("vitest"); //@ts-expect-error - clifty is ESM only const clifty_1 = require("clifty"); vitest_1.describe.sequential('Angular-19', () => { (0, vitest_1.describe)('with empty project', () => { const integration = Constants_1.Integration.angular; let wizardExitCode; const { projectDir, cleanup } = (0, utils_1.createIsolatedTestEnv)('angular-19-test-app'); (0, vitest_1.beforeAll)(async () => { wizardExitCode = await runWizardOnAngularProject(projectDir, integration); }); (0, vitest_1.afterAll)(() => { cleanup(); }); (0, vitest_1.it)('exits with exit code 0', () => { (0, vitest_1.expect)(wizardExitCode).toBe(0); }); checkAngularProject(projectDir, integration); }); (0, vitest_1.describe)('with pre-defined ErrorHandler', () => { const integration = Constants_1.Integration.angular; let wizardExitCode; const { projectDir, cleanup } = (0, utils_1.createIsolatedTestEnv)('angular-19-test-app'); (0, vitest_1.beforeAll)(async () => { wizardExitCode = await runWizardOnAngularProject(projectDir, integration, (projectDir) => { (0, utils_1.modifyFile)(`${projectDir}/src/app/app.config.ts`, { 'providers: [': `providers: [{ provide: ErrorHandler, useValue: null }, `, }); }); }); (0, vitest_1.afterAll)(() => { cleanup(); }); (0, vitest_1.it)('exits with exit code 0', () => { (0, vitest_1.expect)(wizardExitCode).toBe(0); }); checkAngularProject(projectDir, integration, { preExistingErrorHandler: true, }); }); }); async function runWizardOnAngularProject(projectDir, integration, fileModificationFn) { const wizardInteraction = (0, clifty_1.withEnv)({ cwd: projectDir, }).defineInteraction(); if (fileModificationFn) { fileModificationFn(projectDir); wizardInteraction .whenAsked('Do you want to continue anyway?') .respondWith(clifty_1.KEYS.ENTER); } return (wizardInteraction .whenAsked('Please select your package manager.') .respondWith(clifty_1.KEYS.ENTER) // npm is the default for Angular .expectOutput('Installing @sentry/angular') // Installing the sdk can take a while in CI .expectOutput('Installed @sentry/angular with NPM.', { 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 .expectOutput('initialized Sentry in main.ts', { timeout: 10000, }) .expectOutput('updated your app config app.config.ts') .expectOutput('Installing @sentry/cli') .expectOutput('Installed @sentry/cli@', { timeout: 240000, // installing Sentry CLI can take a while in CI }) .whenAsked('Where are your build artifacts located?') .respondWith(clifty_1.KEYS.ENTER) // ./dist is the default value .whenAsked('We couldn\'t find build artifacts at "./dist". What would you like to do?') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // Proceed anyway (this is expected) .whenAsked('Do you want to automatically run the sentry:sourcemaps script after each production build?') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) // no - we can't upload in CI when testing building .whenAsked('Are you using a CI/CD tool to build and deploy your application?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Add a step to your CI pipeline that runs the sentry:sourcemaps script right after building your application') .respondWith(clifty_1.KEYS.ENTER) .expectOutput('Add the Sentry authentication token as an environment variable to your CI setup:') .expectOutput('SENTRY_AUTH_TOKEN=') .whenAsked('Did you configure CI as shown above?') .respondWith(clifty_1.KEYS.ENTER) // yes .whenAsked('Do you want to create an example component to test your Sentry setup?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Did you apply the snippet above?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Looks like you have Prettier in your project. Do you want to run it on your files?') .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 Angular SDK!') .run((0, utils_1.getWizardCommand)(integration))); } function checkAngularProject(projectDir, integration, options) { (0, vitest_1.test)('package.json is updated correctly', () => { (0, utils_1.checkPackageJson)(projectDir, '@sentry/angular'); const packageJsonFile = path.resolve(projectDir, 'package.json'); (0, utils_1.checkFileContents)(packageJsonFile, [ `"sentry:sourcemaps": "sentry-cli sourcemaps inject --org ${utils_2.TEST_ARGS.ORG_SLUG} --project ${utils_2.TEST_ARGS.PROJECT_SLUG} ./dist && sentry-cli sourcemaps upload --org ${utils_2.TEST_ARGS.ORG_SLUG} --project ${utils_2.TEST_ARGS.PROJECT_SLUG} ./dist"`, `"build": "ng build"`, ]); }); (0, vitest_1.test)('Sentry is correctly injected into Angular app config', () => { const appConfigFile = path.resolve(projectDir, 'src/main.ts'); (0, utils_1.checkFileExists)(appConfigFile); (0, utils_1.checkFileContents)(appConfigFile, [ `import * as Sentry from "@sentry/angular";`, 'Sentry.init({', utils_2.TEST_ARGS.PROJECT_DSN, 'Sentry.browserTracingIntegration()', 'Sentry.replayIntegration()', 'tracesSampleRate: 1', 'replaysSessionSampleRate: 0.1', 'replaysOnErrorSampleRate: 1', 'enableLogs: true', 'sendDefaultPii: true', ]); }); (0, vitest_1.test)('Sentry is correctly injected into Angular app module', () => { const appModuleFile = path.resolve(projectDir, 'src/app/app.config.ts'); (0, utils_1.checkFileExists)(appModuleFile); // Checking if the ErrorHandler is already present in the providers array, // and if it is, we skip adding it if (options?.preExistingErrorHandler) { (0, utils_1.checkFileDoesNotContain)(appModuleFile, 'Sentry.createErrorHandler()'); } (0, utils_1.checkFileContents)(appModuleFile, [ `import * as Sentry from "@sentry/angular";`, options?.preExistingErrorHandler ? `provide: ErrorHandler, useValue: null` : `provide: ErrorHandler, useValue: Sentry.createErrorHandler()`, `provide: Sentry.TraceService, deps: [Router]`, `provideAppInitializer(() => { inject(Sentry.TraceService); })`, ]); }); (0, vitest_1.test)('angular.json is updated correctly', async () => { const angularJsonFile = path.resolve(projectDir, 'angular.json'); (0, utils_1.checkFileExists)(angularJsonFile); // eslint-disable-next-line @typescript-eslint/no-explicit-any const angularJson = (await import(angularJsonFile)); // eslint-disable-next-line @typescript-eslint/no-explicit-any for (const [, project] of Object.entries( // eslint-disable-next-line @typescript-eslint/no-explicit-any angularJson.projects)) { (0, vitest_1.expect)( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access project?.architect?.build?.configurations?.production?.sourceMap).toBe(true); } }); (0, vitest_1.test)('builds successfully', async () => { await (0, utils_1.checkIfBuilds)(projectDir); }); (0, vitest_1.test)('runs on prod mode correctly', async () => { await (0, utils_1.checkIfRunsOnProdMode)(projectDir, 'Application bundle generation complete.'); }); (0, vitest_1.test)('runs on dev mode correctly', async () => { await (0, utils_1.checkIfRunsOnDevMode)(projectDir, 'Application bundle generation complete.'); }); } //# sourceMappingURL=angular-19.test.js.map