@sentry/wizard
Version:
Sentry wizard helping you to configure your project
173 lines • 8.88 kB
JavaScript
;
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 Constants_1 = require("../../lib/Constants");
const utils_1 = require("../utils");
const utils_2 = require("../utils");
const vitest_1 = require("vitest");
(0, vitest_1.describe)('Nuxt-4', () => {
const projectDir = path.resolve(__dirname, '../test-applications/nuxt-4-test-app');
(0, vitest_1.beforeAll)(async () => {
await runWizardOnNuxtProject(projectDir);
});
(0, vitest_1.afterAll)(() => {
(0, utils_1.revertLocalChanges)(projectDir);
(0, utils_1.cleanupGit)(projectDir);
});
testNuxtProjectSetup(projectDir);
testNuxtProjectConfigs(projectDir);
testNuxtProjectBuildsAndRuns(projectDir);
});
async function runWizardOnNuxtProject(projectDir) {
const integration = Constants_1.Integration.nuxt;
const wizardInstance = (0, utils_2.startWizardInstance)(integration, projectDir);
const packageManagerPrompted = await wizardInstance.waitForOutput('Please select your package manager.');
const nftOverridePrompted = packageManagerPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Selecting `yarn` as the package manager
[utils_2.KEYS.DOWN, utils_2.KEYS.ENTER], 'Do you want to add an override for @vercel/nft version ^0.27.4?', {
timeout: 240000,
}));
const deploymentPlatformPrompted = nftOverridePrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(utils_2.KEYS.ENTER, 'Please select your deployment platform.', {
timeout: 240000,
}));
const tracingOptionPrompted = deploymentPlatformPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(utils_2.KEYS.ENTER,
// "Do you want to enable Tracing", sometimes doesn't work as `Tracing` can be printed in bold.
'Do you want to enable', {
timeout: 240000,
}));
const replayOptionPrompted = tracingOptionPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput([utils_2.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 logOptionPrompted = replayOptionPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput([utils_2.KEYS.ENTER],
// "Do you want to enable Logs", sometimes doesn't work as `Logs` can be printed in bold.
'to send your application logs to Sentry?'));
const examplePagePrompted = logOptionPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput([utils_2.KEYS.ENTER], 'Do you want to create an example page', {
optional: true,
}));
// Handle the MCP prompt (default is now Yes, so press DOWN to select No)
const mcpPrompted = examplePagePrompted &&
(await wizardInstance.sendStdinAndWaitForOutput([utils_2.KEYS.ENTER], 'Optionally add a project-scoped MCP server configuration for the Sentry MCP?', {
optional: true,
}));
// Now wait for the success message
mcpPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput([utils_2.KEYS.DOWN, utils_2.KEYS.ENTER], 'Successfully installed the Sentry Nuxt SDK!'));
wizardInstance.kill();
}
function testNuxtProjectSetup(projectDir) {
const integration = Constants_1.Integration.nuxt;
(0, vitest_1.test)('package.json is updated correctly', () => {
(0, utils_2.checkPackageJson)(projectDir, integration);
});
(0, vitest_1.test)('.env-sentry-build-plugin is created and contains the auth token', () => {
(0, utils_2.checkEnvBuildPlugin)(projectDir);
});
(0, vitest_1.test)('config files created', () => {
(0, utils_2.checkFileExists)(`${projectDir}/sentry.server.config.ts`);
(0, utils_2.checkFileExists)(`${projectDir}/sentry.client.config.ts`);
});
(0, vitest_1.test)('example page exists', () => {
(0, utils_2.checkFileExists)(`${projectDir}/app/pages/sentry-example-page.vue`);
(0, utils_2.checkFileExists)(`${projectDir}/server/api/sentry-example-api.ts`);
});
}
function testNuxtProjectConfigs(projectDir) {
(0, vitest_1.test)('nuxt config contains sentry module', () => {
(0, utils_2.checkFileContents)(path.resolve(projectDir, 'nuxt.config.ts'), [
"modules: ['@sentry/nuxt/module'],",
'sentry: {',
' sourceMapsUploadOptions: {',
` org: '${utils_2.TEST_ARGS.ORG_SLUG}',`,
` project: '${utils_2.TEST_ARGS.PROJECT_SLUG}'`,
' }',
'},',
'sourcemap: {',
" client: 'hidden'",
'}',
]);
});
(0, vitest_1.test)('sentry.client.config.ts contents', () => {
(0, utils_2.checkFileContents)(path.resolve(projectDir, 'sentry.client.config.ts'), [
'import * as Sentry from "@sentry/nuxt";',
'Sentry.init({',
' // If set up, you can use your runtime config here',
' // dsn: useRuntimeConfig().public.sentry.dsn,',
` dsn: "${utils_2.TEST_ARGS.PROJECT_DSN}",`,
' // We recommend adjusting this value in production, or using tracesSampler',
' // for finer control',
' tracesSampleRate: 1.0,',
' // 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: [Sentry.replayIntegration()],',
' // Enable logs to be sent to Sentry',
' enableLogs: true,',
` // Enable sending of user PII (Personally Identifiable Information)`,
' // https://docs.sentry.io/platforms/javascript/guides/nuxt/configuration/options/#sendDefaultPii',
' sendDefaultPii: true,',
" // Setting this option to true will print useful information to the console while you're setting up Sentry.",
' debug: false,',
'});',
]);
});
(0, vitest_1.test)('sentry.server.config.ts contents', () => {
(0, utils_2.checkFileContents)(path.resolve(projectDir, 'sentry.server.config.ts'), [
'import * as Sentry from "@sentry/nuxt";',
'Sentry.init({',
` dsn: "${utils_2.TEST_ARGS.PROJECT_DSN}",`,
' // We recommend adjusting this value in production, or using tracesSampler',
' // for finer control',
' tracesSampleRate: 1.0,',
' // Enable logs to be sent to Sentry',
' enableLogs: true,',
' // Enable sending of user PII (Personally Identifiable Information)',
' // https://docs.sentry.io/platforms/javascript/guides/nuxt/configuration/options/#sendDefaultPii',
' sendDefaultPii: true,',
" // Setting this option to true will print useful information to the console while you're setting up Sentry.",
' debug: false,',
'});',
]);
});
}
function testNuxtProjectBuildsAndRuns(projectDir) {
(0, vitest_1.test)('builds successfully', async () => {
await (0, utils_2.checkIfBuilds)(projectDir);
});
(0, vitest_1.test)('runs on prod mode correctly', async () => {
await (0, utils_2.checkIfRunsOnProdMode)(projectDir, 'Listening on');
});
}
//# sourceMappingURL=nuxt-4.test.js.map