@sentry/wizard 4.3.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/e2e-tests/tests/nextjs-14.test.js +1 -3
- package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-15.test.js +1 -3
- package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +0 -24
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +1 -2
- package/dist/src/nextjs/templates.js +2 -8
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/react-native/javascript.d.ts +16 -0
- package/dist/src/react-native/javascript.js +141 -6
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +1 -0
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/sentry-cli.js +8 -1
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +9 -8
- package/dist/src/utils/clack-utils.js +38 -8
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.js +7 -8
- package/dist/src/utils/package-manager.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/test/nextjs/templates.test.js +0 -51
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/react-native/javascript.test.js +406 -0
- package/dist/test/react-native/javascript.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/sentry-cli.test.js +11 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -1
- package/dist/test/utils/clack-utils.test.js +41 -24
- package/dist/test/utils/clack-utils.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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CAAC,8DAA8D,EAAE,GAAG,EAAE;YACtE,MAAM,QAAQ,GAAG,IAAA,8CAAkC,EAAC;gBAClD,OAAO,EAAE,QAAQ;gBACjB,WAAW,EAAE,YAAY;gBACzB,UAAU,EAAE,KAAK;gBACjB,SAAS,EAAE,+BAA+B;gBAC1C,WAAW,EAAE,KAAK;gBAClB,wBAAwB,EAAE,KAAK;aAChC,CAAC,CAAC;YAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mFAAmF,EAAE,GAAG,EAAE;YAC3F,MAAM,QAAQ,GAAG,IAAA,8CAAkC,EAAC;gBAClD,OAAO,EAAE,QAAQ;gBACjB,WAAW,EAAE,YAAY;gBACzB,UAAU,EAAE,KAAK;gBACjB,SAAS,EAAE,+BAA+B;gBAC1C,WAAW,EAAE,IAAI;gBACjB,wBAAwB,EAAE,IAAI;aAC/B,CAAC,CAAC;YAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAqChC,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n getSentryConfigContents,\n getWithSentryConfigOptionsTemplate,\n} from '../../src/nextjs/templates';\n\ndescribe('Next.js code templates', () => {\n describe('getSentryConfigContents', () => {\n describe('client-side', () => {\n it('generates client-side Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates client-side Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates client-side Sentry config with session replay disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: true,\n replay: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('server-side', () => {\n it('generates server-side Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates server-side Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates server-side Sentry config with spotlight disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('edge', () => {\n it('generates edge Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'edge', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n // The config you add here will be used whenever one of the edge features is loaded.\n // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates edge Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'edge', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n // The config you add here will be used whenever one of the edge features is loaded.\n // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n });\n\n describe('getWithSentryConfigOptionsTemplate', () => {\n it('generates options for SaaS', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n sentryUrl: 'https://dont-use-this-url.com',\n tunnelRoute: true,\n reactComponentAnnotation: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n\n it('generates options for self-hosted', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: true,\n sentryUrl: 'https://my-sentry.com',\n tunnelRoute: true,\n reactComponentAnnotation: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n sentryUrl: \"https://my-sentry.com\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n\n it('comments out tunnelRoute if `tunnelRoute` option is disabled', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n sentryUrl: 'https://dont-use-this-url.com',\n tunnelRoute: false,\n reactComponentAnnotation: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n // tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n\n it('adds `reactComponentAnnotations` option if `reactComponentAnnotations` is enabled', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n sentryUrl: 'https://dont-use-this-url.com',\n tunnelRoute: true,\n reactComponentAnnotation: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Automatically annotate React components to show their full name in breadcrumbs and session replay\n reactComponentAnnotation: {\n enabled: true,\n },\n\n // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"templates.test.js","sourceRoot":"","sources":["../../../test/nextjs/templates.test.ts"],"names":[],"mappings":";;AAAA,0DAGoC;AAEpC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACvC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;YAC3B,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;gBACvE,MAAM,QAAQ,GAAG,IAAA,mCAAuB,EAAC,QAAQ,EAAE,QAAQ,EAAE;oBAC3D,WAAW,EAAE,IAAI;oBACjB,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC;gBAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA8BtC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,0EAA0E,EAAE,GAAG,EAAE;gBAClF,MAAM,QAAQ,GAAG,IAAA,mCAAuB,EAAC,QAAQ,EAAE,QAAQ,EAAE;oBAC3D,WAAW,EAAE,KAAK;oBAClB,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC;gBAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;SA2BtC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,kEAAkE,E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C;gBAClD,OAAO,EAAE,QAAQ;gBACjB,WAAW,EAAE,YAAY;gBACzB,UAAU,EAAE,IAAI;gBAChB,SAAS,EAAE,uBAAuB;gBAClC,WAAW,EAAE,IAAI;aAClB,CAAC,CAAC;YAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;YACtE,MAAM,QAAQ,GAAG,IAAA,8CAAkC,EAAC;gBAClD,OAAO,EAAE,QAAQ;gBACjB,WAAW,EAAE,YAAY;gBACzB,UAAU,EAAE,KAAK;gBACjB,SAAS,EAAE,+BAA+B;gBAC1C,WAAW,EAAE,KAAK;aACnB,CAAC,CAAC;YAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n getSentryConfigContents,\n getWithSentryConfigOptionsTemplate,\n} from '../../src/nextjs/templates';\n\ndescribe('Next.js code templates', () => {\n describe('getSentryConfigContents', () => {\n describe('client-side', () => {\n it('generates client-side Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates client-side Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates client-side Sentry config with session replay disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'client', {\n performance: true,\n replay: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the client.\n // The config you add here will be used whenever a users loads a page in their browser.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('server-side', () => {\n it('generates server-side Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates server-side Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates server-side Sentry config with spotlight disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'server', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry on the server.\n // The config you add here will be used whenever the server handles a request.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('edge', () => {\n it('generates edge Sentry config with all features enabled', () => {\n const template = getSentryConfigContents('my-dsn', 'edge', {\n performance: true,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n // The config you add here will be used whenever one of the edge features is loaded.\n // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates edge Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents('my-dsn', 'edge', {\n performance: false,\n replay: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n // The config you add here will be used whenever one of the edge features is loaded.\n // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/\n\n import * as Sentry from \"@sentry/nextjs\";\n\n Sentry.init({\n dsn: \"my-dsn\",\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n });\n\n describe('getWithSentryConfigOptionsTemplate', () => {\n it('generates options for SaaS', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n sentryUrl: 'https://dont-use-this-url.com',\n tunnelRoute: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n\n it('generates options for self-hosted', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: true,\n sentryUrl: 'https://my-sentry.com',\n tunnelRoute: true,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n sentryUrl: \"https://my-sentry.com\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n\n it('comments out tunnelRoute if `tunnelRoute` option is disabled', () => {\n const template = getWithSentryConfigOptionsTemplate({\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n sentryUrl: 'https://dont-use-this-url.com',\n tunnelRoute: false,\n });\n\n expect(template).toMatchInlineSnapshot(`\n \"{\n // For all available options, see:\n // https://www.npmjs.com/package/@sentry/webpack-plugin#options\n\n org: \"my-org\",\n project: \"my-project\",\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n // tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }\"\n `);\n });\n });\n});\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const javascript_1 = require("../../src/react-native/javascript");
|
|
4
|
+
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
5
|
+
const magicast_1 = require("magicast");
|
|
4
6
|
describe('react-native javascript', () => {
|
|
5
7
|
describe('addSentryInitWithSdkImport', () => {
|
|
6
8
|
it('adds sdk import and sentry init under last import in the file', () => {
|
|
@@ -109,5 +111,409 @@ export default App;`;
|
|
|
109
111
|
})).toBe(false);
|
|
110
112
|
});
|
|
111
113
|
});
|
|
114
|
+
describe('addSentryWrap', () => {
|
|
115
|
+
it('wraps the root app component', () => {
|
|
116
|
+
const mod = (0, magicast_1.parseModule)(`import * as React from 'react';
|
|
117
|
+
import * as Sentry from '@sentry/react-native';
|
|
118
|
+
|
|
119
|
+
import { View } from 'react-native';
|
|
120
|
+
|
|
121
|
+
const App = () => {
|
|
122
|
+
return (
|
|
123
|
+
<View>
|
|
124
|
+
Test App
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default App;`);
|
|
130
|
+
const expectedOutput = `import * as React from 'react';
|
|
131
|
+
import * as Sentry from '@sentry/react-native';
|
|
132
|
+
|
|
133
|
+
import { View } from 'react-native';
|
|
134
|
+
|
|
135
|
+
const App = () => {
|
|
136
|
+
return (
|
|
137
|
+
<View>
|
|
138
|
+
Test App
|
|
139
|
+
</View>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export default Sentry.wrap(App);`;
|
|
144
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
145
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
146
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
147
|
+
});
|
|
148
|
+
it('wraps a wrapped root app component', () => {
|
|
149
|
+
const mod = (0, magicast_1.parseModule)(`import * as React from 'react';
|
|
150
|
+
import * as Sentry from '@sentry/react-native';
|
|
151
|
+
|
|
152
|
+
import { View } from 'react-native';
|
|
153
|
+
|
|
154
|
+
const App = () => {
|
|
155
|
+
return (
|
|
156
|
+
<View>
|
|
157
|
+
Test App
|
|
158
|
+
</View>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default AnotheWrapper.wrap(App);`);
|
|
163
|
+
const expectedOutput = `import * as React from 'react';
|
|
164
|
+
import * as Sentry from '@sentry/react-native';
|
|
165
|
+
|
|
166
|
+
import { View } from 'react-native';
|
|
167
|
+
|
|
168
|
+
const App = () => {
|
|
169
|
+
return (
|
|
170
|
+
<View>
|
|
171
|
+
Test App
|
|
172
|
+
</View>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default Sentry.wrap(AnotheWrapper.wrap(App));`;
|
|
177
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
178
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
179
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
180
|
+
});
|
|
181
|
+
it('wraps a root app named function', () => {
|
|
182
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
183
|
+
|
|
184
|
+
export default function RootLayout() {
|
|
185
|
+
return (
|
|
186
|
+
<View>
|
|
187
|
+
Test App
|
|
188
|
+
</View>
|
|
189
|
+
);
|
|
190
|
+
}`);
|
|
191
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
192
|
+
|
|
193
|
+
export default Sentry.wrap(function RootLayout() {
|
|
194
|
+
return (
|
|
195
|
+
<View>
|
|
196
|
+
Test App
|
|
197
|
+
</View>
|
|
198
|
+
);
|
|
199
|
+
});`;
|
|
200
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
201
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
202
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
203
|
+
});
|
|
204
|
+
it('wraps a wrapped root app named function', () => {
|
|
205
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
206
|
+
|
|
207
|
+
export default Another.wrapper(function RootLayout() {
|
|
208
|
+
return (
|
|
209
|
+
<View>
|
|
210
|
+
Test App
|
|
211
|
+
</View>
|
|
212
|
+
);
|
|
213
|
+
});`);
|
|
214
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
215
|
+
|
|
216
|
+
export default Sentry.wrap(Another.wrapper(function RootLayout() {
|
|
217
|
+
return (
|
|
218
|
+
<View>
|
|
219
|
+
Test App
|
|
220
|
+
</View>
|
|
221
|
+
);
|
|
222
|
+
}));`;
|
|
223
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
224
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
225
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
226
|
+
});
|
|
227
|
+
it('wraps a root app anonymous function', () => {
|
|
228
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
229
|
+
|
|
230
|
+
export default () => {
|
|
231
|
+
return (
|
|
232
|
+
<View>
|
|
233
|
+
Test App
|
|
234
|
+
</View>
|
|
235
|
+
);
|
|
236
|
+
}`);
|
|
237
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
238
|
+
|
|
239
|
+
export default Sentry.wrap(() => {
|
|
240
|
+
return (
|
|
241
|
+
<View>
|
|
242
|
+
Test App
|
|
243
|
+
</View>
|
|
244
|
+
);
|
|
245
|
+
});`;
|
|
246
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
247
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
248
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
249
|
+
});
|
|
250
|
+
it('wraps a wrapped root app anonymous function', () => {
|
|
251
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
252
|
+
|
|
253
|
+
export default Another.wrap(() => {
|
|
254
|
+
return (
|
|
255
|
+
<View>
|
|
256
|
+
Test App
|
|
257
|
+
</View>
|
|
258
|
+
);
|
|
259
|
+
});`);
|
|
260
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
261
|
+
|
|
262
|
+
export default Sentry.wrap(Another.wrap(() => {
|
|
263
|
+
return (
|
|
264
|
+
<View>
|
|
265
|
+
Test App
|
|
266
|
+
</View>
|
|
267
|
+
);
|
|
268
|
+
}));`;
|
|
269
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
270
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
271
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
272
|
+
});
|
|
273
|
+
it('wraps a complex root function', () => {
|
|
274
|
+
// This is the default export for a new Expo 52 project
|
|
275
|
+
const mod = (0, magicast_1.parseModule)(`import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
|
|
276
|
+
import { useFonts } from 'expo-font';
|
|
277
|
+
import { Stack } from 'expo-router';
|
|
278
|
+
import * as SplashScreen from 'expo-splash-screen';
|
|
279
|
+
import { StatusBar } from 'expo-status-bar';
|
|
280
|
+
import { useEffect } from 'react';
|
|
281
|
+
import 'react-native-reanimated';
|
|
282
|
+
|
|
283
|
+
import { useColorScheme } from '@/hooks/useColorScheme';
|
|
284
|
+
import * as Sentry from '@sentry/react-native';
|
|
285
|
+
|
|
286
|
+
Sentry.init({
|
|
287
|
+
dsn: 'https://sentry.io/123',
|
|
288
|
+
|
|
289
|
+
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
|
|
290
|
+
// spotlight: __DEV__,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
|
294
|
+
SplashScreen.preventAutoHideAsync();
|
|
295
|
+
|
|
296
|
+
export default function RootLayout() {
|
|
297
|
+
const colorScheme = useColorScheme();
|
|
298
|
+
const [loaded] = useFonts({
|
|
299
|
+
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
if (loaded) {
|
|
304
|
+
SplashScreen.hideAsync();
|
|
305
|
+
}
|
|
306
|
+
}, [loaded]);
|
|
307
|
+
|
|
308
|
+
if (!loaded) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return (
|
|
313
|
+
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
314
|
+
<Stack>
|
|
315
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
316
|
+
<Stack.Screen name="+not-found" />
|
|
317
|
+
</Stack>
|
|
318
|
+
<StatusBar style="auto" />
|
|
319
|
+
</ThemeProvider>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
`);
|
|
323
|
+
const expectedOutput = `import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
|
|
324
|
+
import { useFonts } from 'expo-font';
|
|
325
|
+
import { Stack } from 'expo-router';
|
|
326
|
+
import * as SplashScreen from 'expo-splash-screen';
|
|
327
|
+
import { StatusBar } from 'expo-status-bar';
|
|
328
|
+
import { useEffect } from 'react';
|
|
329
|
+
import 'react-native-reanimated';
|
|
330
|
+
|
|
331
|
+
import { useColorScheme } from '@/hooks/useColorScheme';
|
|
332
|
+
import * as Sentry from '@sentry/react-native';
|
|
333
|
+
|
|
334
|
+
Sentry.init({
|
|
335
|
+
dsn: 'https://sentry.io/123',
|
|
336
|
+
|
|
337
|
+
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
|
|
338
|
+
// spotlight: __DEV__,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
|
342
|
+
SplashScreen.preventAutoHideAsync();
|
|
343
|
+
|
|
344
|
+
export default Sentry.wrap(function RootLayout() {
|
|
345
|
+
const colorScheme = useColorScheme();
|
|
346
|
+
const [loaded] = useFonts({
|
|
347
|
+
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
useEffect(() => {
|
|
351
|
+
if (loaded) {
|
|
352
|
+
SplashScreen.hideAsync();
|
|
353
|
+
}
|
|
354
|
+
}, [loaded]);
|
|
355
|
+
|
|
356
|
+
if (!loaded) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return (
|
|
361
|
+
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
362
|
+
<Stack>
|
|
363
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
364
|
+
<Stack.Screen name="+not-found" />
|
|
365
|
+
</Stack>
|
|
366
|
+
<StatusBar style="auto" />
|
|
367
|
+
</ThemeProvider>
|
|
368
|
+
);
|
|
369
|
+
});`;
|
|
370
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
371
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
372
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
373
|
+
});
|
|
374
|
+
it('wraps a root app anonymous complex function', () => {
|
|
375
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
376
|
+
|
|
377
|
+
export default () => {
|
|
378
|
+
const colorScheme = useColorScheme();
|
|
379
|
+
const [loaded] = useFonts({
|
|
380
|
+
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
if (loaded) {
|
|
385
|
+
SplashScreen.hideAsync();
|
|
386
|
+
}
|
|
387
|
+
}, [loaded]);
|
|
388
|
+
|
|
389
|
+
if (!loaded) {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return (
|
|
394
|
+
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
395
|
+
<Stack>
|
|
396
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
397
|
+
<Stack.Screen name="+not-found" />
|
|
398
|
+
</Stack>
|
|
399
|
+
<StatusBar style="auto" />
|
|
400
|
+
</ThemeProvider>
|
|
401
|
+
);
|
|
402
|
+
}`);
|
|
403
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
404
|
+
|
|
405
|
+
export default Sentry.wrap(() => {
|
|
406
|
+
const colorScheme = useColorScheme();
|
|
407
|
+
const [loaded] = useFonts({
|
|
408
|
+
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
useEffect(() => {
|
|
412
|
+
if (loaded) {
|
|
413
|
+
SplashScreen.hideAsync();
|
|
414
|
+
}
|
|
415
|
+
}, [loaded]);
|
|
416
|
+
|
|
417
|
+
if (!loaded) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return (
|
|
422
|
+
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
423
|
+
<Stack>
|
|
424
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
425
|
+
<Stack.Screen name="+not-found" />
|
|
426
|
+
</Stack>
|
|
427
|
+
<StatusBar style="auto" />
|
|
428
|
+
</ThemeProvider>
|
|
429
|
+
);
|
|
430
|
+
});`;
|
|
431
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
432
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
433
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
434
|
+
});
|
|
435
|
+
it('wraps a default class export', () => {
|
|
436
|
+
const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
|
|
437
|
+
|
|
438
|
+
export default class RootLayout extends React.Component {
|
|
439
|
+
render() {
|
|
440
|
+
return (
|
|
441
|
+
<View>
|
|
442
|
+
Test App
|
|
443
|
+
</View>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}`);
|
|
447
|
+
const expectedOutput = `import * as Sentry from '@sentry/react-native';
|
|
448
|
+
|
|
449
|
+
export default Sentry.wrap(class RootLayout extends React.Component {
|
|
450
|
+
render() {
|
|
451
|
+
return (
|
|
452
|
+
<View>
|
|
453
|
+
Test App
|
|
454
|
+
</View>
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
});`;
|
|
458
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
459
|
+
expect(result).toBe(javascript_1.SentryWrapResult.Success);
|
|
460
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
|
|
461
|
+
});
|
|
462
|
+
it('does not wrap a root app component if not found', () => {
|
|
463
|
+
const input = `import * as React from 'react';
|
|
464
|
+
|
|
465
|
+
import { View } from 'react-native';
|
|
466
|
+
|
|
467
|
+
const App = () => {
|
|
468
|
+
return (
|
|
469
|
+
<View>
|
|
470
|
+
Test App
|
|
471
|
+
</View>
|
|
472
|
+
);
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
export { App };`;
|
|
476
|
+
const mod = (0, magicast_1.parseModule)(input);
|
|
477
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
478
|
+
expect(result).toBe(javascript_1.SentryWrapResult.NotFound);
|
|
479
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(input);
|
|
480
|
+
});
|
|
481
|
+
it('does not wrap a root app component if already wrapped', () => {
|
|
482
|
+
const input = `import * as React from 'react';
|
|
483
|
+
import * as Sentry from '@sentry/react-native';
|
|
484
|
+
|
|
485
|
+
import { View } from 'react-native';
|
|
486
|
+
|
|
487
|
+
const App = () => {
|
|
488
|
+
return (
|
|
489
|
+
<View>
|
|
490
|
+
Test App
|
|
491
|
+
</View>
|
|
492
|
+
);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
export default Sentry.wrap(App);`;
|
|
496
|
+
const mod = (0, magicast_1.parseModule)(input);
|
|
497
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
498
|
+
expect(result).toBe(javascript_1.SentryWrapResult.AlreadyWrapped);
|
|
499
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(input);
|
|
500
|
+
});
|
|
501
|
+
it('does not wrap the root app component in an empty file', () => {
|
|
502
|
+
const mod = (0, magicast_1.parseModule)(``);
|
|
503
|
+
const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
|
|
504
|
+
expect(result).toBe(javascript_1.SentryWrapResult.NotFound);
|
|
505
|
+
expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(``);
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
it('does detect Sentry.wrap if exists', () => {
|
|
509
|
+
const mod = (0, magicast_1.parseModule)(`export default Sentry.wrap(App);`);
|
|
510
|
+
const result = (0, javascript_1.doesContainSentryWrap)(mod.$ast);
|
|
511
|
+
expect(result).toBeTruthy();
|
|
512
|
+
});
|
|
513
|
+
it('does not detect Sentry.wrap if not present', () => {
|
|
514
|
+
const mod = (0, magicast_1.parseModule)(`export default App;`);
|
|
515
|
+
const result = (0, javascript_1.doesContainSentryWrap)(mod.$ast);
|
|
516
|
+
expect(result).toBeFalsy();
|
|
517
|
+
});
|
|
112
518
|
});
|
|
113
519
|
//# sourceMappingURL=javascript.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.test.js","sourceRoot":"","sources":["../../../test/react-native/javascript.test.ts"],"names":[],"mappings":";;AAAA,kEAG2C;AAE3C,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;YACvE,MAAM,KAAK,GAAG;;;;;;;;;;;;;;oBAcA,CAAC;YAEf,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;oBAsBT,CAAC;YAEf,MAAM,CAAC,IAAA,uCAA0B,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5D,cAAc,CACf,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;YAC7E,MAAM,KAAK,GAAG,6BAA6B,CAAC;YAC5C,MAAM,CAAC,IAAA,uCAA0B,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;YACnE,MAAM,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,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n addSentryInitWithSdkImport,\n doesJsCodeIncludeSdkSentryImport,\n} from '../../src/react-native/javascript';\n\ndescribe('react-native javascript', () => {\n describe('addSentryInitWithSdkImport', () => {\n it('adds sdk import and sentry init under last import in the file', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n const expectedOutput = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nimport * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: 'dsn',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(\n expectedOutput,\n );\n });\n\n it('does not add sdk import and sentry init in the file without imports', () => {\n const input = `export const test = 'test';`;\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);\n });\n\n it('does not add sdk import and sentry init in the empty file', () => {\n const input = '';\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);\n });\n });\n\n describe('doesJsCodeIncludeSdkSentryImport', () => {\n it('returns true if code has sdk import', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nimport * as Sentry from '@sentry/react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(true);\n });\n\n it('returns true if code has sdk require', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nconst Sentry = require('@sentry/react-native');\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(true);\n });\n\n it('returns false if code does not have sdk import', () => {\n const input = `export const test = 'test';`;\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(false);\n });\n\n it('returns false for empty file', () => {\n const input = '';\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(false);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"javascript.test.js","sourceRoot":"","sources":["../../../test/react-native/javascript.test.ts"],"names":[],"mappings":";;AAAA,kEAM2C;AAC3C,4EAA4E;AAC5E,uCAAqD;AAGrD,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;YACvE,MAAM,KAAK,GAAG;;;;;;;;;;;;;;oBAcA,CAAC;YAEf,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;oBAsBT,CAAC;YAEf,MAAM,CAAC,IAAA,uCAA0B,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5D,cAAc,CACf,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;YAC7E,MAAM,KAAK,GAAG,6BAA6B,CAAC;YAC5C,MAAM,CAAC,IAAA,uCAA0B,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;YACnE,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,CAAC,IAAA,uCAA0B,EAAC,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JsCodeIncludeSdkSentryImport,\n SentryWrapResult,\n} from '../../src/react-native/javascript';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\nimport * as t from '@babel/types';\n\ndescribe('react-native javascript', () => {\n describe('addSentryInitWithSdkImport', () => {\n it('adds sdk import and sentry init under last import in the file', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n const expectedOutput = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nimport * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: 'dsn',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(\n expectedOutput,\n );\n });\n\n it('does not add sdk import and sentry init in the file without imports', () => {\n const input = `export const test = 'test';`;\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);\n });\n\n it('does not add sdk import and sentry init in the empty file', () => {\n const input = '';\n expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);\n });\n });\n\n describe('doesJsCodeIncludeSdkSentryImport', () => {\n it('returns true if code has sdk import', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nimport * as Sentry from '@sentry/react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(true);\n });\n\n it('returns true if code has sdk require', () => {\n const input = `import * as React from 'react';\n\nconst test = 'test';\n\nimport { View } from 'react-native';\nconst Sentry = require('@sentry/react-native');\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`;\n\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(true);\n });\n\n it('returns false if code does not have sdk import', () => {\n const input = `export const test = 'test';`;\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(false);\n });\n\n it('returns false for empty file', () => {\n const input = '';\n expect(\n doesJsCodeIncludeSdkSentryImport(input, {\n sdkPackageName: '@sentry/react-native',\n }),\n ).toBe(false);\n });\n });\n\n describe('addSentryWrap', () => {\n it('wraps the root app component', () => {\n const mod = parseModule(`import * as React from 'react';\nimport * as Sentry from '@sentry/react-native';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default App;`);\n\n const expectedOutput = `import * as React from 'react';\nimport * as Sentry from '@sentry/react-native';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default Sentry.wrap(App);`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a wrapped root app component', () => {\n const mod = parseModule(`import * as React from 'react';\nimport * as Sentry from '@sentry/react-native';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default AnotheWrapper.wrap(App);`);\n\n const expectedOutput = `import * as React from 'react';\nimport * as Sentry from '@sentry/react-native';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default Sentry.wrap(AnotheWrapper.wrap(App));`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a root app named function', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default function RootLayout() {\n return (\n <View>\n Test App\n </View>\n );\n}`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(function RootLayout() {\n return (\n <View>\n Test App\n </View>\n );\n});`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a wrapped root app named function', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default Another.wrapper(function RootLayout() {\n return (\n <View>\n Test App\n </View>\n );\n});`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(Another.wrapper(function RootLayout() {\n return (\n <View>\n Test App\n </View>\n );\n}));`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a root app anonymous function', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default () => {\n return (\n <View>\n Test App\n </View>\n );\n}`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(() => {\n return (\n <View>\n Test App\n </View>\n );\n});`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a wrapped root app anonymous function', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default Another.wrap(() => {\n return (\n <View>\n Test App\n </View>\n );\n});`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(Another.wrap(() => {\n return (\n <View>\n Test App\n </View>\n );\n}));`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a complex root function', () => {\n // This is the default export for a new Expo 52 project\n const mod =\n parseModule(`import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';\nimport { useFonts } from 'expo-font';\nimport { Stack } from 'expo-router';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { StatusBar } from 'expo-status-bar';\nimport { useEffect } from 'react';\nimport 'react-native-reanimated';\n\nimport { useColorScheme } from '@/hooks/useColorScheme';\nimport * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: 'https://sentry.io/123',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});\n\n// Prevent the splash screen from auto-hiding before asset loading is complete.\nSplashScreen.preventAutoHideAsync();\n\nexport default function RootLayout() {\n const colorScheme = useColorScheme();\n const [loaded] = useFonts({\n SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),\n });\n\n useEffect(() => {\n if (loaded) {\n SplashScreen.hideAsync();\n }\n }, [loaded]);\n\n if (!loaded) {\n return null;\n }\n\n return (\n <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>\n <Stack>\n <Stack.Screen name=\"(tabs)\" options={{ headerShown: false }} />\n <Stack.Screen name=\"+not-found\" />\n </Stack>\n <StatusBar style=\"auto\" />\n </ThemeProvider>\n );\n}\n`);\n\n const expectedOutput = `import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';\nimport { useFonts } from 'expo-font';\nimport { Stack } from 'expo-router';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { StatusBar } from 'expo-status-bar';\nimport { useEffect } from 'react';\nimport 'react-native-reanimated';\n\nimport { useColorScheme } from '@/hooks/useColorScheme';\nimport * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: 'https://sentry.io/123',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});\n\n// Prevent the splash screen from auto-hiding before asset loading is complete.\nSplashScreen.preventAutoHideAsync();\n\nexport default Sentry.wrap(function RootLayout() {\n const colorScheme = useColorScheme();\n const [loaded] = useFonts({\n SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),\n });\n\n useEffect(() => {\n if (loaded) {\n SplashScreen.hideAsync();\n }\n }, [loaded]);\n\n if (!loaded) {\n return null;\n }\n\n return (\n <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>\n <Stack>\n <Stack.Screen name=\"(tabs)\" options={{ headerShown: false }} />\n <Stack.Screen name=\"+not-found\" />\n </Stack>\n <StatusBar style=\"auto\" />\n </ThemeProvider>\n );\n});`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a root app anonymous complex function', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default () => {\n const colorScheme = useColorScheme();\n const [loaded] = useFonts({\n SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),\n });\n\n useEffect(() => {\n if (loaded) {\n SplashScreen.hideAsync();\n }\n }, [loaded]);\n\n if (!loaded) {\n return null;\n }\n\n return (\n <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>\n <Stack>\n <Stack.Screen name=\"(tabs)\" options={{ headerShown: false }} />\n <Stack.Screen name=\"+not-found\" />\n </Stack>\n <StatusBar style=\"auto\" />\n </ThemeProvider>\n );\n}`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(() => {\n const colorScheme = useColorScheme();\n const [loaded] = useFonts({\n SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),\n });\n\n useEffect(() => {\n if (loaded) {\n SplashScreen.hideAsync();\n }\n }, [loaded]);\n\n if (!loaded) {\n return null;\n }\n\n return (\n <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>\n <Stack>\n <Stack.Screen name=\"(tabs)\" options={{ headerShown: false }} />\n <Stack.Screen name=\"+not-found\" />\n </Stack>\n <StatusBar style=\"auto\" />\n </ThemeProvider>\n );\n});`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('wraps a default class export', () => {\n const mod = parseModule(`import * as Sentry from '@sentry/react-native';\n\nexport default class RootLayout extends React.Component {\n render() {\n return (\n <View>\n Test App\n </View>\n );\n }\n}`);\n\n const expectedOutput = `import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(class RootLayout extends React.Component {\n render() {\n return (\n <View>\n Test App\n </View>\n );\n }\n});`;\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.Success);\n expect(generateCode(mod.$ast).code).toBe(expectedOutput);\n });\n\n it('does not wrap a root app component if not found', () => {\n const input = `import * as React from 'react';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport { App };`;\n const mod = parseModule(input);\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.NotFound);\n expect(generateCode(mod.$ast).code).toBe(input);\n });\n\n it('does not wrap a root app component if already wrapped', () => {\n const input = `import * as React from 'react';\nimport * as Sentry from '@sentry/react-native';\n\nimport { View } from 'react-native';\n\nconst App = () => {\n return (\n <View>\n Test App\n </View>\n );\n};\n\nexport default Sentry.wrap(App);`;\n const mod = parseModule(input);\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.AlreadyWrapped);\n expect(generateCode(mod.$ast).code).toBe(input);\n });\n\n it('does not wrap the root app component in an empty file', () => {\n const mod = parseModule(``);\n\n const result = checkAndWrapRootComponent(mod);\n\n expect(result).toBe(SentryWrapResult.NotFound);\n expect(generateCode(mod.$ast).code).toBe(``);\n });\n });\n\n it('does detect Sentry.wrap if exists', () => {\n const mod = parseModule(`export default Sentry.wrap(App);`);\n\n const result = doesContainSentryWrap(mod.$ast as t.Program);\n\n expect(result).toBeTruthy();\n });\n\n it('does not detect Sentry.wrap if not present', () => {\n const mod = parseModule(`export default App;`);\n\n const result = doesContainSentryWrap(mod.$ast as t.Program);\n\n expect(result).toBeFalsy();\n });\n});\n"]}
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const fs = __importStar(require("fs"));
|
|
27
27
|
const sentry_cli_1 = require("../../../src/sourcemaps/tools/sentry-cli");
|
|
28
28
|
const packageManagerHelpers = __importStar(require("../../../src/utils/package-manager"));
|
|
29
|
+
const clack_utils_1 = require("../../../src/utils/clack-utils");
|
|
29
30
|
const writeFileSpy = jest
|
|
30
31
|
.spyOn(fs.promises, 'writeFile')
|
|
31
32
|
.mockImplementation(() => Promise.resolve());
|
|
@@ -68,5 +69,15 @@ describe('addSentryCommandToBuildCommand', () => {
|
|
|
68
69
|
await (0, sentry_cli_1.addSentryCommandToBuildCommand)();
|
|
69
70
|
expect(writeFileSpy).toHaveBeenCalledWith(expect.stringContaining('package.json'), expect.stringContaining(`tsc && ${pacMan.runScriptCommand} sentry:sourcemaps`));
|
|
70
71
|
});
|
|
72
|
+
it('does not add the cli command to the script command if it is already in there', async () => {
|
|
73
|
+
jest.mocked(clack_utils_1.getPackageDotJson).mockResolvedValue({
|
|
74
|
+
scripts: {
|
|
75
|
+
build: 'tsc && sentry:sourcemaps',
|
|
76
|
+
},
|
|
77
|
+
version: '1.0.0',
|
|
78
|
+
});
|
|
79
|
+
await (0, sentry_cli_1.addSentryCommandToBuildCommand)();
|
|
80
|
+
expect(writeFileSpy).not.toHaveBeenCalled();
|
|
81
|
+
});
|
|
71
82
|
});
|
|
72
83
|
//# sourceMappingURL=sentry-cli.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-cli.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/sentry-cli.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,yEAA0F;AAE1F,0FAA4E;
|
|
1
|
+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C1B,qBAAqB,CAAC,OAAO;YAC7B,qBAAqB,CAAC,OAAO;YAC7B,qBAAqB,CAAC,GAAG;SAC1B;KACF,CAAC,CAAC,iDAAiD,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;QACxE,IAAI;aACD,KAAK,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;aACnD,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,IAAA,2CAA8B,GAAE,CAAC;QACvC,MAAM,CAAC,YAAY,CAAC,CAAC,oBAAoB,CACvC,MAAM,CAAC,gBAAgB,CAAC,cAAc,CAAC,EACvC,MAAM,CAAC,gBAAgB,CACrB,UAAU,MAAM,CAAC,gBAAgB,oBAAoB,CACtD,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;QAC5F,IAAI,CAAC,MAAM,CAAC,+BAAiB,CAAC,CAAC,iBAAiB,CAAC;YAC/C,OAAO,EAAE;gBACP,KAAK,EAAE,0BAA0B;aAClC;YACD,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;QAEH,MAAM,IAAA,2CAA8B,GAAE,CAAC;QAEvC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\n\nimport { addSentryCommandToBuildCommand } from '../../../src/sourcemaps/tools/sentry-cli';\n\nimport * as packageManagerHelpers from '../../../src/utils/package-manager';\nimport { getPackageDotJson } from '../../../src/utils/clack-utils';\nconst writeFileSpy = jest\n .spyOn(fs.promises, 'writeFile')\n .mockImplementation(() => Promise.resolve());\n\njest.mock('@clack/prompts', () => {\n return {\n log: {\n info: jest.fn(),\n success: jest.fn(),\n },\n confirm: jest.fn().mockResolvedValue(true),\n isCancel: jest.fn().mockReturnValue(false),\n };\n});\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-return\njest.mock('../../../src/utils/clack-utils', () => ({\n ...jest.requireActual('../../../src/utils/clack-utils'),\n getPackageDotJson: jest.fn().mockResolvedValue({\n scripts: {\n build: 'tsc',\n },\n version: '1.0.0',\n }),\n}));\n\ndescribe('addSentryCommandToBuildCommand', () => {\n afterEach(() => {\n jest.clearAllMocks();\n });\n it.each([\n [\n packageManagerHelpers.NPM,\n packageManagerHelpers.PNPM,\n packageManagerHelpers.YARN_V1,\n packageManagerHelpers.YARN_V2,\n packageManagerHelpers.BUN,\n ],\n ])('adds the cli command to the script command (%s)', async (_, pacMan) => {\n jest\n .spyOn(packageManagerHelpers, 'detectPackageManger')\n .mockReturnValue(pacMan);\n await addSentryCommandToBuildCommand();\n expect(writeFileSpy).toHaveBeenCalledWith(\n expect.stringContaining('package.json'),\n expect.stringContaining(\n `tsc && ${pacMan.runScriptCommand} sentry:sourcemaps`,\n ),\n );\n });\n\n it('does not add the cli command to the script command if it is already in there', async () => {\n jest.mocked(getPackageDotJson).mockResolvedValue({\n scripts: {\n build: 'tsc && sentry:sourcemaps',\n },\n version: '1.0.0',\n });\n\n await addSentryCommandToBuildCommand();\n\n expect(writeFileSpy).not.toHaveBeenCalled();\n });\n});\n"]}
|