@sentry/wizard 6.11.0 → 6.13.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 +64 -0
- package/dist/bin.js +16 -1
- package/dist/bin.js.map +1 -1
- package/dist/e2e-tests/tests/angular-17.test.js +3 -4
- package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
- package/dist/e2e-tests/tests/angular-19.test.js +3 -4
- package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
- package/dist/e2e-tests/tests/cloudflare-worker.test.js +5 -0
- package/dist/e2e-tests/tests/cloudflare-worker.test.js.map +1 -1
- package/dist/e2e-tests/tests/flutter.test.js +60 -0
- package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
- package/dist/e2e-tests/tests/help-message.test.js +8 -3
- package/dist/e2e-tests/tests/help-message.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-3.test.js +12 -6
- package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-4.test.js +12 -6
- package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
- package/dist/e2e-tests/tests/pnpm-workspace.test.js +8 -4
- package/dist/e2e-tests/tests/pnpm-workspace.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js +96 -0
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js.map +1 -0
- package/dist/e2e-tests/tests/react-router.test.js +6 -7
- package/dist/e2e-tests/tests/react-router.test.js.map +1 -1
- package/dist/e2e-tests/tests/remix.test.js +2 -4
- package/dist/e2e-tests/tests/remix.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit-hooks.test.js +24 -8
- package/dist/e2e-tests/tests/sveltekit-hooks.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js +8 -4
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js.map +1 -1
- package/dist/lib/Constants.d.ts +1 -0
- package/dist/lib/Constants.js +5 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/lib/Steps/Integrations/Electron.js +2 -2
- package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
- package/dist/src/android/android-wizard.js +3 -0
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/angular/codemods/main.d.ts +1 -1
- package/dist/src/angular/codemods/main.js +0 -1
- package/dist/src/angular/codemods/main.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +2 -3
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/apple/check-installed-cli.d.ts +1 -1
- package/dist/src/apple/check-installed-cli.js +13 -7
- package/dist/src/apple/check-installed-cli.js.map +1 -1
- package/dist/src/apple/code-tools.js +17 -3
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/configure-package-manager.js +18 -5
- package/dist/src/apple/configure-package-manager.js.map +1 -1
- package/dist/src/apple/configure-xcode-project.js +8 -1
- package/dist/src/apple/configure-xcode-project.js.map +1 -1
- package/dist/src/apple/lookup-xcode-project.d.ts +8 -5
- package/dist/src/apple/lookup-xcode-project.js +22 -17
- package/dist/src/apple/lookup-xcode-project.js.map +1 -1
- package/dist/src/apple/options.d.ts +5 -0
- package/dist/src/apple/options.js.map +1 -1
- package/dist/src/apple/sentry-swift-package.d.ts +4 -0
- package/dist/src/apple/sentry-swift-package.js +17 -0
- package/dist/src/apple/sentry-swift-package.js.map +1 -0
- package/dist/src/apple/snapshots/apple-snapshots-wizard.d.ts +2 -0
- package/dist/src/apple/snapshots/apple-snapshots-wizard.js +251 -0
- package/dist/src/apple/snapshots/apple-snapshots-wizard.js.map +1 -0
- package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.d.ts +13 -0
- package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.js +48 -0
- package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.js.map +1 -0
- package/dist/src/apple/snapshots/snapshot-test-file.d.ts +18 -0
- package/dist/src/apple/snapshots/snapshot-test-file.js +122 -0
- package/dist/src/apple/snapshots/snapshot-test-file.js.map +1 -0
- package/dist/src/apple/snapshots/snapshot-verification-scheme.d.ts +6 -0
- package/dist/src/apple/snapshots/snapshot-verification-scheme.js +147 -0
- package/dist/src/apple/snapshots/snapshot-verification-scheme.js.map +1 -0
- package/dist/src/apple/snapshots/snapshotpreviews-package.d.ts +4 -0
- package/dist/src/apple/snapshots/snapshotpreviews-package.js +8 -0
- package/dist/src/apple/snapshots/snapshotpreviews-package.js.map +1 -0
- package/dist/src/apple/snapshots/snapshots-cli-preflight.d.ts +23 -0
- package/dist/src/apple/snapshots/snapshots-cli-preflight.js +136 -0
- package/dist/src/apple/snapshots/snapshots-cli-preflight.js.map +1 -0
- package/dist/src/apple/xcode-manager.d.ts +59 -1
- package/dist/src/apple/xcode-manager.js +507 -106
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/cloudflare/cloudflare-wizard.js +5 -0
- package/dist/src/cloudflare/cloudflare-wizard.js.map +1 -1
- package/dist/src/cloudflare/sdk-setup.d.ts +1 -0
- package/dist/src/cloudflare/sdk-setup.js.map +1 -1
- package/dist/src/cloudflare/templates.d.ts +1 -0
- package/dist/src/cloudflare/templates.js +7 -1
- package/dist/src/cloudflare/templates.js.map +1 -1
- package/dist/src/cloudflare/wrap-worker.d.ts +1 -0
- package/dist/src/cloudflare/wrap-worker.js +7 -0
- package/dist/src/cloudflare/wrap-worker.js.map +1 -1
- package/dist/src/flutter/flutter-wizard.js +3 -0
- package/dist/src/flutter/flutter-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.js +12 -6
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nuxt/templates.js +12 -6
- package/dist/src/nuxt/templates.js.map +1 -1
- package/dist/src/react-native/expo.d.ts +6 -0
- package/dist/src/react-native/expo.js +27 -1
- package/dist/src/react-native/expo.js.map +1 -1
- package/dist/src/react-native/git.d.ts +5 -0
- package/dist/src/react-native/git.js +32 -1
- package/dist/src/react-native/git.js.map +1 -1
- package/dist/src/react-native/javascript.js +3 -1
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +12 -6
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-router/codemods/client.entry.d.ts +1 -1
- package/dist/src/react-router/codemods/client.entry.js +124 -26
- package/dist/src/react-router/codemods/client.entry.js.map +1 -1
- package/dist/src/react-router/codemods/react-router-config.js +1 -1
- package/dist/src/react-router/codemods/react-router-config.js.map +1 -1
- package/dist/src/react-router/codemods/server-entry.d.ts +1 -1
- package/dist/src/react-router/codemods/server-entry.js +40 -4
- package/dist/src/react-router/codemods/server-entry.js.map +1 -1
- package/dist/src/react-router/codemods/vite.js +46 -1
- package/dist/src/react-router/codemods/vite.js.map +1 -1
- package/dist/src/react-router/react-router-wizard.js +62 -21
- package/dist/src/react-router/react-router-wizard.js.map +1 -1
- package/dist/src/react-router/sdk-setup.d.ts +5 -3
- package/dist/src/react-router/sdk-setup.js +44 -16
- package/dist/src/react-router/sdk-setup.js.map +1 -1
- package/dist/src/react-router/templates.d.ts +2 -4
- package/dist/src/react-router/templates.js +89 -87
- package/dist/src/react-router/templates.js.map +1 -1
- package/dist/src/remix/sdk-setup.js +1 -2
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/run.d.ts +4 -1
- package/dist/src/run.js +13 -0
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/tools/remix.js +4 -4
- package/dist/src/sourcemaps/tools/remix.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +1 -1
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup/setup.js +17 -4
- package/dist/src/sveltekit/sdk-setup/setup.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js.map +1 -1
- package/dist/src/sveltekit/templates.js +12 -6
- package/dist/src/sveltekit/templates.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +10 -0
- package/dist/src/utils/ast-utils.js +19 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack/index.d.ts +2 -1
- package/dist/src/utils/clack/index.js +17 -6
- package/dist/src/utils/clack/index.js.map +1 -1
- package/dist/src/utils/files.d.ts +2 -0
- package/dist/src/utils/files.js +58 -0
- package/dist/src/utils/files.js.map +1 -0
- package/dist/src/utils/git.d.ts +3 -1
- package/dist/src/utils/git.js +2 -1
- package/dist/src/utils/git.js.map +1 -1
- package/dist/src/utils/line-endings.d.ts +1 -0
- package/dist/src/utils/line-endings.js +76 -0
- package/dist/src/utils/line-endings.js.map +1 -0
- 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/angular/angular-wizard.test.js +0 -5
- package/dist/test/angular/angular-wizard.test.js.map +1 -1
- package/dist/test/apple/code-tools.test.js +78 -0
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/configure-package-manager.test.d.ts +1 -0
- package/dist/test/apple/configure-package-manager.test.js +161 -0
- package/dist/test/apple/configure-package-manager.test.js.map +1 -0
- package/dist/test/apple/lookup-xcode-project.test.d.ts +1 -0
- package/dist/test/apple/lookup-xcode-project.test.js +167 -0
- package/dist/test/apple/lookup-xcode-project.test.js.map +1 -0
- package/dist/test/apple/snapshots/apple-snapshots-wizard.test.d.ts +1 -0
- package/dist/test/apple/snapshots/apple-snapshots-wizard.test.js +487 -0
- package/dist/test/apple/snapshots/apple-snapshots-wizard.test.js.map +1 -0
- package/dist/test/apple/snapshots/hosted-test-target-fixture.d.ts +24 -0
- package/dist/test/apple/snapshots/hosted-test-target-fixture.js +191 -0
- package/dist/test/apple/snapshots/hosted-test-target-fixture.js.map +1 -0
- package/dist/test/apple/snapshots/snapshot-test-file.test.d.ts +1 -0
- package/dist/test/apple/snapshots/snapshot-test-file.test.js +110 -0
- package/dist/test/apple/snapshots/snapshot-test-file.test.js.map +1 -0
- package/dist/test/apple/snapshots/snapshot-verification-scheme.test.d.ts +1 -0
- package/dist/test/apple/snapshots/snapshot-verification-scheme.test.js +146 -0
- package/dist/test/apple/snapshots/snapshot-verification-scheme.test.js.map +1 -0
- package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.d.ts +1 -0
- package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.js +186 -0
- package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.js.map +1 -0
- package/dist/test/apple/snapshots/snapshots-cli-preflight.test.d.ts +1 -0
- package/dist/test/apple/snapshots/snapshots-cli-preflight.test.js +192 -0
- package/dist/test/apple/snapshots/snapshots-cli-preflight.test.js.map +1 -0
- package/dist/test/apple/snapshots/source-file-insertion.test.d.ts +1 -0
- package/dist/test/apple/snapshots/source-file-insertion.test.js +77 -0
- package/dist/test/apple/snapshots/source-file-insertion.test.js.map +1 -0
- package/dist/test/apple/xcode-manager.test.js +452 -43
- package/dist/test/apple/xcode-manager.test.js.map +1 -1
- package/dist/test/cloudflare/sdk-setup.test.js +20 -2
- package/dist/test/cloudflare/sdk-setup.test.js.map +1 -1
- package/dist/test/cloudflare/templates.test.js +54 -0
- package/dist/test/cloudflare/templates.test.js.map +1 -1
- package/dist/test/cloudflare/wrap-worker.test.js +74 -11
- package/dist/test/cloudflare/wrap-worker.test.js.map +1 -1
- package/dist/test/constants.test.d.ts +1 -0
- package/dist/test/constants.test.js +12 -0
- package/dist/test/constants.test.js.map +1 -0
- package/dist/test/nextjs/templates.test.js +66 -33
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/nuxt/templates.test.js +66 -36
- package/dist/test/nuxt/templates.test.js.map +1 -1
- package/dist/test/react-native/expo.test.js +140 -0
- package/dist/test/react-native/expo.test.js.map +1 -1
- package/dist/test/react-native/git.test.d.ts +1 -0
- package/dist/test/react-native/git.test.js +160 -0
- package/dist/test/react-native/git.test.js.map +1 -0
- package/dist/test/react-router/codemods/client-entry.test.js +38 -5
- package/dist/test/react-router/codemods/client-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/server-entry.test.js +83 -0
- package/dist/test/react-router/codemods/server-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/vite.test.js +89 -0
- package/dist/test/react-router/codemods/vite.test.js.map +1 -1
- package/dist/test/react-router/sdk-setup.test.js +98 -6
- package/dist/test/react-router/sdk-setup.test.js.map +1 -1
- package/dist/test/react-router/templates.test.js +50 -38
- package/dist/test/react-router/templates.test.js.map +1 -1
- package/dist/test/remix/build-script.test.d.ts +1 -0
- package/dist/test/remix/build-script.test.js +124 -0
- package/dist/test/remix/build-script.test.js.map +1 -0
- package/dist/test/remix/client-entry.test.js +4 -10
- package/dist/test/remix/client-entry.test.js.map +1 -1
- package/dist/test/run.test.d.ts +1 -0
- package/dist/test/run.test.js +137 -0
- package/dist/test/run.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/vite.test.js +12 -8
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
- package/dist/test/sveltekit/templates.test.js +78 -27
- package/dist/test/sveltekit/templates.test.js.map +1 -1
- package/dist/test/utils/ast-utils.test.js +22 -0
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/dist/test/utils/clack/index.test.js +101 -0
- package/dist/test/utils/clack/index.test.js.map +1 -1
- package/dist/test/utils/git.test.js +10 -0
- package/dist/test/utils/git.test.js.map +1 -1
- package/dist/test/utils/line-endings.test.d.ts +1 -0
- package/dist/test/utils/line-endings.test.js +103 -0
- package/dist/test/utils/line-endings.test.js.map +1 -0
- package/package.json +2 -2
- package/dist/src/react-router/codemods/root.d.ts +0 -1
- package/dist/src/react-router/codemods/root.js +0 -171
- package/dist/src/react-router/codemods/root.js.map +0 -1
- package/dist/test/react-router/codemods/root.test.js +0 -178
- package/dist/test/react-router/codemods/root.test.js.map +0 -1
- /package/dist/{test/react-router/codemods/root.test.d.ts → e2e-tests/tests/react-router-instrumentation-api.test.d.ts} +0 -0
|
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AA,eAAM,EAAC,MAAM,CAAC,CAAC,SAAS,CACtB,wEAAwE,CACzE,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,MAAM,GAAG,IAAA,sCAA0B,EAAC;YACxC,UAAU,EAAE,KAAK;YACjB,GAAG,EAAE,mBAAmB;YACxB,OAAO,EAAE,UAAU;YACnB,SAAS,EAAE,cAAc;YACzB,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;QAEH,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,SAAS,CACtB,yDAAyD,CAC1D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAA,iBAAQ,EAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAA,WAAE,EAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG,IAAA,oCAAwB,GAAE,CAAC;QAC1C,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport {\n getClientHooksTemplate,\n getInstrumentationServerTemplate,\n getSentryExampleApiRoute,\n getSentryExampleSveltePage,\n getServerHooksTemplate,\n} from '../../src/sveltekit/templates';\nimport { insertClientInitCall } from '../../src/sveltekit/sdk-setup/setup';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule } from 'magicast';\n\nvi.mock('../../src/utils/clack/mcp-config', () => ({\n offerProjectScopedMcpConfig: vi.fn().mockResolvedValue(undefined),\n}));\n\ndescribe('getClientHooksTemplate', () => {\n it('generates client hooks template with all features enabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: true,\n replay: true,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\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 // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // If you don't want to use Session Replay, just remove the line below:\n integrations: [replayIntegration()],\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template when performance disabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: false,\n replay: true,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\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 // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // If you don't want to use Session Replay, just remove the line below:\n integrations: [replayIntegration()],\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template when replay disabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: true,\n replay: false,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n\n\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template with only logs enabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: false,\n replay: false,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n});\n\ndescribe('getServerHooksTemplate', () => {\n it('generates server hooks template with all features enabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template when performance disabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: true,\n logs: false,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template with only logs enabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n // Enable sending user PII (Personally Identifiable Information)\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii\n sendDefaultPii: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template without Sentry.init if includeSentryInit is false', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n false,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n});\n\ndescribe('getInstrumentationServerTemplate', () => {\n it('generates instrumentation.server template with all features enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: true,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template with only logs enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: false,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template with only tracesSampleRate enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: true,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template without any extra features enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: false,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n});\n\ndescribe('insertClientInitCall', () => {\n it('should insert client init call with all features enabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/123', originalHooksMod, {\n performance: true,\n replay: true,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/123\",\n tracesSampleRate: 1,\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1,\n integrations: [Sentry.replayIntegration()],\n enableLogs: true,\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with performance disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/456', originalHooksMod, {\n performance: false,\n replay: true,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/456\",\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1,\n integrations: [Sentry.replayIntegration()],\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with replay disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/789', originalHooksMod, {\n performance: true,\n replay: false,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/789\",\n tracesSampleRate: 1,\n enableLogs: true,\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with only logs enabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/xyz', originalHooksMod, {\n performance: false,\n replay: false,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/xyz\",\n enableLogs: true,\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with all features disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/minimal', originalHooksMod, {\n performance: false,\n replay: false,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/minimal\",\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert init call after imports', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import { somethingElse } from \"some-package\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n export const someOtherExport = somethingElse();\n `);\n\n insertClientInitCall('https://sentry.io/order-test', originalHooksMod, {\n performance: true,\n replay: false,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import { somethingElse } from \"some-package\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/order-test\",\n tracesSampleRate: 1,\n sendDefaultPii: true\n })\n\n export const handleError = handleErrorWithSentry();\n export const someOtherExport = somethingElse();\"\n `);\n });\n});\n\ndescribe('getSentryExampleSveltePage', () => {\n it('generates example page template with Svelte 5', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"<!--\n This is just a very simple page with a button to throw an example error.\n Feel free to delete this file and the entire sentry route.\n -->\n\n <script>\n import * as Sentry from '@sentry/sveltekit';\n import { onMount } from 'svelte';\n \n let hasSentError = $state(false);\n let isConnected = true;\n\n onMount(async () => {\n const result = await Sentry.diagnoseSdkConnectivity();\n isConnected = result !== 'sentry-unreachable';\n });\n\n function getSentryData() {\n Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test'\n },\n async () => {\n const res = await fetch('/sentry-example-page');\n if (!res.ok) {\n hasSentError = true;\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }\n </script>\n\n <title>sentry-example-page</title>\n\n <div>\n <main>\n <div class=\"flex-spacer\"></div>\n <svg height=\"40\" width=\"40\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z\" fill=\"currentcolor\"/>\n </svg>\n <h1>\n sentry-example-page\n </h1>\n\n <p class=\"description\">\n Click the button below, and view the sample error on the Sentry <a target=\"_blank\" href=\"https://test-org.sentry.io/issues/?project=test-project\">Issues Page</a>. \n For more details about setting up Sentry, <a target=\"_blank\" href=\"https://docs.sentry.io/platforms/javascript/guides/sveltekit/\">read our docs</a>.\n </p>\n\n <button\n type=\"button\"\n onclick={getSentryData}\n disabled={!isConnected}\n >\n <span>\n Throw Sample Error\n </span>\n </button>\n\n {#if hasSentError}\n <p class=\"success\">\n Sample error was sent to Sentry.\n </p>\n {:else if !isConnected}\n <div class=\"connectivity-error\">\n <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>\n </div>\n {:else}\n <div class=\"success_placeholder\"></div>\n {/if}\n <div class=\"flex-spacer\"></div>\n </main>\n </div>\n\n <style>\n :global(body) {\n margin: 0;\n\n @media (prefers-color-scheme: dark) {\n color: #ededed;\n background-color: #0a0a0a;\n }\n }\n\n main {\n display: flex;\n min-height: 100vh;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n box-sizing: border-box;\n gap: 16px;\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n }\n\n h1 {\n padding: 0px 4px;\n border-radius: 4px;\n background-color: rgba(24, 20, 35, 0.03);\n font-family: monospace;\n font-size: 20px;\n line-height: 1.2;\n }\n\n p {\n margin: 0;\n font-size: 20px;\n }\n\n a {\n color: #6341F0;\n text-decoration: underline;\n cursor: pointer;\n\n @media (prefers-color-scheme: dark) {\n color: #B3A1FF;\n }\n }\n\n button {\n border-radius: 8px;\n color: white;\n cursor: pointer;\n background-color: #553DB8;\n border: none;\n padding: 0;\n margin-top: 4px;\n\n & > span {\n display: inline-block;\n padding: 12px 16px;\n border-radius: inherit;\n font-size: 20px;\n font-weight: bold;\n line-height: 1;\n background-color: #7553FF;\n border: 1px solid #553DB8;\n transform: translateY(-4px);\n }\n\n &:hover > span {\n transform: translateY(-8px);\n }\n\n &:active > span {\n transform: translateY(0);\n }\n\n &:disabled {\n cursor: not-allowed;\n opacity: 0.6;\n\n & > span {\n transform: translateY(0);\n border: none;\n }\n }\n }\n\n .description {\n text-align: center;\n color: #6E6C75;\n max-width: 500px;\n line-height: 1.5;\n font-size: 20px;\n\n @media (prefers-color-scheme: dark) {\n color: #A49FB5;\n }\n }\n\n .flex-spacer {\n flex: 1;\n }\n\n .success {\n padding: 12px 16px;\n border-radius: 8px;\n font-size: 20px;\n line-height: 1;\n background-color: #00F261;\n border: 1px solid #00BF4D;\n color: #181423;\n }\n\n .success_placeholder {\n height: 46px;\n }\n\n .connectivity-error {\n padding: 12px 16px;\n background-color: #E50045;\n border-radius: 8px;\n width: 500px;\n color: #FFFFFF;\n border: 1px solid #A80033;\n text-align: center;\n margin: 0;\n }\n \n .connectivity-error a {\n color: #FFFFFF;\n text-decoration: underline;\n }\n </style>\n \"\n `);\n });\n\n it('generates example page template pre-Svelte 5', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"<!--\n This is just a very simple page with a button to throw an example error.\n Feel free to delete this file and the entire sentry route.\n -->\n\n <script>\n import * as Sentry from '@sentry/sveltekit';\n import { onMount } from 'svelte';\n \n let hasSentError = false;\n let isConnected = true;\n\n onMount(async () => {\n const result = await Sentry.diagnoseSdkConnectivity();\n isConnected = result !== 'sentry-unreachable';\n });\n\n function getSentryData() {\n Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test'\n },\n async () => {\n const res = await fetch('/sentry-example-page');\n if (!res.ok) {\n hasSentError = true;\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }\n </script>\n\n <title>sentry-example-page</title>\n\n <div>\n <main>\n <div class=\"flex-spacer\"></div>\n <svg height=\"40\" width=\"40\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z\" fill=\"currentcolor\"/>\n </svg>\n <h1>\n sentry-example-page\n </h1>\n\n <p class=\"description\">\n Click the button below, and view the sample error on the Sentry <a target=\"_blank\" href=\"https://test-org.sentry.io/issues/?project=test-project\">Issues Page</a>. \n For more details about setting up Sentry, <a target=\"_blank\" href=\"https://docs.sentry.io/platforms/javascript/guides/sveltekit/\">read our docs</a>.\n </p>\n\n <button\n type=\"button\"\n on:click={getSentryData}\n disabled={!isConnected}\n >\n <span>\n Throw Sample Error\n </span>\n </button>\n\n {#if hasSentError}\n <p class=\"success\">\n Sample error was sent to Sentry.\n </p>\n {:else if !isConnected}\n <div class=\"connectivity-error\">\n <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>\n </div>\n {:else}\n <div class=\"success_placeholder\"></div>\n {/if}\n <div class=\"flex-spacer\"></div>\n </main>\n </div>\n\n <style>\n :global(body) {\n margin: 0;\n\n @media (prefers-color-scheme: dark) {\n color: #ededed;\n background-color: #0a0a0a;\n }\n }\n\n main {\n display: flex;\n min-height: 100vh;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n box-sizing: border-box;\n gap: 16px;\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n }\n\n h1 {\n padding: 0px 4px;\n border-radius: 4px;\n background-color: rgba(24, 20, 35, 0.03);\n font-family: monospace;\n font-size: 20px;\n line-height: 1.2;\n }\n\n p {\n margin: 0;\n font-size: 20px;\n }\n\n a {\n color: #6341F0;\n text-decoration: underline;\n cursor: pointer;\n\n @media (prefers-color-scheme: dark) {\n color: #B3A1FF;\n }\n }\n\n button {\n border-radius: 8px;\n color: white;\n cursor: pointer;\n background-color: #553DB8;\n border: none;\n padding: 0;\n margin-top: 4px;\n\n & > span {\n display: inline-block;\n padding: 12px 16px;\n border-radius: inherit;\n font-size: 20px;\n font-weight: bold;\n line-height: 1;\n background-color: #7553FF;\n border: 1px solid #553DB8;\n transform: translateY(-4px);\n }\n\n &:hover > span {\n transform: translateY(-8px);\n }\n\n &:active > span {\n transform: translateY(0);\n }\n\n &:disabled {\n cursor: not-allowed;\n opacity: 0.6;\n\n & > span {\n transform: translateY(0);\n border: none;\n }\n }\n }\n\n .description {\n text-align: center;\n color: #6E6C75;\n max-width: 500px;\n line-height: 1.5;\n font-size: 20px;\n\n @media (prefers-color-scheme: dark) {\n color: #A49FB5;\n }\n }\n\n .flex-spacer {\n flex: 1;\n }\n\n .success {\n padding: 12px 16px;\n border-radius: 8px;\n font-size: 20px;\n line-height: 1;\n background-color: #00F261;\n border: 1px solid #00BF4D;\n color: #181423;\n }\n\n .success_placeholder {\n height: 46px;\n }\n\n .connectivity-error {\n padding: 12px 16px;\n background-color: #E50045;\n border-radius: 8px;\n width: 500px;\n color: #FFFFFF;\n border: 1px solid #A80033;\n text-align: center;\n margin: 0;\n }\n \n .connectivity-error a {\n color: #FFFFFF;\n text-decoration: underline;\n }\n </style>\n \"\n `);\n });\n\n it('generates an issues link for self-hosted', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: true,\n url: 'https://sAntry.com/',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toContain(\n 'https://sAntry.com/organizations/test-org/issues/?project=test-project',\n );\n });\n\n it('generates an issues link for saas', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toContain(\n 'https://test-org.sentry.io/issues/?project=test-project',\n );\n });\n});\n\ndescribe('getSentryExampleApiRoute', () => {\n it('generates the correct API route template', () => {\n const result = getSentryExampleApiRoute();\n expect(result).toMatchInlineSnapshot(`\n \"// This is just a very simple API route that throws an example error.\n // Feel free to delete this file and the entire sentry route.\n\n export const GET = async () => {\n throw new Error(\"Sentry Example API Route Error\");\n };\n \"\n `);\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"templates.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SACrB,CAAC,CAAC;QAEH,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,SAAS,CACtB,wEAAwE,CACzE,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,MAAM,GAAG,IAAA,sCAA0B,EAAC;YACxC,UAAU,EAAE,KAAK;YACjB,GAAG,EAAE,mBAAmB;YACxB,OAAO,EAAE,UAAU;YACnB,SAAS,EAAE,cAAc;YACzB,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;QAEH,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,SAAS,CACtB,yDAAyD,CAC1D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAA,iBAAQ,EAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAA,WAAE,EAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG,IAAA,oCAAwB,GAAE,CAAC;QAC1C,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport {\n getClientHooksTemplate,\n getInstrumentationServerTemplate,\n getSentryExampleApiRoute,\n getSentryExampleSveltePage,\n getServerHooksTemplate,\n} from '../../src/sveltekit/templates';\nimport { insertClientInitCall } from '../../src/sveltekit/sdk-setup/setup';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule } from 'magicast';\n\nvi.mock('../../src/utils/clack/mcp-config', () => ({\n offerProjectScopedMcpConfig: vi.fn().mockResolvedValue(undefined),\n}));\n\ndescribe('getClientHooksTemplate', () => {\n it('generates client hooks template with all features enabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: true,\n replay: true,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\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 // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // If you don't want to use Session Replay, just remove the line below:\n integrations: [replayIntegration()],\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template when performance disabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: false,\n replay: true,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\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 // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // If you don't want to use Session Replay, just remove the line below:\n integrations: [replayIntegration()],\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template when replay disabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: true,\n replay: false,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n\n\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates client hooks template with only logs enabled', () => {\n const result = getClientHooksTemplate('https://sentry.io/123', {\n performance: false,\n replay: false,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n });\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n});\n\ndescribe('getServerHooksTemplate', () => {\n it('generates server hooks template with all features enabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template when performance disabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: true,\n logs: false,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template with only logs enabled', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n true,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n\n it('generates server hooks template without Sentry.init if includeSentryInit is false', () => {\n const result = getServerHooksTemplate(\n 'https://sentry.io/123',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n false,\n );\n\n expect(result).toMatchInlineSnapshot(`\n \"import { sequence } from \"@sveltejs/kit/hooks\";\n import { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\n\n\n // If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\n export const handle = sequence(sentryHandle());\n\n // If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\n export const handleError = handleErrorWithSentry();\n \"\n `);\n });\n});\n\ndescribe('getInstrumentationServerTemplate', () => {\n it('generates instrumentation.server template with all features enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: true,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template with only logs enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: false,\n logs: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template with only tracesSampleRate enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: true,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n tracesSampleRate: 1.0,\n\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n\n it('generates instrumentation.server template without any extra features enabled', () => {\n const result = getInstrumentationServerTemplate('https://sentry.io/123', {\n performance: false,\n logs: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"import * as Sentry from '@sentry/sveltekit';\n\n Sentry.init({\n dsn: 'https://sentry.io/123',\n\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n });\"`);\n });\n});\n\ndescribe('insertClientInitCall', () => {\n it('should insert client init call with all features enabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/123', originalHooksMod, {\n performance: true,\n replay: true,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/123\",\n tracesSampleRate: 1,\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1,\n integrations: [Sentry.replayIntegration()],\n enableLogs: true,\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with performance disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/456', originalHooksMod, {\n performance: false,\n replay: true,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/456\",\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1,\n integrations: [Sentry.replayIntegration()],\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with replay disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/789', originalHooksMod, {\n performance: true,\n replay: false,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/789\",\n tracesSampleRate: 1,\n enableLogs: true,\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with only logs enabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/xyz', originalHooksMod, {\n performance: false,\n replay: false,\n logs: true,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/xyz\",\n enableLogs: true,\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert client init call with all features disabled', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n `);\n\n insertClientInitCall('https://sentry.io/minimal', originalHooksMod, {\n performance: false,\n replay: false,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/minimal\",\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\"\n `);\n });\n\n it('should insert init call after imports', () => {\n const originalHooksMod = parseModule(`\n import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import { somethingElse } from \"some-package\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n export const handleError = handleErrorWithSentry();\n export const someOtherExport = somethingElse();\n `);\n\n insertClientInitCall('https://sentry.io/order-test', originalHooksMod, {\n performance: true,\n replay: false,\n logs: false,\n });\n\n const result = originalHooksMod.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import { handleErrorWithSentry } from \"@sentry/sveltekit\";\n import { somethingElse } from \"some-package\";\n import * as Sentry from \"@sentry/sveltekit\";\n\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.\n Sentry.init({\n dsn: \"https://sentry.io/order-test\",\n tracesSampleRate: 1,\n dataCollection: {\n // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit:\n // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#dataCollection\n // userInfo: false,\n // httpBodies: [],\n },\n })\n\n export const handleError = handleErrorWithSentry();\n export const someOtherExport = somethingElse();\"\n `);\n });\n});\n\ndescribe('getSentryExampleSveltePage', () => {\n it('generates example page template with Svelte 5', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"<!--\n This is just a very simple page with a button to throw an example error.\n Feel free to delete this file and the entire sentry route.\n -->\n\n <script>\n import * as Sentry from '@sentry/sveltekit';\n import { onMount } from 'svelte';\n \n let hasSentError = $state(false);\n let isConnected = true;\n\n onMount(async () => {\n const result = await Sentry.diagnoseSdkConnectivity();\n isConnected = result !== 'sentry-unreachable';\n });\n\n function getSentryData() {\n Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test'\n },\n async () => {\n const res = await fetch('/sentry-example-page');\n if (!res.ok) {\n hasSentError = true;\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }\n </script>\n\n <title>sentry-example-page</title>\n\n <div>\n <main>\n <div class=\"flex-spacer\"></div>\n <svg height=\"40\" width=\"40\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z\" fill=\"currentcolor\"/>\n </svg>\n <h1>\n sentry-example-page\n </h1>\n\n <p class=\"description\">\n Click the button below, and view the sample error on the Sentry <a target=\"_blank\" href=\"https://test-org.sentry.io/issues/?project=test-project\">Issues Page</a>. \n For more details about setting up Sentry, <a target=\"_blank\" href=\"https://docs.sentry.io/platforms/javascript/guides/sveltekit/\">read our docs</a>.\n </p>\n\n <button\n type=\"button\"\n onclick={getSentryData}\n disabled={!isConnected}\n >\n <span>\n Throw Sample Error\n </span>\n </button>\n\n {#if hasSentError}\n <p class=\"success\">\n Sample error was sent to Sentry.\n </p>\n {:else if !isConnected}\n <div class=\"connectivity-error\">\n <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>\n </div>\n {:else}\n <div class=\"success_placeholder\"></div>\n {/if}\n <div class=\"flex-spacer\"></div>\n </main>\n </div>\n\n <style>\n :global(body) {\n margin: 0;\n\n @media (prefers-color-scheme: dark) {\n color: #ededed;\n background-color: #0a0a0a;\n }\n }\n\n main {\n display: flex;\n min-height: 100vh;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n box-sizing: border-box;\n gap: 16px;\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n }\n\n h1 {\n padding: 0px 4px;\n border-radius: 4px;\n background-color: rgba(24, 20, 35, 0.03);\n font-family: monospace;\n font-size: 20px;\n line-height: 1.2;\n }\n\n p {\n margin: 0;\n font-size: 20px;\n }\n\n a {\n color: #6341F0;\n text-decoration: underline;\n cursor: pointer;\n\n @media (prefers-color-scheme: dark) {\n color: #B3A1FF;\n }\n }\n\n button {\n border-radius: 8px;\n color: white;\n cursor: pointer;\n background-color: #553DB8;\n border: none;\n padding: 0;\n margin-top: 4px;\n\n & > span {\n display: inline-block;\n padding: 12px 16px;\n border-radius: inherit;\n font-size: 20px;\n font-weight: bold;\n line-height: 1;\n background-color: #7553FF;\n border: 1px solid #553DB8;\n transform: translateY(-4px);\n }\n\n &:hover > span {\n transform: translateY(-8px);\n }\n\n &:active > span {\n transform: translateY(0);\n }\n\n &:disabled {\n cursor: not-allowed;\n opacity: 0.6;\n\n & > span {\n transform: translateY(0);\n border: none;\n }\n }\n }\n\n .description {\n text-align: center;\n color: #6E6C75;\n max-width: 500px;\n line-height: 1.5;\n font-size: 20px;\n\n @media (prefers-color-scheme: dark) {\n color: #A49FB5;\n }\n }\n\n .flex-spacer {\n flex: 1;\n }\n\n .success {\n padding: 12px 16px;\n border-radius: 8px;\n font-size: 20px;\n line-height: 1;\n background-color: #00F261;\n border: 1px solid #00BF4D;\n color: #181423;\n }\n\n .success_placeholder {\n height: 46px;\n }\n\n .connectivity-error {\n padding: 12px 16px;\n background-color: #E50045;\n border-radius: 8px;\n width: 500px;\n color: #FFFFFF;\n border: 1px solid #A80033;\n text-align: center;\n margin: 0;\n }\n \n .connectivity-error a {\n color: #FFFFFF;\n text-decoration: underline;\n }\n </style>\n \"\n `);\n });\n\n it('generates example page template pre-Svelte 5', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: false,\n });\n\n expect(result).toMatchInlineSnapshot(`\n \"<!--\n This is just a very simple page with a button to throw an example error.\n Feel free to delete this file and the entire sentry route.\n -->\n\n <script>\n import * as Sentry from '@sentry/sveltekit';\n import { onMount } from 'svelte';\n \n let hasSentError = false;\n let isConnected = true;\n\n onMount(async () => {\n const result = await Sentry.diagnoseSdkConnectivity();\n isConnected = result !== 'sentry-unreachable';\n });\n\n function getSentryData() {\n Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test'\n },\n async () => {\n const res = await fetch('/sentry-example-page');\n if (!res.ok) {\n hasSentError = true;\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }\n </script>\n\n <title>sentry-example-page</title>\n\n <div>\n <main>\n <div class=\"flex-spacer\"></div>\n <svg height=\"40\" width=\"40\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z\" fill=\"currentcolor\"/>\n </svg>\n <h1>\n sentry-example-page\n </h1>\n\n <p class=\"description\">\n Click the button below, and view the sample error on the Sentry <a target=\"_blank\" href=\"https://test-org.sentry.io/issues/?project=test-project\">Issues Page</a>. \n For more details about setting up Sentry, <a target=\"_blank\" href=\"https://docs.sentry.io/platforms/javascript/guides/sveltekit/\">read our docs</a>.\n </p>\n\n <button\n type=\"button\"\n on:click={getSentryData}\n disabled={!isConnected}\n >\n <span>\n Throw Sample Error\n </span>\n </button>\n\n {#if hasSentError}\n <p class=\"success\">\n Sample error was sent to Sentry.\n </p>\n {:else if !isConnected}\n <div class=\"connectivity-error\">\n <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>\n </div>\n {:else}\n <div class=\"success_placeholder\"></div>\n {/if}\n <div class=\"flex-spacer\"></div>\n </main>\n </div>\n\n <style>\n :global(body) {\n margin: 0;\n\n @media (prefers-color-scheme: dark) {\n color: #ededed;\n background-color: #0a0a0a;\n }\n }\n\n main {\n display: flex;\n min-height: 100vh;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n box-sizing: border-box;\n gap: 16px;\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n }\n\n h1 {\n padding: 0px 4px;\n border-radius: 4px;\n background-color: rgba(24, 20, 35, 0.03);\n font-family: monospace;\n font-size: 20px;\n line-height: 1.2;\n }\n\n p {\n margin: 0;\n font-size: 20px;\n }\n\n a {\n color: #6341F0;\n text-decoration: underline;\n cursor: pointer;\n\n @media (prefers-color-scheme: dark) {\n color: #B3A1FF;\n }\n }\n\n button {\n border-radius: 8px;\n color: white;\n cursor: pointer;\n background-color: #553DB8;\n border: none;\n padding: 0;\n margin-top: 4px;\n\n & > span {\n display: inline-block;\n padding: 12px 16px;\n border-radius: inherit;\n font-size: 20px;\n font-weight: bold;\n line-height: 1;\n background-color: #7553FF;\n border: 1px solid #553DB8;\n transform: translateY(-4px);\n }\n\n &:hover > span {\n transform: translateY(-8px);\n }\n\n &:active > span {\n transform: translateY(0);\n }\n\n &:disabled {\n cursor: not-allowed;\n opacity: 0.6;\n\n & > span {\n transform: translateY(0);\n border: none;\n }\n }\n }\n\n .description {\n text-align: center;\n color: #6E6C75;\n max-width: 500px;\n line-height: 1.5;\n font-size: 20px;\n\n @media (prefers-color-scheme: dark) {\n color: #A49FB5;\n }\n }\n\n .flex-spacer {\n flex: 1;\n }\n\n .success {\n padding: 12px 16px;\n border-radius: 8px;\n font-size: 20px;\n line-height: 1;\n background-color: #00F261;\n border: 1px solid #00BF4D;\n color: #181423;\n }\n\n .success_placeholder {\n height: 46px;\n }\n\n .connectivity-error {\n padding: 12px 16px;\n background-color: #E50045;\n border-radius: 8px;\n width: 500px;\n color: #FFFFFF;\n border: 1px solid #A80033;\n text-align: center;\n margin: 0;\n }\n \n .connectivity-error a {\n color: #FFFFFF;\n text-decoration: underline;\n }\n </style>\n \"\n `);\n });\n\n it('generates an issues link for self-hosted', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: true,\n url: 'https://sAntry.com/',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toContain(\n 'https://sAntry.com/organizations/test-org/issues/?project=test-project',\n );\n });\n\n it('generates an issues link for saas', () => {\n const result = getSentryExampleSveltePage({\n selfHosted: false,\n url: 'https://sentry.io',\n orgSlug: 'test-org',\n projectId: 'test-project',\n isUsingSvelte5: true,\n });\n\n expect(result).toContain(\n 'https://test-org.sentry.io/issues/?project=test-project',\n );\n });\n});\n\ndescribe('getSentryExampleApiRoute', () => {\n it('generates the correct API route template', () => {\n const result = getSentryExampleApiRoute();\n expect(result).toMatchInlineSnapshot(`\n \"// This is just a very simple API route that throws an example error.\n // Feel free to delete this file and the entire sentry route.\n\n export const GET = async () => {\n throw new Error(\"Sentry Example API Route Error\");\n };\n \"\n `);\n });\n});\n"]}
|
|
@@ -184,6 +184,28 @@ const vitest_1 = require("vitest");
|
|
|
184
184
|
(0, vitest_1.expect)(property?.comments[0].value).toBe(' This is a comment');
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
+
(0, vitest_1.describe)('preserveTrailingNewline', () => {
|
|
188
|
+
(0, vitest_1.it)('adds trailing newline if original had one but generated does not', () => {
|
|
189
|
+
const original = 'const foo = 1;\n';
|
|
190
|
+
const generated = 'const foo = 1;';
|
|
191
|
+
(0, vitest_1.expect)((0, ast_utils_1.preserveTrailingNewline)(original, generated)).toBe('const foo = 1;\n');
|
|
192
|
+
});
|
|
193
|
+
(0, vitest_1.it)('does not add trailing newline if original did not have one', () => {
|
|
194
|
+
const original = 'const foo = 1;';
|
|
195
|
+
const generated = 'const foo = 1;';
|
|
196
|
+
(0, vitest_1.expect)((0, ast_utils_1.preserveTrailingNewline)(original, generated)).toBe('const foo = 1;');
|
|
197
|
+
});
|
|
198
|
+
(0, vitest_1.it)('does not double trailing newline if both already have one', () => {
|
|
199
|
+
const original = 'const foo = 1;\n';
|
|
200
|
+
const generated = 'const foo = 1;\n';
|
|
201
|
+
(0, vitest_1.expect)((0, ast_utils_1.preserveTrailingNewline)(original, generated)).toBe('const foo = 1;\n');
|
|
202
|
+
});
|
|
203
|
+
(0, vitest_1.it)('does not remove trailing newline if original did not have one but generated does', () => {
|
|
204
|
+
const original = 'const foo = 1;';
|
|
205
|
+
const generated = 'const foo = 1;\n';
|
|
206
|
+
(0, vitest_1.expect)((0, ast_utils_1.preserveTrailingNewline)(original, generated)).toBe('const foo = 1;\n');
|
|
207
|
+
});
|
|
208
|
+
});
|
|
187
209
|
(0, vitest_1.describe)('parse and print JSON-C', () => {
|
|
188
210
|
vitest_1.it.each([
|
|
189
211
|
['simple JSON', "{'foo': 'bar'}"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.test.js","sourceRoot":"","sources":["../../../test/utils/ast-utils.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAOmC;AAEnC,+CAAiC;AACjC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,mCAA8C;AAE9C,IAAA,iBAAQ,EAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,WAAE,CAAC,IAAI,CAAC;QACN;;;KAGC;QACD;;;;;;;OAOG;KACJ,CAAC,CACA,2EAA2E,EAC3E,CAAC,IA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;QAClC,IAAA,eAAM,EAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACjC,IAAA,eAAM,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClD,gEAAgE;QAChE,IAAA,eAAM,EAAC,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAA,sBAAU,EAAC;;MAErC,CAAC,CAAC;QACJ,IAAA,eAAM,EAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC5B,IAAA,eAAM,EAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n getObjectProperty,\n getOrSetObjectProperty,\n hasSentryContent,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../src/utils/ast-utils';\n\nimport * as recast from 'recast';\nconst b = recast.types.builders;\n\nimport { describe, it, expect } from 'vitest';\n\ndescribe('hasSentryContent', () => {\n it.each([\n `\n const { sentryVitePlugin } = require(\"@sentry/vite-plugin\");\n const somethingelse = require('gs');\n `,\n `\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n `,\n ])(\n \"returns true if a require('@sentry/') call was found in the parsed module\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(true);\n },\n );\n\n it.each([\n `const whatever = require('something')`,\n `// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')`,\n `const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')`,\n `\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n `,\n `import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n `,\n `import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n `,\n ])(\n \"returns false if the file doesn't contain any require('@sentry/') calls\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(false);\n },\n );\n});\n\ndescribe('getObjectProperty', () => {\n it.each([\n [\n 'literal',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(\n b.stringLiteral('needle'),\n b.stringLiteral('haystack'),\n ),\n ]),\n ],\n [\n 'stringLiteral',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.literal('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n [\n 'identifier',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n ])('returns the poperty (%s) if it exists', (_, object) => {\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeDefined();\n // @ts-expect-error we know it's defined due to the expect above\n expect(recast.print(property).code).toEqual(\n expect.stringContaining('needle'),\n );\n });\n\n it('returns undefined if the property does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n\n it('handles objects without simple properties', () => {\n const object = b.objectExpression([b.spreadElement(b.identifier('foo'))]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n});\n\ndescribe('getOrSetObjectProperty', () => {\n it('returns the property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('nope'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('ObjectProperty');\n // @ts-expect-error we know its type\n expect(property.key.name).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n\n it('adds the property if it does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('Property');\n // @ts-expect-error we know its type\n expect(property.key.value).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n});\n\ndescribe('setOrUpdateObjectProperty', () => {\n it('sets a new property if it does not exist yet', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack'));\n\n expect(getObjectProperty(object, 'needle')).toBeDefined();\n });\n\n it('updates an existing property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack2'));\n\n const property = getObjectProperty(object, 'needle');\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.value.value).toBe('haystack2');\n });\n\n it('adds a comment to the existing property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n\n it('adds a comment to the new property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n});\n\ndescribe('parse and print JSON-C', () => {\n it.each([\n ['simple JSON', \"{'foo': 'bar'}\"],\n [\n 'JSON-C with inline comment',\n `\n {\n \"foo\": \"bar\" // with an inline comment\n }\n `,\n ],\n [\n 'JSON-C with multiple comments',\n `\n /*\n * let's throw in a block comment for good measure\n */ \n {\n // one line comment\n \"foo\": \"bar\", // another inline comment\n /* one more here */\n \"dogs\": /* and here */ \"awesome\",\n }\n /* and here */\n `,\n ],\n ])(`parses and prints JSON-C (%s)`, (_, json) => {\n const { ast, jsonObject } = parseJsonC(json);\n expect(ast?.type).toBe('Program');\n expect(jsonObject).toBeDefined();\n expect(jsonObject?.type).toBe('ObjectExpression');\n // @ts-expect-error we know it's defined due to the expect above\n expect(printJsonC(ast)).toEqual(json);\n });\n\n it('returns undefined if the input is not valid JSON-C', () => {\n const { ast, jsonObject } = parseJsonC(`{\n \"invalid\": // \"json\"\n }`);\n expect(ast).toBeUndefined();\n expect(jsonObject).toBeUndefined();\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ast-utils.test.js","sourceRoot":"","sources":["../../../test/utils/ast-utils.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAQmC;AAEnC,+CAAiC;AACjC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,mCAA8C;AAE9C,IAAA,iBAAQ,EAAC,kBA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CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAClC,IAAA,eAAM,EAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACjC,IAAA,eAAM,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClD,gEAAgE;QAChE,IAAA,eAAM,EAAC,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAA,sBAAU,EAAC;;MAErC,CAAC,CAAC;QACJ,IAAA,eAAM,EAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC5B,IAAA,eAAM,EAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n getObjectProperty,\n getOrSetObjectProperty,\n hasSentryContent,\n parseJsonC,\n preserveTrailingNewline,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../src/utils/ast-utils';\n\nimport * as recast from 'recast';\nconst b = recast.types.builders;\n\nimport { describe, it, expect } from 'vitest';\n\ndescribe('hasSentryContent', () => {\n it.each([\n `\n const { sentryVitePlugin } = require(\"@sentry/vite-plugin\");\n const somethingelse = require('gs');\n `,\n `\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n `,\n ])(\n \"returns true if a require('@sentry/') call was found in the parsed module\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(true);\n },\n );\n\n it.each([\n `const whatever = require('something')`,\n `// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')`,\n `const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')`,\n `\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n `,\n `import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n `,\n `import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n `,\n ])(\n \"returns false if the file doesn't contain any require('@sentry/') calls\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(false);\n },\n );\n});\n\ndescribe('getObjectProperty', () => {\n it.each([\n [\n 'literal',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(\n b.stringLiteral('needle'),\n b.stringLiteral('haystack'),\n ),\n ]),\n ],\n [\n 'stringLiteral',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.literal('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n [\n 'identifier',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n ])('returns the poperty (%s) if it exists', (_, object) => {\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeDefined();\n // @ts-expect-error we know it's defined due to the expect above\n expect(recast.print(property).code).toEqual(\n expect.stringContaining('needle'),\n );\n });\n\n it('returns undefined if the property does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n\n it('handles objects without simple properties', () => {\n const object = b.objectExpression([b.spreadElement(b.identifier('foo'))]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n});\n\ndescribe('getOrSetObjectProperty', () => {\n it('returns the property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('nope'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('ObjectProperty');\n // @ts-expect-error we know its type\n expect(property.key.name).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n\n it('adds the property if it does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('Property');\n // @ts-expect-error we know its type\n expect(property.key.value).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n});\n\ndescribe('setOrUpdateObjectProperty', () => {\n it('sets a new property if it does not exist yet', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack'));\n\n expect(getObjectProperty(object, 'needle')).toBeDefined();\n });\n\n it('updates an existing property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack2'));\n\n const property = getObjectProperty(object, 'needle');\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.value.value).toBe('haystack2');\n });\n\n it('adds a comment to the existing property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n\n it('adds a comment to the new property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n});\n\ndescribe('preserveTrailingNewline', () => {\n it('adds trailing newline if original had one but generated does not', () => {\n const original = 'const foo = 1;\\n';\n const generated = 'const foo = 1;';\n expect(preserveTrailingNewline(original, generated)).toBe(\n 'const foo = 1;\\n',\n );\n });\n\n it('does not add trailing newline if original did not have one', () => {\n const original = 'const foo = 1;';\n const generated = 'const foo = 1;';\n expect(preserveTrailingNewline(original, generated)).toBe('const foo = 1;');\n });\n\n it('does not double trailing newline if both already have one', () => {\n const original = 'const foo = 1;\\n';\n const generated = 'const foo = 1;\\n';\n expect(preserveTrailingNewline(original, generated)).toBe(\n 'const foo = 1;\\n',\n );\n });\n\n it('does not remove trailing newline if original did not have one but generated does', () => {\n const original = 'const foo = 1;';\n const generated = 'const foo = 1;\\n';\n expect(preserveTrailingNewline(original, generated)).toBe(\n 'const foo = 1;\\n',\n );\n });\n});\n\ndescribe('parse and print JSON-C', () => {\n it.each([\n ['simple JSON', \"{'foo': 'bar'}\"],\n [\n 'JSON-C with inline comment',\n `\n {\n \"foo\": \"bar\" // with an inline comment\n }\n `,\n ],\n [\n 'JSON-C with multiple comments',\n `\n /*\n * let's throw in a block comment for good measure\n */ \n {\n // one line comment\n \"foo\": \"bar\", // another inline comment\n /* one more here */\n \"dogs\": /* and here */ \"awesome\",\n }\n /* and here */\n `,\n ],\n ])(`parses and prints JSON-C (%s)`, (_, json) => {\n const { ast, jsonObject } = parseJsonC(json);\n expect(ast?.type).toBe('Program');\n expect(jsonObject).toBeDefined();\n expect(jsonObject?.type).toBe('ObjectExpression');\n // @ts-expect-error we know it's defined due to the expect above\n expect(printJsonC(ast)).toEqual(json);\n });\n\n it('returns undefined if the input is not valid JSON-C', () => {\n const { ast, jsonObject } = parseJsonC(`{\n \"invalid\": // \"json\"\n }`);\n expect(ast).toBeUndefined();\n expect(jsonObject).toBeUndefined();\n });\n});\n"]}
|
|
@@ -30,6 +30,7 @@ const clack_1 = require("../../../src/utils/clack/");
|
|
|
30
30
|
const fs = __importStar(require("node:fs"));
|
|
31
31
|
const ChildProcess = __importStar(require("node:child_process"));
|
|
32
32
|
const PackageManagerUtils = __importStar(require("../../../src/utils/package-manager"));
|
|
33
|
+
const GitUtils = __importStar(require("../../../src/utils/git"));
|
|
33
34
|
const package_manager_1 = require("../../../src/utils/package-manager");
|
|
34
35
|
const axios_1 = __importDefault(require("axios"));
|
|
35
36
|
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
@@ -61,6 +62,10 @@ vitest_1.vi.mock('@clack/prompts', () => ({
|
|
|
61
62
|
const clackMock = clack;
|
|
62
63
|
vitest_1.vi.mock('axios');
|
|
63
64
|
const mockedAxios = axios_1.default;
|
|
65
|
+
vitest_1.vi.mock('../../../src/utils/git', () => ({
|
|
66
|
+
isInGitRepo: vitest_1.vi.fn(),
|
|
67
|
+
getUncommittedOrUntrackedFiles: vitest_1.vi.fn(),
|
|
68
|
+
}));
|
|
64
69
|
vitest_1.vi.mock('opn', () => ({
|
|
65
70
|
default: vitest_1.vi.fn(() => Promise.resolve({ on: vitest_1.vi.fn() })),
|
|
66
71
|
}));
|
|
@@ -380,4 +385,100 @@ function mockUserResponse(fn, response) {
|
|
|
380
385
|
});
|
|
381
386
|
});
|
|
382
387
|
});
|
|
388
|
+
(0, vitest_1.describe)('confirmContinueIfNoOrDirtyGitRepo', () => {
|
|
389
|
+
// process.exit is mocked to throw so that abort() halts execution the same
|
|
390
|
+
// way it would terminate the process in production, instead of falling
|
|
391
|
+
// through to the interactive prompt.
|
|
392
|
+
let exitSpy;
|
|
393
|
+
(0, vitest_1.beforeEach)(() => {
|
|
394
|
+
vitest_1.vi.clearAllMocks();
|
|
395
|
+
// Drain any leftover `mockReturnValueOnce` values queued by earlier
|
|
396
|
+
// suites; `clearAllMocks` clears call history but not the once-queue.
|
|
397
|
+
clackMock.confirm.mockReset();
|
|
398
|
+
exitSpy = vitest_1.vi.spyOn(process, 'exit').mockImplementation((() => {
|
|
399
|
+
throw new Error('exit');
|
|
400
|
+
}));
|
|
401
|
+
});
|
|
402
|
+
(0, vitest_1.afterEach)(() => {
|
|
403
|
+
exitSpy.mockRestore();
|
|
404
|
+
});
|
|
405
|
+
(0, vitest_1.describe)('non-interactive mode', () => {
|
|
406
|
+
(0, vitest_1.it)('aborts without prompting when the project is not a git repository', async () => {
|
|
407
|
+
GitUtils.isInGitRepo.mockReturnValue(false);
|
|
408
|
+
await (0, vitest_1.expect)((0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({
|
|
409
|
+
ignoreGitChanges: undefined,
|
|
410
|
+
cwd: undefined,
|
|
411
|
+
nonInteractive: true,
|
|
412
|
+
})).rejects.toThrow('exit');
|
|
413
|
+
(0, vitest_1.expect)(clack.log.error).toHaveBeenCalledWith(vitest_1.expect.stringContaining('not inside a git repository in non-interactive mode'));
|
|
414
|
+
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('continue-without-git', false);
|
|
415
|
+
(0, vitest_1.expect)(clack.confirm).not.toHaveBeenCalled();
|
|
416
|
+
(0, vitest_1.expect)(exitSpy).toHaveBeenCalled();
|
|
417
|
+
});
|
|
418
|
+
(0, vitest_1.it)('aborts without prompting when the repository has uncommitted or untracked files', async () => {
|
|
419
|
+
GitUtils.isInGitRepo.mockReturnValue(true);
|
|
420
|
+
GitUtils.getUncommittedOrUntrackedFiles.mockReturnValue([
|
|
421
|
+
'- src/index.ts',
|
|
422
|
+
]);
|
|
423
|
+
await (0, vitest_1.expect)((0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({
|
|
424
|
+
ignoreGitChanges: false,
|
|
425
|
+
cwd: undefined,
|
|
426
|
+
nonInteractive: true,
|
|
427
|
+
})).rejects.toThrow('exit');
|
|
428
|
+
(0, vitest_1.expect)(clack.log.warn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('uncommitted or untracked files'));
|
|
429
|
+
(0, vitest_1.expect)(clack.log.error).toHaveBeenCalledWith(vitest_1.expect.stringContaining('uncommitted or untracked files in non-interactive mode'));
|
|
430
|
+
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('continue-with-dirty-repo', false);
|
|
431
|
+
(0, vitest_1.expect)(clack.confirm).not.toHaveBeenCalled();
|
|
432
|
+
(0, vitest_1.expect)(exitSpy).toHaveBeenCalled();
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
(0, vitest_1.describe)('interactive mode (default)', () => {
|
|
436
|
+
(0, vitest_1.it)('prompts to continue when the project is not a git repository', async () => {
|
|
437
|
+
GitUtils.isInGitRepo.mockReturnValue(false);
|
|
438
|
+
mockUserResponse(clack.confirm, true);
|
|
439
|
+
await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({
|
|
440
|
+
ignoreGitChanges: undefined,
|
|
441
|
+
cwd: undefined,
|
|
442
|
+
});
|
|
443
|
+
(0, vitest_1.expect)(clack.confirm).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
444
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
445
|
+
message: vitest_1.expect.stringContaining('not inside a git repository'),
|
|
446
|
+
}));
|
|
447
|
+
(0, vitest_1.expect)(clack.log.error).not.toHaveBeenCalled();
|
|
448
|
+
(0, vitest_1.expect)(exitSpy).not.toHaveBeenCalled();
|
|
449
|
+
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('continue-without-git', true);
|
|
450
|
+
});
|
|
451
|
+
(0, vitest_1.it)('prompts to continue when the repository has uncommitted or untracked files', async () => {
|
|
452
|
+
GitUtils.isInGitRepo.mockReturnValue(true);
|
|
453
|
+
GitUtils.getUncommittedOrUntrackedFiles.mockReturnValue([
|
|
454
|
+
'- src/index.ts',
|
|
455
|
+
]);
|
|
456
|
+
mockUserResponse(clack.confirm, true);
|
|
457
|
+
await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({
|
|
458
|
+
ignoreGitChanges: false,
|
|
459
|
+
cwd: undefined,
|
|
460
|
+
nonInteractive: false,
|
|
461
|
+
});
|
|
462
|
+
(0, vitest_1.expect)(clack.log.warn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('uncommitted or untracked files'));
|
|
463
|
+
(0, vitest_1.expect)(clack.confirm).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
464
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
465
|
+
message: vitest_1.expect.stringContaining('continue anyway'),
|
|
466
|
+
}));
|
|
467
|
+
(0, vitest_1.expect)(clack.log.error).not.toHaveBeenCalled();
|
|
468
|
+
(0, vitest_1.expect)(exitSpy).not.toHaveBeenCalled();
|
|
469
|
+
(0, vitest_1.expect)(Sentry.setTag).toHaveBeenCalledWith('continue-with-dirty-repo', true);
|
|
470
|
+
});
|
|
471
|
+
(0, vitest_1.it)('does not prompt or abort for a clean git repository', async () => {
|
|
472
|
+
GitUtils.isInGitRepo.mockReturnValue(true);
|
|
473
|
+
GitUtils.getUncommittedOrUntrackedFiles.mockReturnValue([]);
|
|
474
|
+
await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({
|
|
475
|
+
ignoreGitChanges: undefined,
|
|
476
|
+
cwd: undefined,
|
|
477
|
+
});
|
|
478
|
+
(0, vitest_1.expect)(clack.confirm).not.toHaveBeenCalled();
|
|
479
|
+
(0, vitest_1.expect)(clack.log.warn).not.toHaveBeenCalled();
|
|
480
|
+
(0, vitest_1.expect)(exitSpy).not.toHaveBeenCalled();
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
});
|
|
383
484
|
//# sourceMappingURL=index.test.js.map
|