@sentry/wizard 4.9.0 → 5.1.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 +17 -0
- package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.d.ts +1 -0
- package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.js +91 -0
- package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.js.map +1 -0
- package/dist/e2e-tests/tests/nextjs-14.test.js +27 -0
- package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
- package/dist/e2e-tests/utils/index.d.ts +1 -0
- package/dist/e2e-tests/utils/index.js +23 -1
- package/dist/e2e-tests/utils/index.js.map +1 -1
- package/dist/lib/Steps/Integrations/Cordova.js +13 -30
- package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +24 -10
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +2 -0
- package/dist/src/nextjs/templates.js +47 -1
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nextjs/utils.d.ts +2 -0
- package/dist/src/nextjs/utils.js +42 -1
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/react-native/gradle.d.ts +0 -1
- package/dist/src/react-native/gradle.js +1 -5
- package/dist/src/react-native/gradle.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +0 -4
- package/dist/src/react-native/metro.js +1 -129
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/options.d.ts +1 -3
- package/dist/src/react-native/options.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.d.ts +1 -23
- package/dist/src/react-native/react-native-wizard.js +25 -127
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-native/xcode.d.ts +0 -7
- package/dist/src/react-native/xcode.js +1 -109
- package/dist/src/react-native/xcode.js.map +1 -1
- package/dist/src/run.js +1 -4
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +14 -0
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/wrangler.d.ts +28 -0
- package/dist/src/sourcemaps/tools/wrangler.js +276 -0
- package/dist/src/sourcemaps/tools/wrangler.js.map +1 -0
- package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
- package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
- package/dist/src/sourcemaps/utils/sdk-version.js +3 -0
- package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +0 -7
- package/dist/src/utils/ast-utils.js +1 -27
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack/index.d.ts +9 -1
- package/dist/src/utils/clack/index.js +8 -1
- package/dist/src/utils/clack/index.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 +98 -0
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/nextjs/utils.test.d.ts +1 -0
- package/dist/test/nextjs/utils.test.js +104 -0
- package/dist/test/nextjs/utils.test.js.map +1 -0
- package/dist/test/react-native/gradle.test.js +0 -119
- package/dist/test/react-native/gradle.test.js.map +1 -1
- package/dist/test/react-native/metro.test.js +0 -90
- package/dist/test/react-native/metro.test.js.map +1 -1
- package/dist/test/react-native/xcode.test.js +0 -81
- package/dist/test/react-native/xcode.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/wrangler.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/wrangler.test.js +132 -0
- package/dist/test/sourcemaps/tools/wrangler.test.js.map +1 -0
- package/package.json +2 -1
- package/dist/src/react-native/uninstall.d.ts +0 -2
- package/dist/src/react-native/uninstall.js +0 -94
- package/dist/src/react-native/uninstall.js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,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,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,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,iBAAQ,EAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,IAAA,WAAE,EAAC,8CAA8C,EAAE,GAAG,EAAE;YACtD,IAAA,eAAM,EAAC,IAAA,yBAAa,EAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;OAqBjD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAA,WAAE,EAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,IAAA,eAAM,EAAC,IAAA,yBAAa,EAAC,KAAK,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;OAmBlD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from 'vitest';\nimport {\n getRootLayout,\n getSentryServersideConfigContents,\n getInstrumentationClientFileContents,\n getWithSentryConfigOptionsTemplate,\n} from '../../src/nextjs/templates';\n\ndescribe('Next.js code templates', () => {\n describe('getInstrumentationClientFileContents', () => {\n it('generates client-side Sentry config with all features enabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n\n it('generates client-side Sentry config with performance monitoring disabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n\n it('generates client-side Sentry config with session replay disabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n });\n\n describe('getSentryServersideConfigContents', () => {\n describe('server-side', () => {\n it('generates server-side Sentry config with all features enabled', () => {\n const template = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 describe('getRootLayout', () => {\n it('generates a root layout component with types', () => {\n expect(getRootLayout(true)).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n // You can delete this file at any time.\n\n export const metadata = {\n title: 'Sentry NextJS Example',\n description: 'Generated by Sentry',\n }\n\n export default function RootLayout({\n children,\n }: {\n children: React.ReactNode\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n it('generates a root layout component without types', () => {\n expect(getRootLayout(false)).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n // You can delete this file at any time.\n\n export const metadata = {\n title: 'Sentry NextJS Example',\n description: 'Generated by Sentry',\n }\n\n export default function RootLayout({\n children,\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"templates.test.js","sourceRoot":"","sources":["../../../test/nextjs/templates.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,0DAOoC;AAEpC,IAAA,iBAAQ,EAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,IAAA,iBAAQ,EAAC,sCAAsC,EAAE,GAAG,EAAE;QACpD,IAAA,WAAE,EAAC,+DAA+D,EAAE,GAAG,EAAE;YACvE,MAAM,QAAQ,GAAG,IAAA,gDAAoC,EAAC,QAAQ,EAAE;gBAC9D,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;YAEH,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,0EAA0E,EAAE,GAAG,EAAE;YAClF,MAAM,QAAQ,GAAG,IAAA,gDAAoC,EAAC,QAAQ,EAAE;gBAC9D,WAAW,EAAE,KAAK;gBAClB,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;YAEH,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,kEAAkE,EAAE,GAAG,EA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Layout,\n getSentryServersideConfigContents,\n getInstrumentationClientFileContents,\n getWithSentryConfigOptionsTemplate,\n getGenerateMetadataSnippet,\n getRootLayoutWithGenerateMetadata,\n} from '../../src/nextjs/templates';\n\ndescribe('Next.js code templates', () => {\n describe('getInstrumentationClientFileContents', () => {\n it('generates client-side Sentry config with all features enabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n\n it('generates client-side Sentry config with performance monitoring disabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n\n it('generates client-side Sentry config with session replay disabled', () => {\n const template = getInstrumentationClientFileContents('my-dsn', {\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 added config 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 export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;\"\n `);\n });\n });\n\n describe('getSentryServersideConfigContents', () => {\n describe('server-side', () => {\n it('generates server-side Sentry config with all features enabled', () => {\n const template = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 = getSentryServersideConfigContents('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 describe('getRootLayout', () => {\n it('generates a root layout component with types', () => {\n expect(getRootLayout(true)).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n // You can delete this file at any time.\n\n export const metadata = {\n title: 'Sentry NextJS Example',\n description: 'Generated by Sentry',\n }\n\n export default function RootLayout({\n children,\n }: {\n children: React.ReactNode\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n it('generates a root layout component without types', () => {\n expect(getRootLayout(false)).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n // You can delete this file at any time.\n\n export const metadata = {\n title: 'Sentry NextJS Example',\n description: 'Generated by Sentry',\n }\n\n export default function RootLayout({\n children,\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n });\n\n describe('getGenerateMetadataSnippet', () => {\n it('generates metadata snippet with TypeScript types', () => {\n const template = getGenerateMetadataSnippet(true);\n\n expect(template).toMatchInlineSnapshot(`\n\"\n import * as Sentry from '@sentry/nextjs';\n import type { Metadata } from 'next';\n\n // Add or edit your \"generateMetadata\" to include the Sentry trace data:\n export function generateMetadata(): Metadata {\n return {\n // ... your existing metadata\n other: {\n ...Sentry.getTraceData()\n }\n };\n }\n\"\n`);\n });\n\n it('generates metadata snippet without TypeScript types', () => {\n const template = getGenerateMetadataSnippet(false);\n\n expect(template).toMatchInlineSnapshot(`\n\"\n import * as Sentry from '@sentry/nextjs';\n \n\n // Add or edit your \"generateMetadata\" to include the Sentry trace data:\n export function generateMetadata() {\n return {\n // ... your existing metadata\n other: {\n ...Sentry.getTraceData()\n }\n };\n }\n\"\n `);\n });\n });\n\n describe('getRootLayoutWithGenerateMetadata', () => {\n it('generates root layout with TypeScript types', () => {\n const template = getRootLayoutWithGenerateMetadata(true);\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n import * as Sentry from '@sentry/nextjs';\n import type { Metadata } from 'next';\n\n export function generateMetadata(): Metadata {\n return {\n other: {\n ...Sentry.getTraceData(),\n }\n }\n };\n\n export default function RootLayout({\n children,\n }: {\n children: React.ReactNode\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n\n it('generates root layout without TypeScript types', () => {\n const template = getRootLayoutWithGenerateMetadata(false);\n\n expect(template).toMatchInlineSnapshot(`\n \"// This file was generated by the Sentry wizard because we couldn't find a root layout file.\n import * as Sentry from '@sentry/nextjs';\n\n \n export function generateMetadata() {\n return {\n other: {\n ...Sentry.getTraceData(),\n }\n }\n };\n\n export default function RootLayout({\n children,\n }) {\n return (\n <html lang=\"en\">\n <body>{children}</body>\n </html>\n )\n }\n \"\n `);\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const vitest_1 = require("vitest");
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const utils_1 = require("../../src/nextjs/utils");
|
|
29
|
+
vitest_1.vi.mock('fs', () => ({
|
|
30
|
+
existsSync: vitest_1.vi.fn(),
|
|
31
|
+
lstatSync: vitest_1.vi.fn(),
|
|
32
|
+
}));
|
|
33
|
+
(0, vitest_1.describe)('Next.js Utils', () => {
|
|
34
|
+
(0, vitest_1.describe)('getNextJsVersionBucket', () => {
|
|
35
|
+
(0, vitest_1.it)('returns "none" for undefined version', () => {
|
|
36
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)(undefined)).toBe('none');
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('returns "<11.0.0" for versions below 11', () => {
|
|
39
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('10.0.0')).toBe('<11.0.0');
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.it)('returns major version for versions 11 and above', () => {
|
|
42
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('11.0.0')).toBe('11.x');
|
|
43
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('11.2.5')).toBe('11.x');
|
|
44
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('13.5.2')).toBe('13.x');
|
|
45
|
+
(0, vitest_1.expect)((0, utils_1.getNextJsVersionBucket)('14.0.0')).toBe('14.x');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.describe)('getMaybeAppDirLocation', () => {
|
|
49
|
+
const mockCwd = '/mock/cwd';
|
|
50
|
+
let originalCwd;
|
|
51
|
+
(0, vitest_1.beforeEach)(() => {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
53
|
+
originalCwd = process.cwd;
|
|
54
|
+
process.cwd = vitest_1.vi.fn(() => mockCwd);
|
|
55
|
+
vitest_1.vi.clearAllMocks();
|
|
56
|
+
});
|
|
57
|
+
(0, vitest_1.afterEach)(() => {
|
|
58
|
+
process.cwd = originalCwd;
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.it)('returns ["app"] when app directory exists in root', () => {
|
|
61
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
62
|
+
return filePath === '/mock/cwd/app';
|
|
63
|
+
});
|
|
64
|
+
fs.lstatSync.mockImplementation((filePath) => ({
|
|
65
|
+
isDirectory: () => filePath === '/mock/cwd/app',
|
|
66
|
+
}));
|
|
67
|
+
(0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toEqual(['app']);
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)('returns ["src", "app"] when app directory exists in src', () => {
|
|
70
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
71
|
+
return filePath === '/mock/cwd/src/app';
|
|
72
|
+
});
|
|
73
|
+
fs.lstatSync.mockImplementation((filePath) => ({
|
|
74
|
+
isDirectory: () => filePath === '/mock/cwd/src/app',
|
|
75
|
+
}));
|
|
76
|
+
(0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toEqual(['src', 'app']);
|
|
77
|
+
});
|
|
78
|
+
(0, vitest_1.it)('returns undefined when no app directory exists', () => {
|
|
79
|
+
fs.existsSync.mockReturnValue(false);
|
|
80
|
+
(0, vitest_1.expect)((0, utils_1.getMaybeAppDirLocation)()).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.describe)('hasRootLayoutFile', () => {
|
|
84
|
+
(0, vitest_1.beforeEach)(() => {
|
|
85
|
+
vitest_1.vi.clearAllMocks();
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)('returns true when layout file exists with any supported extension', () => {
|
|
88
|
+
const mockAppFolderPath = '/mock/app';
|
|
89
|
+
const supportedExtensions = ['jsx', 'tsx', 'js'];
|
|
90
|
+
supportedExtensions.forEach((ext) => {
|
|
91
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
92
|
+
return filePath === `/mock/app/layout.${ext}`;
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.expect)((0, utils_1.hasRootLayoutFile)(mockAppFolderPath)).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
(0, vitest_1.it)('returns false when no layout file exists', () => {
|
|
98
|
+
const mockAppFolderPath = '/mock/app';
|
|
99
|
+
fs.existsSync.mockReturnValue(false);
|
|
100
|
+
(0, vitest_1.expect)((0, utils_1.hasRootLayoutFile)(mockAppFolderPath)).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../test/nextjs/utils.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAyE;AAEzE,uCAAyB;AACzB,kDAIgC;AAEhC,WAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACnB,UAAU,EAAE,WAAE,CAAC,EAAE,EAAE;IACnB,SAAS,EAAE,WAAE,CAAC,EAAE,EAAE;CACnB,CAAC,CAAC,CAAC;AAEJ,IAAA,iBAAQ,EAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAA,iBAAQ,EAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,IAAA,WAAE,EAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,IAAA,eAAM,EAAC,IAAA,8BAAsB,EAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,C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YACd,WAAE,CAAC,aAAa,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,mEAAmE,EAAE,GAAG,EAAE;YAC3E,MAAM,iBAAiB,GAAG,WAAW,CAAC;YACtC,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YAEjD,mBAAmB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACjC,EAAE,CAAC,UAAmB,CAAC,kBAAkB,CAAC,CAAC,QAAgB,EAAE,EAAE;oBAC9D,OAAO,QAAQ,KAAK,oBAAoB,GAAG,EAAE,CAAC;gBAChD,CAAC,CAAC,CAAC;gBAEH,IAAA,eAAM,EAAC,IAAA,yBAAiB,EAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,iBAAiB,GAAG,WAAW,CAAC;YACrC,EAAE,CAAC,UAAmB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAE/C,IAAA,eAAM,EAAC,IAAA,yBAAiB,EAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';\nimport type { Mock } from 'vitest';\nimport * as fs from 'fs';\nimport {\n getNextJsVersionBucket,\n getMaybeAppDirLocation,\n hasRootLayoutFile,\n} from '../../src/nextjs/utils';\n\nvi.mock('fs', () => ({\n existsSync: vi.fn(),\n lstatSync: vi.fn(),\n}));\n\ndescribe('Next.js Utils', () => {\n describe('getNextJsVersionBucket', () => {\n it('returns \"none\" for undefined version', () => {\n expect(getNextJsVersionBucket(undefined)).toBe('none');\n });\n\n it('returns \"<11.0.0\" for versions below 11', () => {\n expect(getNextJsVersionBucket('10.0.0')).toBe('<11.0.0');\n });\n\n it('returns major version for versions 11 and above', () => {\n expect(getNextJsVersionBucket('11.0.0')).toBe('11.x');\n expect(getNextJsVersionBucket('11.2.5')).toBe('11.x');\n expect(getNextJsVersionBucket('13.5.2')).toBe('13.x');\n expect(getNextJsVersionBucket('14.0.0')).toBe('14.x');\n });\n });\n\n describe('getMaybeAppDirLocation', () => {\n const mockCwd = '/mock/cwd';\n let originalCwd: () => string;\n\n beforeEach(() => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n originalCwd = process.cwd;\n process.cwd = vi.fn(() => mockCwd);\n vi.clearAllMocks();\n });\n\n afterEach(() => {\n process.cwd = originalCwd;\n });\n\n it('returns [\"app\"] when app directory exists in root', () => {\n (fs.existsSync as Mock).mockImplementation((filePath: string) => {\n return filePath === '/mock/cwd/app';\n });\n (fs.lstatSync as Mock).mockImplementation((filePath: string) => ({\n isDirectory: () => filePath === '/mock/cwd/app',\n }));\n\n expect(getMaybeAppDirLocation()).toEqual(['app']);\n });\n\n it('returns [\"src\", \"app\"] when app directory exists in src', () => {\n (fs.existsSync as Mock).mockImplementation((filePath: string) => {\n return filePath === '/mock/cwd/src/app';\n });\n (fs.lstatSync as Mock).mockImplementation((filePath: string) => ({\n isDirectory: () => filePath === '/mock/cwd/src/app',\n }));\n\n expect(getMaybeAppDirLocation()).toEqual(['src', 'app']);\n });\n\n it('returns undefined when no app directory exists', () => {\n (fs.existsSync as Mock).mockReturnValue(false);\n\n expect(getMaybeAppDirLocation()).toBeUndefined();\n });\n });\n\n describe('hasRootLayoutFile', () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it('returns true when layout file exists with any supported extension', () => {\n const mockAppFolderPath = '/mock/app';\n const supportedExtensions = ['jsx', 'tsx', 'js'];\n\n supportedExtensions.forEach((ext) => {\n (fs.existsSync as Mock).mockImplementation((filePath: string) => {\n return filePath === `/mock/app/layout.${ext}`;\n });\n\n expect(hasRootLayoutFile(mockAppFolderPath)).toBe(true);\n });\n });\n\n it('returns false when no layout file exists', () => {\n const mockAppFolderPath = '/mock/app';\n (fs.existsSync as Mock).mockReturnValue(false);\n\n expect(hasRootLayoutFile(mockAppFolderPath)).toBe(false);\n });\n });\n});\n"]}
|
|
@@ -167,124 +167,5 @@ android {
|
|
|
167
167
|
(0, vitest_1.expect)((0, gradle_1.addRNSentryGradlePlugin)(input)).toBe(expectedOutput);
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
|
-
(0, vitest_1.describe)('removeRNSentryGradlePlugin', () => {
|
|
171
|
-
(0, vitest_1.it)('does not add nothing to empty file', () => {
|
|
172
|
-
(0, vitest_1.expect)((0, gradle_1.removeRNSentryGradlePlugin)('')).toBe('');
|
|
173
|
-
});
|
|
174
|
-
(0, vitest_1.it)('does not change build gradle without RN SAGP', () => {
|
|
175
|
-
const input = `apply plugin: "com.android.application"
|
|
176
|
-
apply plugin: "io.sentry.android.gradle"
|
|
177
|
-
|
|
178
|
-
sentry {
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
android {
|
|
182
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
183
|
-
|
|
184
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
185
|
-
|
|
186
|
-
namespace "com.samplenewarchitecture"
|
|
187
|
-
defaultConfig {
|
|
188
|
-
applicationId "com.samplenewarchitecture"
|
|
189
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
190
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
191
|
-
versionCode 1
|
|
192
|
-
versionName "1.0"
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
`;
|
|
196
|
-
(0, vitest_1.expect)((0, gradle_1.removeRNSentryGradlePlugin)(input)).toBe(input);
|
|
197
|
-
});
|
|
198
|
-
(0, vitest_1.it)('does remove RN SAGP referenced by node resolved path', () => {
|
|
199
|
-
const input = `apply plugin: "com.android.application"
|
|
200
|
-
apply plugin: "io.sentry.android.gradle"
|
|
201
|
-
|
|
202
|
-
sentry {
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
|
|
206
|
-
android {
|
|
207
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
208
|
-
|
|
209
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
210
|
-
|
|
211
|
-
namespace "com.samplenewarchitecture"
|
|
212
|
-
defaultConfig {
|
|
213
|
-
applicationId "com.samplenewarchitecture"
|
|
214
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
215
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
216
|
-
versionCode 1
|
|
217
|
-
versionName "1.0"
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
`;
|
|
221
|
-
const output = `apply plugin: "com.android.application"
|
|
222
|
-
apply plugin: "io.sentry.android.gradle"
|
|
223
|
-
|
|
224
|
-
sentry {
|
|
225
|
-
}
|
|
226
|
-
android {
|
|
227
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
228
|
-
|
|
229
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
230
|
-
|
|
231
|
-
namespace "com.samplenewarchitecture"
|
|
232
|
-
defaultConfig {
|
|
233
|
-
applicationId "com.samplenewarchitecture"
|
|
234
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
235
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
236
|
-
versionCode 1
|
|
237
|
-
versionName "1.0"
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
`;
|
|
241
|
-
(0, vitest_1.expect)((0, gradle_1.removeRNSentryGradlePlugin)(input)).toBe(output);
|
|
242
|
-
});
|
|
243
|
-
(0, vitest_1.it)('does remove RN SAGP reference by relative path', () => {
|
|
244
|
-
const input = `apply plugin: "com.android.application"
|
|
245
|
-
apply plugin: "io.sentry.android.gradle"
|
|
246
|
-
|
|
247
|
-
sentry {
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"
|
|
251
|
-
android {
|
|
252
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
253
|
-
|
|
254
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
255
|
-
|
|
256
|
-
namespace "com.samplenewarchitecture"
|
|
257
|
-
defaultConfig {
|
|
258
|
-
applicationId "com.samplenewarchitecture"
|
|
259
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
260
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
261
|
-
versionCode 1
|
|
262
|
-
versionName "1.0"
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
`;
|
|
266
|
-
const output = `apply plugin: "com.android.application"
|
|
267
|
-
apply plugin: "io.sentry.android.gradle"
|
|
268
|
-
|
|
269
|
-
sentry {
|
|
270
|
-
}
|
|
271
|
-
android {
|
|
272
|
-
ndkVersion rootProject.ext.ndkVersion
|
|
273
|
-
|
|
274
|
-
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
275
|
-
|
|
276
|
-
namespace "com.samplenewarchitecture"
|
|
277
|
-
defaultConfig {
|
|
278
|
-
applicationId "com.samplenewarchitecture"
|
|
279
|
-
minSdkVersion rootProject.ext.minSdkVersion
|
|
280
|
-
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
281
|
-
versionCode 1
|
|
282
|
-
versionName "1.0"
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
`;
|
|
286
|
-
(0, vitest_1.expect)((0, gradle_1.removeRNSentryGradlePlugin)(input)).toBe(output);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
170
|
});
|
|
290
171
|
//# sourceMappingURL=gradle.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradle.test.js","sourceRoot":"","sources":["../../../test/react-native/gradle.test.ts"],"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,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;CAmBpB,CAAC;YAEI,IAAA,eAAM,EAAC,IAAA,mCAA0B,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBnB,CAAC;YACI,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;CAmBpB,CAAC;YAEI,IAAA,eAAM,EAAC,IAAA,mCAA0B,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from 'vitest';\nimport {\n addRNSentryGradlePlugin,\n doesAppBuildGradleIncludeRNSentryGradlePlugin,\n removeRNSentryGradlePlugin,\n} from '../../src/react-native/gradle';\n\ndescribe('react-native gradle', () => {\n describe('doesAppBuildGradleIncludeSentry', () => {\n it('returns false for empty file', () => {\n expect(doesAppBuildGradleIncludeRNSentryGradlePlugin('')).toBe(false);\n });\n\n it('returns false for minimal app/build.gradle', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(false);\n });\n\n it('returns false for app/build.gradle with SAGP', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(false);\n });\n\n it('returns true for app/build.gradle with RN SAGP', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(true);\n });\n });\n\n describe('addRNSentryGradlePlugin', () => {\n it('does not add nothing to empty file', () => {\n expect(addRNSentryGradlePlugin('')).toBe('');\n });\n\n it('does add RN SAGP', () => {\n const input = `apply plugin: \"com.android.application\"\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const expectedOutput = `apply plugin: \"com.android.application\"\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);\n });\n\n it('does add RN SAGP to build gradle with SAGP', () => {\n const input = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const expectedOutput = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);\n });\n });\n\n describe('removeRNSentryGradlePlugin', () => {\n it('does not add nothing to empty file', () => {\n expect(removeRNSentryGradlePlugin('')).toBe('');\n });\n\n it('does not change build gradle without RN SAGP', () => {\n const input = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n\n expect(removeRNSentryGradlePlugin(input)).toBe(input);\n });\n\n it('does remove RN SAGP referenced by node resolved path', () => {\n const input = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const output = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n\n expect(removeRNSentryGradlePlugin(input)).toBe(output);\n });\n\n it('does remove RN SAGP reference by relative path', () => {\n const input = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: \"../../node_modules/@sentry/react-native/sentry.gradle\"\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const output = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n\n expect(removeRNSentryGradlePlugin(input)).toBe(output);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"gradle.test.js","sourceRoot":"","sources":["../../../test/react-native/gradle.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,0DAGuC;AAEvC,IAAA,iBAAQ,EAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAA,iBAAQ,EAAC,iCAAiC,EAAE,GAAG,EAAE;QAC/C,IAAA,WAAE,EAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,IAAA,eAAM,EAAC,IAAA,sDAA6C,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;CAgB5B,CAAC;YACI,IAAA,eAAM,EACJ,IAAA,sDAA6C,EAAC,cAAc,CAAC,CAC9D,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,8CAA8C,EAAE,GAAG,EAAE;YACtD,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;CAoB5B,CAAC;YACI,IAAA,eAAM,EACJ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e, expect, it } from 'vitest';\nimport {\n addRNSentryGradlePlugin,\n doesAppBuildGradleIncludeRNSentryGradlePlugin,\n} from '../../src/react-native/gradle';\n\ndescribe('react-native gradle', () => {\n describe('doesAppBuildGradleIncludeSentry', () => {\n it('returns false for empty file', () => {\n expect(doesAppBuildGradleIncludeRNSentryGradlePlugin('')).toBe(false);\n });\n\n it('returns false for minimal app/build.gradle', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(false);\n });\n\n it('returns false for app/build.gradle with SAGP', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(false);\n });\n\n it('returns true for app/build.gradle with RN SAGP', () => {\n const appBuildGradle = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),\n ).toBe(true);\n });\n });\n\n describe('addRNSentryGradlePlugin', () => {\n it('does not add nothing to empty file', () => {\n expect(addRNSentryGradlePlugin('')).toBe('');\n });\n\n it('does add RN SAGP', () => {\n const input = `apply plugin: \"com.android.application\"\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const expectedOutput = `apply plugin: \"com.android.application\"\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);\n });\n\n it('does add RN SAGP to build gradle with SAGP', () => {\n const input = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n const expectedOutput = `apply plugin: \"com.android.application\"\napply plugin: \"io.sentry.android.gradle\"\n\nsentry {\n}\n\napply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")\nandroid {\n ndkVersion rootProject.ext.ndkVersion\n\n compileSdkVersion rootProject.ext.compileSdkVersion\n\n namespace \"com.samplenewarchitecture\"\n defaultConfig {\n applicationId \"com.samplenewarchitecture\"\n minSdkVersion rootProject.ext.minSdkVersion\n targetSdkVersion rootProject.ext.targetSdkVersion\n versionCode 1\n versionName \"1.0\"\n }\n}\n`;\n expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);\n });\n });\n});\n"]}
|
|
@@ -330,96 +330,6 @@ module.exports = {
|
|
|
330
330
|
.value.value).toBe('config');
|
|
331
331
|
});
|
|
332
332
|
});
|
|
333
|
-
(0, vitest_1.describe)('remove @sentry require', () => {
|
|
334
|
-
(0, vitest_1.it)('nothing to remove', () => {
|
|
335
|
-
const mod = (0, magicast_1.parseModule)(`let config = { some: 'config' };`);
|
|
336
|
-
const result = (0, metro_1.removeSentryRequire)(mod.$ast);
|
|
337
|
-
(0, vitest_1.expect)(result).toBe(false);
|
|
338
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = { some: 'config' };`);
|
|
339
|
-
});
|
|
340
|
-
(0, vitest_1.it)('remove metro serializer import', () => {
|
|
341
|
-
const mod = (0, magicast_1.parseModule)(`const {
|
|
342
|
-
createSentryMetroSerializer,
|
|
343
|
-
} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
|
|
344
|
-
let config = { some: 'config' };`);
|
|
345
|
-
const result = (0, metro_1.removeSentryRequire)(mod.$ast);
|
|
346
|
-
(0, vitest_1.expect)(result).toBe(true);
|
|
347
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = { some: 'config' };`);
|
|
348
|
-
});
|
|
349
|
-
(0, vitest_1.it)('remove all sentry imports', () => {
|
|
350
|
-
const mod = (0, magicast_1.parseModule)(`const {
|
|
351
|
-
createSentryMetroSerializer,
|
|
352
|
-
} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
|
|
353
|
-
var Sentry = require('@sentry/react-native');
|
|
354
|
-
let SentryIntegrations = require('@sentry/integrations');
|
|
355
|
-
|
|
356
|
-
let config = { some: 'config' };`);
|
|
357
|
-
const result = (0, metro_1.removeSentryRequire)(mod.$ast);
|
|
358
|
-
(0, vitest_1.expect)(result).toBe(true);
|
|
359
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = { some: 'config' };`);
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
(0, vitest_1.describe)('remove sentryMetroSerializer', () => {
|
|
363
|
-
(0, vitest_1.it)('no custom serializer to remove', () => {
|
|
364
|
-
const mod = (0, magicast_1.parseModule)(`let config = { some: 'config' };`);
|
|
365
|
-
const result = (0, metro_1.removeSentrySerializerFromMetroConfig)(mod.$ast);
|
|
366
|
-
(0, vitest_1.expect)(result).toBe(false);
|
|
367
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = { some: 'config' };`);
|
|
368
|
-
});
|
|
369
|
-
(0, vitest_1.it)('no Sentry custom serializer to remove', () => {
|
|
370
|
-
const mod = (0, magicast_1.parseModule)(`let config = {
|
|
371
|
-
serializer: {
|
|
372
|
-
customSerializer: 'existing-serializer',
|
|
373
|
-
other: 'config',
|
|
374
|
-
},
|
|
375
|
-
other: 'config',
|
|
376
|
-
};`);
|
|
377
|
-
const result = (0, metro_1.removeSentrySerializerFromMetroConfig)(mod.$ast);
|
|
378
|
-
(0, vitest_1.expect)(result).toBe(false);
|
|
379
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = {
|
|
380
|
-
serializer: {
|
|
381
|
-
customSerializer: 'existing-serializer',
|
|
382
|
-
other: 'config',
|
|
383
|
-
},
|
|
384
|
-
other: 'config',
|
|
385
|
-
};`);
|
|
386
|
-
});
|
|
387
|
-
(0, vitest_1.it)('Sentry serializer to remove', () => {
|
|
388
|
-
const mod = (0, magicast_1.parseModule)(`let config = {
|
|
389
|
-
serializer: {
|
|
390
|
-
customSerializer: createSentryMetroSerializer(),
|
|
391
|
-
other: 'config',
|
|
392
|
-
},
|
|
393
|
-
other: 'config',
|
|
394
|
-
};`);
|
|
395
|
-
const result = (0, metro_1.removeSentrySerializerFromMetroConfig)(mod.$ast);
|
|
396
|
-
(0, vitest_1.expect)(result).toBe(true);
|
|
397
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = {
|
|
398
|
-
serializer: {
|
|
399
|
-
other: 'config'
|
|
400
|
-
},
|
|
401
|
-
other: 'config',
|
|
402
|
-
};`);
|
|
403
|
-
});
|
|
404
|
-
(0, vitest_1.it)('Sentry serializer to remove with wrapped serializer', () => {
|
|
405
|
-
const mod = (0, magicast_1.parseModule)(`let config = {
|
|
406
|
-
serializer: {
|
|
407
|
-
customSerializer: createSentryMetroSerializer(wrappedSerializer()),
|
|
408
|
-
other: 'config',
|
|
409
|
-
},
|
|
410
|
-
other: 'config',
|
|
411
|
-
};`);
|
|
412
|
-
const result = (0, metro_1.removeSentrySerializerFromMetroConfig)(mod.$ast);
|
|
413
|
-
(0, vitest_1.expect)(result).toBe(true);
|
|
414
|
-
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`let config = {
|
|
415
|
-
serializer: {
|
|
416
|
-
customSerializer: wrappedSerializer(),
|
|
417
|
-
other: 'config',
|
|
418
|
-
},
|
|
419
|
-
other: 'config',
|
|
420
|
-
};`);
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
333
|
});
|
|
424
334
|
function getModuleExportsObject(mod, index = 0) {
|
|
425
335
|
return mod.$ast.body[index]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C,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAC7B,GAAoB,EACpB,KAAK,GAAG,CAAC;IAET,OACI,GAAG,CAAC,IAAkB,CAAC,IAAI,CAAC,KAAK,CAA2B;SAC3D,UACJ,CAAC,KAA2B,CAAC;AAChC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, type ProxifiedModule, parseModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport {\n addSentrySerializerRequireToMetroConfig,\n addSentrySerializerToMetroConfig,\n getMetroConfigObject,\n patchMetroWithSentryConfigInMemory,\n removeSentryRequire,\n removeSentrySerializerFromMetroConfig,\n} from '../../src/react-native/metro';\nimport { describe, expect, it } from 'vitest';\n\ndescribe('patch metro config - sentry serializer', () => {\n describe('patchMetroWithSentryConfigInMemory', () => {\n it('patches react native 0.72 default metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('patches react native 0.65 default metro config', async () => {\n const mod = parseModule(`/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = {\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n};`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = withSentryConfig({\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n});`);\n });\n\n it('patches react native metro config exported variable', async () => {\n const mod = parseModule(`const testConfig = {};\n\nmodule.exports = testConfig;`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst testConfig = {};\n\nmodule.exports = withSentryConfig(testConfig);`);\n });\n\n it('patches custom react native metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('does not patch react native metro config exported as factory function', async () => {\n const mod = parseModule(`module.exports = () => ({});`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = () => ({});`);\n });\n });\n\n describe('addSentrySerializerToMetroConfig', () => {\n it('add to empty config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config'\n }`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n\n serializer: {\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('add to existing serializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('not add to existing customSerializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n });\n });\n\n describe('addSentrySerializerImportToMetroConfig', () => {\n it('add import', () => {\n const mod =\n parseModule(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nmodule.exports = {\n other: 'config'\n}`);\n const result = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nconst {\n createSentryMetroSerializer\n} = require(\"@sentry/react-native/dist/js/tools/sentryMetroSerializer\");\n\nmodule.exports = {\n other: 'config'\n}`);\n });\n });\n\n describe('getMetroConfigObject', () => {\n it('get config object from variable called config', () => {\n const mod = parseModule(`var config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from const called config', () => {\n const mod = parseModule(`const config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config oject from let called config', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from module.exports', () => {\n const mod = parseModule(`module.exports = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n });\n\n describe('remove @sentry require', () => {\n it('nothing to remove', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const result = removeSentryRequire(mod.$ast as t.Program);\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(\n `let config = { some: 'config' };`,\n );\n });\n\n it('remove metro serializer import', () => {\n const mod = parseModule(`const {\n createSentryMetroSerializer,\n} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\nlet config = { some: 'config' };`);\n const result = removeSentryRequire(mod.$ast as t.Program);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(\n `let config = { some: 'config' };`,\n );\n });\n\n it('remove all sentry imports', () => {\n const mod = parseModule(`const {\n createSentryMetroSerializer,\n} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\nvar Sentry = require('@sentry/react-native');\nlet SentryIntegrations = require('@sentry/integrations');\n\nlet config = { some: 'config' };`);\n const result = removeSentryRequire(mod.$ast as t.Program);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(\n `let config = { some: 'config' };`,\n );\n });\n });\n\n describe('remove sentryMetroSerializer', () => {\n it('no custom serializer to remove', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const result = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(\n `let config = { some: 'config' };`,\n );\n });\n\n it('no Sentry custom serializer to remove', () => {\n const mod = parseModule(`let config = {\n serializer: {\n customSerializer: 'existing-serializer',\n other: 'config',\n },\n other: 'config',\n};`);\n const result = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`let config = {\n serializer: {\n customSerializer: 'existing-serializer',\n other: 'config',\n },\n other: 'config',\n};`);\n });\n\n it('Sentry serializer to remove', () => {\n const mod = parseModule(`let config = {\n serializer: {\n customSerializer: createSentryMetroSerializer(),\n other: 'config',\n },\n other: 'config',\n};`);\n const result = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`let config = {\n serializer: {\n other: 'config'\n },\n other: 'config',\n};`);\n });\n\n it('Sentry serializer to remove with wrapped serializer', () => {\n const mod = parseModule(`let config = {\n serializer: {\n customSerializer: createSentryMetroSerializer(wrappedSerializer()),\n other: 'config',\n },\n other: 'config',\n};`);\n const result = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`let config = {\n serializer: {\n customSerializer: wrappedSerializer(),\n other: 'config',\n },\n other: 'config',\n};`);\n });\n });\n});\n\nfunction getModuleExportsObject(\n mod: ProxifiedModule,\n index = 0,\n): t.ObjectExpression {\n return (\n ((mod.$ast as t.Program).body[index] as t.ExpressionStatement)\n .expression as t.AssignmentExpression\n ).right as t.ObjectExpression;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"metro.test.js","sourceRoot":"","sources":["../../../test/react-native/metro.test.ts"],"names":[],"mappings":";;AAAA,kFAAkF;AAClF,uCAA2E;AAM3E,wDAKsC;AACtC,mCAA8C;AAE9C,IAAA,iBAAQ,EAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,IAAA,iBAAQ,EAAC,oCAAoC,EAAE,GAAG,EAAE;QAClD,IAAA,WAAE,EAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,GAAG,GACP,IAAA,sBAAW,EAAC;;;;;;;;;;mEAU+C,CAAC,CAAC;YAE/D,MAAM,MAAM,GAAG,MAAM,IAAA,0CAAkC,EAAC,GAAG,EAAE,KAAK,IAAI,EAAE;gBACtE,UAAU;YACZ,CAAC,CAAC,CAAC;YACH,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,IAAA,eAAM,EAAC,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;iBAChC,IAAI,CAAC;;;;;;;;;;;;;;qFAcuE,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC;;;;;;;;;;;;;;;;GAgB3B,CAAC,CAAC;YAEC,MAAM,MAAM,GAAG,MAAM,IAAA,0CAAkC,EAAC,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AAC,kCAAkC,CAAC,CAAC;YAC5D,MAAM,YAAY,GAAG,IAAA,4BAAoB,EAAC,GAAG,CAAC,IAAiB,CAAC,CAAC;YACjE,IAAA,eAAM,EACH,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA,CAAC,GAAoB;iBACpE,IAAI,CACR,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,IAAA,eAAM,EAEF,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA;iBAC9C,KACJ,CAAC,KAAK,CACR,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC,sCAAsC,CAAC,CAAC;YAChE,MAAM,YAAY,GAAG,IAAA,4BAAoB,EAAC,GAAG,CAAC,IAAiB,CAAC,CAAC;YACjE,IAAA,eAAM,EACH,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA,CAAC,GAAoB;iBACpE,IAAI,CACR,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,IAAA,eAAM,EAEF,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA;iBAC9C,KACJ,CAAC,KAAK,CACR,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAC7B,GAAoB,EACpB,KAAK,GAAG,CAAC;IAET,OACI,GAAG,CAAC,IAAkB,CAAC,IAAI,CAAC,KAAK,CAA2B;SAC3D,UACJ,CAAC,KAA2B,CAAC;AAChC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, type ProxifiedModule, parseModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport {\n addSentrySerializerRequireToMetroConfig,\n addSentrySerializerToMetroConfig,\n getMetroConfigObject,\n patchMetroWithSentryConfigInMemory,\n} from '../../src/react-native/metro';\nimport { describe, expect, it } from 'vitest';\n\ndescribe('patch metro config - sentry serializer', () => {\n describe('patchMetroWithSentryConfigInMemory', () => {\n it('patches react native 0.72 default metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('patches react native 0.65 default metro config', async () => {\n const mod = parseModule(`/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = {\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n};`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = withSentryConfig({\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n});`);\n });\n\n it('patches react native metro config exported variable', async () => {\n const mod = parseModule(`const testConfig = {};\n\nmodule.exports = testConfig;`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst testConfig = {};\n\nmodule.exports = withSentryConfig(testConfig);`);\n });\n\n it('patches custom react native metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('does not patch react native metro config exported as factory function', async () => {\n const mod = parseModule(`module.exports = () => ({});`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = () => ({});`);\n });\n });\n\n describe('addSentrySerializerToMetroConfig', () => {\n it('add to empty config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config'\n }`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n\n serializer: {\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('add to existing serializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('not add to existing customSerializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n });\n });\n\n describe('addSentrySerializerImportToMetroConfig', () => {\n it('add import', () => {\n const mod =\n parseModule(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nmodule.exports = {\n other: 'config'\n}`);\n const result = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nconst {\n createSentryMetroSerializer\n} = require(\"@sentry/react-native/dist/js/tools/sentryMetroSerializer\");\n\nmodule.exports = {\n other: 'config'\n}`);\n });\n });\n\n describe('getMetroConfigObject', () => {\n it('get config object from variable called config', () => {\n const mod = parseModule(`var config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from const called config', () => {\n const mod = parseModule(`const config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config oject from let called config', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from module.exports', () => {\n const mod = parseModule(`module.exports = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n });\n});\n\nfunction getModuleExportsObject(\n mod: ProxifiedModule,\n index = 0,\n): t.ObjectExpression {\n return (\n ((mod.$ast as t.Program).body[index] as t.ExpressionStatement)\n .expression as t.AssignmentExpression\n ).right as t.ObjectExpression;\n}\n"]}
|