UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

119 lines (110 loc) 6.02 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)('ReactNative', () => { const integration = Constants_1.Integration.reactNative; let wizardExitCode; const { projectDir, cleanup } = (0, utils_1.createIsolatedTestEnv)('react-native-test-app'); (0, vitest_1.beforeAll)(async () => { const wizardInteraction = (0, clifty_1.withEnv)({ cwd: projectDir, debug: true, }) .defineInteraction() .whenAsked('Please select your package manager.') .respondWith(clifty_1.KEYS.DOWN, clifty_1.KEYS.ENTER) .expectOutput('Installing @sentry/react-native') .expectOutput('Installed @sentry/react-native', { timeout: 240000, }) .whenAsked('Do you want to enable Session Replay') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Do you want to enable the Feedback Widget to collect feedback from your users?') .respondWith(clifty_1.KEYS.ENTER) .whenAsked('Do you want to enable Logs') .respondWith(clifty_1.KEYS.ENTER); // Only prompt to run `pod install` if running on macOS. if (process.platform === 'darwin') { wizardInteraction .whenAsked('Do you want to run `pod install` now?') .respondWith(clifty_1.KEYS.ENTER) .expectOutput('Pods installed.', { timeout: 240000 }); } wizardExitCode = await wizardInteraction .expectOutput('Added Sentry.init to App.tsx') .whenAsked('Looks like you have Prettier in your project. Do you want to run it on your files?') .respondWith(clifty_1.KEYS.DOWN, 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('To make sure everything is set up correctly, put the following code snippet into your application.') .whenAsked('Have you successfully sent a test event?') .respondWith(clifty_1.KEYS.ENTER) .expectOutput('Everything is set up!') .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.checkFileContents)(`${projectDir}/package.json`, `@sentry/react-native`); }); (0, vitest_1.test)('metro.config.js is updated correctly', () => { (0, utils_1.checkFileContents)(`${projectDir}/metro.config.js`, `const { withSentryConfig } = require("@sentry/react-native/metro");`); (0, utils_1.checkFileContents)(`${projectDir}/metro.config.js`, `module.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`); }); (0, vitest_1.test)('App.tsx is updated correctly', () => { (0, utils_1.checkFileContents)(`${projectDir}/App.tsx`, `import * as Sentry from '@sentry/react-native'; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', // Adds more context data to events (IP address, cookies, user, etc.) // For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/ sendDefaultPii: true, // Enable Logs enableLogs: true, // Configure Session Replay replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1, integrations: [Sentry.mobileReplayIntegration(), Sentry.feedbackIntegration()], // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: __DEV__, });`); (0, utils_1.checkFileContents)(`${projectDir}/App.tsx`, `export default Sentry.wrap(App);`); }); (0, vitest_1.test)('ios/sentry.properties is added', () => { (0, utils_1.checkFileContents)(`${projectDir}/ios/sentry.properties`, `auth.token=${utils_1.TEST_ARGS.AUTH_TOKEN} defaults.org=${utils_1.TEST_ARGS.ORG_SLUG} defaults.project=${utils_1.TEST_ARGS.PROJECT_SLUG} defaults.url=https://sentry.io/`); }); (0, vitest_1.test)('android/sentry.properties is added', () => { (0, utils_1.checkFileContents)(`${projectDir}/android/sentry.properties`, `auth.token=${utils_1.TEST_ARGS.AUTH_TOKEN} defaults.org=${utils_1.TEST_ARGS.ORG_SLUG} defaults.project=${utils_1.TEST_ARGS.PROJECT_SLUG} defaults.url=https://sentry.io/`); }); (0, vitest_1.test)('build.gradle is updated correctly', () => { (0, utils_1.checkFileContents)(`${projectDir}/android/app/build.gradle`, `apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")`); }); vitest_1.test.skipIf(process.platform !== 'darwin')('xcode project is updated correctly', () => { (0, utils_1.checkFileContents)(`${projectDir}/ios/reactnative078.xcodeproj/project.pbxproj`, `@sentry/react-native/scripts/sentry-xcode.sh`); (0, utils_1.checkFileContents)(`${projectDir}/ios/reactnative078.xcodeproj/project.pbxproj`, `../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh`); }); (0, vitest_1.test)('android project is bundled correctly', async () => { const bundled = await (0, utils_1.checkIfReactNativeBundles)(projectDir, 'android'); (0, vitest_1.expect)(bundled).toBe(true); }); (0, vitest_1.test)('ios project is bundled correctly', async () => { const bundled = await (0, utils_1.checkIfReactNativeBundles)(projectDir, 'ios'); (0, vitest_1.expect)(bundled).toBe(true); }); }); //# sourceMappingURL=react-native.test.js.map