@sentry/wizard
Version:
Sentry wizard helping you to configure your project
155 lines (146 loc) • 7.93 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 vitest_1 = require("vitest");
(0, vitest_1.describe)('ReactNative', () => {
const integration = Constants_1.Integration.reactNative;
const projectDir = path.resolve(__dirname, '../test-applications/react-native-test-app');
let podInstallPrompted = false;
(0, vitest_1.beforeAll)(async () => {
const wizardInstance = (0, utils_1.startWizardInstance)(integration, projectDir);
const packageManagerPrompted = await wizardInstance.waitForOutput('Please select your package manager.');
const sessionReplayPrompted = packageManagerPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Selecting `yarn` as the package manager
[utils_1.KEYS.DOWN, utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Do you want to enable Session Replay to help debug issues? (See https://docs.sentry.io/platforms/react-native/session-replay/)'),
{
timeout: 240000,
});
const feedbackWidgetPrompted = sessionReplayPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Enable session replay
[utils_1.KEYS.ENTER], 'Do you want to enable the Feedback Widget to collect feedback from your users? (See https://docs.sentry.io/platforms/react-native/user-feedback/)'));
const logsPrompted = feedbackWidgetPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Enable feedback widget
[utils_1.KEYS.ENTER], 'Do you want to enable Logs? (See https://docs.sentry.io/platforms/react-native/logs/)'));
podInstallPrompted =
logsPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Enable logs
[utils_1.KEYS.ENTER], 'Do you want to run `pod install` now?', {
optional: true,
timeout: 5000,
}));
const prettierPrompted = podInstallPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Skip pod install
[utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Looks like you have Prettier in your project. Do you want to run it on your files?'));
// Handle the MCP prompt (default is now Yes, so press DOWN to select No)
const mcpPrompted = prettierPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Skip prettier
[utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Optionally add a project-scoped MCP server configuration for the Sentry MCP?', {
optional: true,
}));
const testEventPrompted = mcpPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Decline MCP config by selecting No
[utils_1.KEYS.DOWN, utils_1.KEYS.ENTER], 'Have you successfully sent a test event?'));
testEventPrompted &&
(await wizardInstance.sendStdinAndWaitForOutput(
// Respond that test event was sent
[utils_1.KEYS.ENTER], 'Everything is set up!'));
wizardInstance.kill();
});
(0, vitest_1.afterAll)(() => {
(0, utils_1.revertLocalChanges)(projectDir);
(0, utils_1.cleanupGit)(projectDir);
});
(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', () => {
if (!podInstallPrompted) {
return;
}
(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")`);
});
(0, vitest_1.test)('xcode project is updated correctly', () => {
if (!podInstallPrompted) {
return;
}
(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