@sentry/wizard
Version:
Sentry wizard helping you to configure your project
187 lines • 14.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-useless-escape */
var xcode_1 = require("../../src/react-native/xcode");
describe('react-native xcode', function () {
describe('addSentryWithCliToBundleShellScript', function () {
it('adds sentry cli to rn bundle build phase', function () {
var input = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"";
// actual shell script looks like this:
// /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
// but during parsing xcode library removes the quotes
var expectedOutput = "export SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\\\"\"\n/bin/sh -c \"$WITH_ENVIRONMENT ../node_modules/@sentry/react-native/scripts/collect-modules.sh\"\n";
expect((0, xcode_1.addSentryWithCliToBundleShellScript)(input)).toBe(expectedOutput);
});
});
describe('addSentryBundledScriptsToBundleShellScript', function () {
it('adds sentry cli to rn bundle build phase', function () {
var input = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"";
// actual shell script looks like this:
// /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
// but during parsing xcode library removes the quotes
var expectedOutput = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\\\"\"";
expect((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input)).toBe(expectedOutput);
});
it('adds sentry cli to expo bundle build phase', function () {
var input = "\nif [[ -f \"$PODS_ROOT/../.xcode.env\" ]]; then\n source \"$PODS_ROOT/../.xcode.env\"\nfi\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n# The project root by default is one level up from the ios directory\nexport PROJECT_ROOT=\"$PROJECT_DIR\"/..\n\nif [[ \"$CONFIGURATION\" = *Debug* ]]; then\n export SKIP_BUNDLING=1\nfi\nif [[ -z \"$ENTRY_FILE\" ]]; then\n # Set the entry JS file using the bundler's entry resolution.\n export ENTRY_FILE=\"$(\"$NODE_BINARY\" -e \"require('expo/scripts/resolveAppEntry')\" \"$PROJECT_ROOT\" ios absolute | tail -n 1)\"\nfi\n\nif [[ -z \"$CLI_PATH\" ]]; then\n # Use Expo CLI\n export CLI_PATH=\"$(\"$NODE_BINARY\" --print \"require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })\")\"\nfi\nif [[ -z \"$BUNDLE_COMMAND\" ]]; then\n # Default Expo CLI command for bundling\n export BUNDLE_COMMAND=\"export:embed\"\nfi\n\n# Source .xcode.env.updates if it exists to allow\n# SKIP_BUNDLING to be unset if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.updates\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.updates\"\nfi\n# Source local changes to allow overrides\n# if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n`\"$NODE_BINARY\" --print \"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\"`\n";
var expectedOutput = "\nif [[ -f \"$PODS_ROOT/../.xcode.env\" ]]; then\n source \"$PODS_ROOT/../.xcode.env\"\nfi\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n# The project root by default is one level up from the ios directory\nexport PROJECT_ROOT=\"$PROJECT_DIR\"/..\n\nif [[ \"$CONFIGURATION\" = *Debug* ]]; then\n export SKIP_BUNDLING=1\nfi\nif [[ -z \"$ENTRY_FILE\" ]]; then\n # Set the entry JS file using the bundler's entry resolution.\n export ENTRY_FILE=\"$(\"$NODE_BINARY\" -e \"require('expo/scripts/resolveAppEntry')\" \"$PROJECT_ROOT\" ios absolute | tail -n 1)\"\nfi\n\nif [[ -z \"$CLI_PATH\" ]]; then\n # Use Expo CLI\n export CLI_PATH=\"$(\"$NODE_BINARY\" --print \"require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })\")\"\nfi\nif [[ -z \"$BUNDLE_COMMAND\" ]]; then\n # Default Expo CLI command for bundling\n export BUNDLE_COMMAND=\"export:embed\"\nfi\n\n# Source .xcode.env.updates if it exists to allow\n# SKIP_BUNDLING to be unset if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.updates\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.updates\"\nfi\n# Source local changes to allow overrides\n# if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n/bin/sh `\"$NODE_BINARY\" --print \"require('path').dirname(require.resolve('@sentry/react-native/package.json')) + '/scripts/sentry-xcode.sh'\"` `\"$NODE_BINARY\" --print \"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\"`\n";
expect((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input)).toBe(expectedOutput);
});
});
describe('removeSentryFromBundleShellScript', function () {
it('removes sentry cli from rn bundle build phase', function () {
var input = "export SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\"\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT ../node_modules/@sentry/react-native/scripts/collect-modules.sh\"\n";
var expectedOutput = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"\n\n";
expect((0, xcode_1.removeSentryFromBundleShellScript)(input)).toBe(expectedOutput);
});
it('removes sentry bundled scripts from rn bundle build phase', function () {
var input = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\"\"";
var expectedOutput = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"";
expect((0, xcode_1.removeSentryFromBundleShellScript)(input)).toBe(expectedOutput);
});
});
describe('findBundlePhase', function () {
it('returns build phase with react native xcode shell script', function () {
var inputMap = {
1: {
shellScript: 'foo',
},
2: {
shellScript: 'bar',
},
3: {
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"\n\n",
},
4: {
shellScript: 'qux',
},
};
var expected = {
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"\n\n",
};
expect((0, xcode_1.findBundlePhase)(inputMap)).toEqual(expected);
});
it('returns undefined if bundle phase not present', function () {
var inputMap = {
1: {
shellScript: 'foo',
},
2: {
shellScript: 'bar',
},
3: {
// note different path to the script
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/unknown/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"\n\n",
},
4: {
shellScript: 'qux',
},
};
expect((0, xcode_1.findBundlePhase)(inputMap)).toBeUndefined();
});
});
describe('doesBundlePhaseIncludeSentry', function () {
it('returns true for script containing sentry cli calling react native xcode command', function () {
var input = {
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nSENTRY_CLI=\"sentry-cli react-native xcode\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$SENTRY_CLI $REACT_NATIVE_XCODE\"\"\n",
};
expect((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeTruthy();
});
it('returns true for script containing sentry bundled script', function () {
var input = {
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nSENTRY_CLI=\"sentry-cli react-native xcode\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\"\\\"\n",
};
expect((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeTruthy();
});
it('returns false', function () {
var input = {
// note sentry-cli can be part of the script but doesn't call react native xcode script
shellScript: "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\"\"\n\nsentry-cli --version\n",
};
expect((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeFalsy();
});
});
describe('findDebugFilesUploadPhase', function () {
it('returns debug files build phase using debug files command', function () {
var input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: "set -e\nsentry-cli debug-files upload path/to/dsym --include-sources\n",
},
};
var expected = [
'2',
{
shellScript: "set -e\nsentry-cli debug-files upload path/to/dsym --include-sources\n",
},
];
expect((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
it('returns debug files build phase with sentry-cli absolute path', function () {
var input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: "set -e\n/path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources\n",
},
};
var expected = [
'2',
{
shellScript: "set -e\n/path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources\n",
},
];
expect((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
it('returns debug files build phase using dsym command', function () {
var input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: "set -e\nsentry-cli upload-dsym path/to/dsym --include-sources\n",
},
};
var expected = [
'2',
{
shellScript: "set -e\nsentry-cli upload-dsym path/to/dsym --include-sources\n",
},
];
expect((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
it('returns debug files build phase using bundled scripts', function () {
var input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: "/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh",
},
};
var expected = [
'2',
{
shellScript: "/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh",
},
];
expect((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
it('returns undefined if build phase not present', function () {
var input = {
1: {
shellScript: 'foo',
},
2: {
// sentry-cli present but with different command
shellScript: 'sentry-cli sourcempas upload',
},
};
expect((0, xcode_1.findDebugFilesUploadPhase)(input)).toBeUndefined();
});
});
});
//# sourceMappingURL=xcode.test.js.map