@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.
Files changed (245) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/bin.js +16 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/e2e-tests/tests/angular-17.test.js +3 -4
  5. package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
  6. package/dist/e2e-tests/tests/angular-19.test.js +3 -4
  7. package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
  8. package/dist/e2e-tests/tests/cloudflare-worker.test.js +5 -0
  9. package/dist/e2e-tests/tests/cloudflare-worker.test.js.map +1 -1
  10. package/dist/e2e-tests/tests/flutter.test.js +60 -0
  11. package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
  12. package/dist/e2e-tests/tests/help-message.test.js +8 -3
  13. package/dist/e2e-tests/tests/help-message.test.js.map +1 -1
  14. package/dist/e2e-tests/tests/nuxt-3.test.js +12 -6
  15. package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
  16. package/dist/e2e-tests/tests/nuxt-4.test.js +12 -6
  17. package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
  18. package/dist/e2e-tests/tests/pnpm-workspace.test.js +8 -4
  19. package/dist/e2e-tests/tests/pnpm-workspace.test.js.map +1 -1
  20. package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js +96 -0
  21. package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js.map +1 -0
  22. package/dist/e2e-tests/tests/react-router.test.js +6 -7
  23. package/dist/e2e-tests/tests/react-router.test.js.map +1 -1
  24. package/dist/e2e-tests/tests/remix.test.js +2 -4
  25. package/dist/e2e-tests/tests/remix.test.js.map +1 -1
  26. package/dist/e2e-tests/tests/sveltekit-hooks.test.js +24 -8
  27. package/dist/e2e-tests/tests/sveltekit-hooks.test.js.map +1 -1
  28. package/dist/e2e-tests/tests/sveltekit-tracing.test.js +8 -4
  29. package/dist/e2e-tests/tests/sveltekit-tracing.test.js.map +1 -1
  30. package/dist/lib/Constants.d.ts +1 -0
  31. package/dist/lib/Constants.js +5 -0
  32. package/dist/lib/Constants.js.map +1 -1
  33. package/dist/lib/Steps/Integrations/Electron.js +2 -2
  34. package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
  35. package/dist/src/android/android-wizard.js +3 -0
  36. package/dist/src/android/android-wizard.js.map +1 -1
  37. package/dist/src/angular/codemods/main.d.ts +1 -1
  38. package/dist/src/angular/codemods/main.js +0 -1
  39. package/dist/src/angular/codemods/main.js.map +1 -1
  40. package/dist/src/apple/apple-wizard.js +2 -3
  41. package/dist/src/apple/apple-wizard.js.map +1 -1
  42. package/dist/src/apple/check-installed-cli.d.ts +1 -1
  43. package/dist/src/apple/check-installed-cli.js +13 -7
  44. package/dist/src/apple/check-installed-cli.js.map +1 -1
  45. package/dist/src/apple/code-tools.js +17 -3
  46. package/dist/src/apple/code-tools.js.map +1 -1
  47. package/dist/src/apple/configure-package-manager.js +18 -5
  48. package/dist/src/apple/configure-package-manager.js.map +1 -1
  49. package/dist/src/apple/configure-xcode-project.js +8 -1
  50. package/dist/src/apple/configure-xcode-project.js.map +1 -1
  51. package/dist/src/apple/lookup-xcode-project.d.ts +8 -5
  52. package/dist/src/apple/lookup-xcode-project.js +22 -17
  53. package/dist/src/apple/lookup-xcode-project.js.map +1 -1
  54. package/dist/src/apple/options.d.ts +5 -0
  55. package/dist/src/apple/options.js.map +1 -1
  56. package/dist/src/apple/sentry-swift-package.d.ts +4 -0
  57. package/dist/src/apple/sentry-swift-package.js +17 -0
  58. package/dist/src/apple/sentry-swift-package.js.map +1 -0
  59. package/dist/src/apple/snapshots/apple-snapshots-wizard.d.ts +2 -0
  60. package/dist/src/apple/snapshots/apple-snapshots-wizard.js +251 -0
  61. package/dist/src/apple/snapshots/apple-snapshots-wizard.js.map +1 -0
  62. package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.d.ts +13 -0
  63. package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.js +48 -0
  64. package/dist/src/apple/snapshots/configure-snapshotpreviews-xcode-project.js.map +1 -0
  65. package/dist/src/apple/snapshots/snapshot-test-file.d.ts +18 -0
  66. package/dist/src/apple/snapshots/snapshot-test-file.js +122 -0
  67. package/dist/src/apple/snapshots/snapshot-test-file.js.map +1 -0
  68. package/dist/src/apple/snapshots/snapshot-verification-scheme.d.ts +6 -0
  69. package/dist/src/apple/snapshots/snapshot-verification-scheme.js +147 -0
  70. package/dist/src/apple/snapshots/snapshot-verification-scheme.js.map +1 -0
  71. package/dist/src/apple/snapshots/snapshotpreviews-package.d.ts +4 -0
  72. package/dist/src/apple/snapshots/snapshotpreviews-package.js +8 -0
  73. package/dist/src/apple/snapshots/snapshotpreviews-package.js.map +1 -0
  74. package/dist/src/apple/snapshots/snapshots-cli-preflight.d.ts +23 -0
  75. package/dist/src/apple/snapshots/snapshots-cli-preflight.js +136 -0
  76. package/dist/src/apple/snapshots/snapshots-cli-preflight.js.map +1 -0
  77. package/dist/src/apple/xcode-manager.d.ts +59 -1
  78. package/dist/src/apple/xcode-manager.js +507 -106
  79. package/dist/src/apple/xcode-manager.js.map +1 -1
  80. package/dist/src/cloudflare/cloudflare-wizard.js +5 -0
  81. package/dist/src/cloudflare/cloudflare-wizard.js.map +1 -1
  82. package/dist/src/cloudflare/sdk-setup.d.ts +1 -0
  83. package/dist/src/cloudflare/sdk-setup.js.map +1 -1
  84. package/dist/src/cloudflare/templates.d.ts +1 -0
  85. package/dist/src/cloudflare/templates.js +7 -1
  86. package/dist/src/cloudflare/templates.js.map +1 -1
  87. package/dist/src/cloudflare/wrap-worker.d.ts +1 -0
  88. package/dist/src/cloudflare/wrap-worker.js +7 -0
  89. package/dist/src/cloudflare/wrap-worker.js.map +1 -1
  90. package/dist/src/flutter/flutter-wizard.js +3 -0
  91. package/dist/src/flutter/flutter-wizard.js.map +1 -1
  92. package/dist/src/nextjs/templates.js +12 -6
  93. package/dist/src/nextjs/templates.js.map +1 -1
  94. package/dist/src/nuxt/templates.js +12 -6
  95. package/dist/src/nuxt/templates.js.map +1 -1
  96. package/dist/src/react-native/expo.d.ts +6 -0
  97. package/dist/src/react-native/expo.js +27 -1
  98. package/dist/src/react-native/expo.js.map +1 -1
  99. package/dist/src/react-native/git.d.ts +5 -0
  100. package/dist/src/react-native/git.js +32 -1
  101. package/dist/src/react-native/git.js.map +1 -1
  102. package/dist/src/react-native/javascript.js +3 -1
  103. package/dist/src/react-native/javascript.js.map +1 -1
  104. package/dist/src/react-native/react-native-wizard.js +12 -6
  105. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  106. package/dist/src/react-router/codemods/client.entry.d.ts +1 -1
  107. package/dist/src/react-router/codemods/client.entry.js +124 -26
  108. package/dist/src/react-router/codemods/client.entry.js.map +1 -1
  109. package/dist/src/react-router/codemods/react-router-config.js +1 -1
  110. package/dist/src/react-router/codemods/react-router-config.js.map +1 -1
  111. package/dist/src/react-router/codemods/server-entry.d.ts +1 -1
  112. package/dist/src/react-router/codemods/server-entry.js +40 -4
  113. package/dist/src/react-router/codemods/server-entry.js.map +1 -1
  114. package/dist/src/react-router/codemods/vite.js +46 -1
  115. package/dist/src/react-router/codemods/vite.js.map +1 -1
  116. package/dist/src/react-router/react-router-wizard.js +62 -21
  117. package/dist/src/react-router/react-router-wizard.js.map +1 -1
  118. package/dist/src/react-router/sdk-setup.d.ts +5 -3
  119. package/dist/src/react-router/sdk-setup.js +44 -16
  120. package/dist/src/react-router/sdk-setup.js.map +1 -1
  121. package/dist/src/react-router/templates.d.ts +2 -4
  122. package/dist/src/react-router/templates.js +89 -87
  123. package/dist/src/react-router/templates.js.map +1 -1
  124. package/dist/src/remix/sdk-setup.js +1 -2
  125. package/dist/src/remix/sdk-setup.js.map +1 -1
  126. package/dist/src/run.d.ts +4 -1
  127. package/dist/src/run.js +13 -0
  128. package/dist/src/run.js.map +1 -1
  129. package/dist/src/sourcemaps/tools/remix.js +4 -4
  130. package/dist/src/sourcemaps/tools/remix.js.map +1 -1
  131. package/dist/src/sourcemaps/tools/vite.js +1 -1
  132. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  133. package/dist/src/sveltekit/sdk-setup/setup.js +17 -4
  134. package/dist/src/sveltekit/sdk-setup/setup.js.map +1 -1
  135. package/dist/src/sveltekit/sdk-setup/vite.js +1 -1
  136. package/dist/src/sveltekit/sdk-setup/vite.js.map +1 -1
  137. package/dist/src/sveltekit/templates.js +12 -6
  138. package/dist/src/sveltekit/templates.js.map +1 -1
  139. package/dist/src/utils/ast-utils.d.ts +10 -0
  140. package/dist/src/utils/ast-utils.js +19 -1
  141. package/dist/src/utils/ast-utils.js.map +1 -1
  142. package/dist/src/utils/clack/index.d.ts +2 -1
  143. package/dist/src/utils/clack/index.js +17 -6
  144. package/dist/src/utils/clack/index.js.map +1 -1
  145. package/dist/src/utils/files.d.ts +2 -0
  146. package/dist/src/utils/files.js +58 -0
  147. package/dist/src/utils/files.js.map +1 -0
  148. package/dist/src/utils/git.d.ts +3 -1
  149. package/dist/src/utils/git.js +2 -1
  150. package/dist/src/utils/git.js.map +1 -1
  151. package/dist/src/utils/line-endings.d.ts +1 -0
  152. package/dist/src/utils/line-endings.js +76 -0
  153. package/dist/src/utils/line-endings.js.map +1 -0
  154. package/dist/src/version.d.ts +1 -1
  155. package/dist/src/version.js +1 -1
  156. package/dist/src/version.js.map +1 -1
  157. package/dist/test/angular/angular-wizard.test.js +0 -5
  158. package/dist/test/angular/angular-wizard.test.js.map +1 -1
  159. package/dist/test/apple/code-tools.test.js +78 -0
  160. package/dist/test/apple/code-tools.test.js.map +1 -1
  161. package/dist/test/apple/configure-package-manager.test.d.ts +1 -0
  162. package/dist/test/apple/configure-package-manager.test.js +161 -0
  163. package/dist/test/apple/configure-package-manager.test.js.map +1 -0
  164. package/dist/test/apple/lookup-xcode-project.test.d.ts +1 -0
  165. package/dist/test/apple/lookup-xcode-project.test.js +167 -0
  166. package/dist/test/apple/lookup-xcode-project.test.js.map +1 -0
  167. package/dist/test/apple/snapshots/apple-snapshots-wizard.test.d.ts +1 -0
  168. package/dist/test/apple/snapshots/apple-snapshots-wizard.test.js +487 -0
  169. package/dist/test/apple/snapshots/apple-snapshots-wizard.test.js.map +1 -0
  170. package/dist/test/apple/snapshots/hosted-test-target-fixture.d.ts +24 -0
  171. package/dist/test/apple/snapshots/hosted-test-target-fixture.js +191 -0
  172. package/dist/test/apple/snapshots/hosted-test-target-fixture.js.map +1 -0
  173. package/dist/test/apple/snapshots/snapshot-test-file.test.d.ts +1 -0
  174. package/dist/test/apple/snapshots/snapshot-test-file.test.js +110 -0
  175. package/dist/test/apple/snapshots/snapshot-test-file.test.js.map +1 -0
  176. package/dist/test/apple/snapshots/snapshot-verification-scheme.test.d.ts +1 -0
  177. package/dist/test/apple/snapshots/snapshot-verification-scheme.test.js +146 -0
  178. package/dist/test/apple/snapshots/snapshot-verification-scheme.test.js.map +1 -0
  179. package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.d.ts +1 -0
  180. package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.js +186 -0
  181. package/dist/test/apple/snapshots/snapshotpreviews-xcode-smoke.test.js.map +1 -0
  182. package/dist/test/apple/snapshots/snapshots-cli-preflight.test.d.ts +1 -0
  183. package/dist/test/apple/snapshots/snapshots-cli-preflight.test.js +192 -0
  184. package/dist/test/apple/snapshots/snapshots-cli-preflight.test.js.map +1 -0
  185. package/dist/test/apple/snapshots/source-file-insertion.test.d.ts +1 -0
  186. package/dist/test/apple/snapshots/source-file-insertion.test.js +77 -0
  187. package/dist/test/apple/snapshots/source-file-insertion.test.js.map +1 -0
  188. package/dist/test/apple/xcode-manager.test.js +452 -43
  189. package/dist/test/apple/xcode-manager.test.js.map +1 -1
  190. package/dist/test/cloudflare/sdk-setup.test.js +20 -2
  191. package/dist/test/cloudflare/sdk-setup.test.js.map +1 -1
  192. package/dist/test/cloudflare/templates.test.js +54 -0
  193. package/dist/test/cloudflare/templates.test.js.map +1 -1
  194. package/dist/test/cloudflare/wrap-worker.test.js +74 -11
  195. package/dist/test/cloudflare/wrap-worker.test.js.map +1 -1
  196. package/dist/test/constants.test.d.ts +1 -0
  197. package/dist/test/constants.test.js +12 -0
  198. package/dist/test/constants.test.js.map +1 -0
  199. package/dist/test/nextjs/templates.test.js +66 -33
  200. package/dist/test/nextjs/templates.test.js.map +1 -1
  201. package/dist/test/nuxt/templates.test.js +66 -36
  202. package/dist/test/nuxt/templates.test.js.map +1 -1
  203. package/dist/test/react-native/expo.test.js +140 -0
  204. package/dist/test/react-native/expo.test.js.map +1 -1
  205. package/dist/test/react-native/git.test.d.ts +1 -0
  206. package/dist/test/react-native/git.test.js +160 -0
  207. package/dist/test/react-native/git.test.js.map +1 -0
  208. package/dist/test/react-router/codemods/client-entry.test.js +38 -5
  209. package/dist/test/react-router/codemods/client-entry.test.js.map +1 -1
  210. package/dist/test/react-router/codemods/server-entry.test.js +83 -0
  211. package/dist/test/react-router/codemods/server-entry.test.js.map +1 -1
  212. package/dist/test/react-router/codemods/vite.test.js +89 -0
  213. package/dist/test/react-router/codemods/vite.test.js.map +1 -1
  214. package/dist/test/react-router/sdk-setup.test.js +98 -6
  215. package/dist/test/react-router/sdk-setup.test.js.map +1 -1
  216. package/dist/test/react-router/templates.test.js +50 -38
  217. package/dist/test/react-router/templates.test.js.map +1 -1
  218. package/dist/test/remix/build-script.test.d.ts +1 -0
  219. package/dist/test/remix/build-script.test.js +124 -0
  220. package/dist/test/remix/build-script.test.js.map +1 -0
  221. package/dist/test/remix/client-entry.test.js +4 -10
  222. package/dist/test/remix/client-entry.test.js.map +1 -1
  223. package/dist/test/run.test.d.ts +1 -0
  224. package/dist/test/run.test.js +137 -0
  225. package/dist/test/run.test.js.map +1 -0
  226. package/dist/test/sourcemaps/tools/vite.test.js +12 -8
  227. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
  228. package/dist/test/sveltekit/templates.test.js +78 -27
  229. package/dist/test/sveltekit/templates.test.js.map +1 -1
  230. package/dist/test/utils/ast-utils.test.js +22 -0
  231. package/dist/test/utils/ast-utils.test.js.map +1 -1
  232. package/dist/test/utils/clack/index.test.js +101 -0
  233. package/dist/test/utils/clack/index.test.js.map +1 -1
  234. package/dist/test/utils/git.test.js +10 -0
  235. package/dist/test/utils/git.test.js.map +1 -1
  236. package/dist/test/utils/line-endings.test.d.ts +1 -0
  237. package/dist/test/utils/line-endings.test.js +103 -0
  238. package/dist/test/utils/line-endings.test.js.map +1 -0
  239. package/package.json +2 -2
  240. package/dist/src/react-router/codemods/root.d.ts +0 -1
  241. package/dist/src/react-router/codemods/root.js +0 -171
  242. package/dist/src/react-router/codemods/root.js.map +0 -1
  243. package/dist/test/react-router/codemods/root.test.js +0 -178
  244. package/dist/test/react-router/codemods/root.test.js.map +0 -1
  245. /package/dist/{test/react-router/codemods/root.test.d.ts → e2e-tests/tests/react-router-instrumentation-api.test.d.ts} +0 -0
@@ -1,178 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const vitest_1 = require("vitest");
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const root_1 = require("../../../src/react-router/codemods/root");
30
- vitest_1.vi.mock('@clack/prompts', () => {
31
- const mock = {
32
- log: {
33
- warn: vitest_1.vi.fn(),
34
- info: vitest_1.vi.fn(),
35
- success: vitest_1.vi.fn(),
36
- },
37
- };
38
- return {
39
- default: mock,
40
- ...mock,
41
- };
42
- });
43
- vitest_1.vi.mock('../../../src/utils/debug', () => ({
44
- debug: vitest_1.vi.fn(),
45
- }));
46
- (0, vitest_1.describe)('instrumentRoot', () => {
47
- const fixturesDir = path.join(__dirname, 'fixtures', 'root');
48
- let tmpDir;
49
- let appDir;
50
- (0, vitest_1.beforeEach)(() => {
51
- vitest_1.vi.clearAllMocks();
52
- // Create unique tmp directory for each test
53
- tmpDir = path.join(fixturesDir, 'tmp', `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
54
- appDir = path.join(tmpDir, 'app');
55
- // Ensure tmp and app directories exist
56
- fs.mkdirSync(appDir, { recursive: true });
57
- // Mock process.cwd() to return the tmp directory
58
- vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
59
- });
60
- (0, vitest_1.afterEach)(() => {
61
- // Clean up tmp directory
62
- if (fs.existsSync(tmpDir)) {
63
- fs.rmSync(tmpDir, { recursive: true });
64
- }
65
- vitest_1.vi.restoreAllMocks();
66
- });
67
- (0, vitest_1.it)('should add ErrorBoundary when no ErrorBoundary exists and no Sentry content', async () => {
68
- // Copy fixture to tmp directory for testing
69
- const srcFile = path.join(fixturesDir, 'no-error-boundary.tsx');
70
- // Create app directory and copy file
71
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
72
- // Mock process.cwd() to return tmpDir
73
- await (0, root_1.instrumentRoot)('root.tsx');
74
- // Check that the file was modified correctly
75
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
76
- (0, vitest_1.expect)(modifiedContent).toContain('import * as Sentry from "@sentry/react-router";');
77
- (0, vitest_1.expect)(modifiedContent).toContain("import { Outlet, isRouteErrorResponse } from 'react-router';");
78
- (0, vitest_1.expect)(modifiedContent).toContain('export function ErrorBoundary({ error })');
79
- (0, vitest_1.expect)(modifiedContent).toContain('Sentry.captureException(error);');
80
- (0, vitest_1.expect)(modifiedContent).toContain('if (isRouteErrorResponse(error))');
81
- });
82
- (0, vitest_1.it)('should add Sentry.captureException to existing function declaration ErrorBoundary', async () => {
83
- const srcFile = path.join(fixturesDir, 'with-function-error-boundary.tsx');
84
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
85
- await (0, root_1.instrumentRoot)('root.tsx');
86
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
87
- (0, vitest_1.expect)(modifiedContent).toContain('import * as Sentry from "@sentry/react-router";');
88
- (0, vitest_1.expect)(modifiedContent).toContain('Sentry.captureException(error);');
89
- });
90
- (0, vitest_1.it)('should add Sentry.captureException to existing variable declaration ErrorBoundary', async () => {
91
- const srcFile = path.join(fixturesDir, 'with-variable-error-boundary.tsx');
92
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
93
- await (0, root_1.instrumentRoot)('root.tsx');
94
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
95
- (0, vitest_1.expect)(modifiedContent).toContain('import * as Sentry from "@sentry/react-router";');
96
- // Now properly handles variable declaration ErrorBoundary
97
- (0, vitest_1.expect)(modifiedContent).toContain('Sentry.captureException(error);');
98
- });
99
- (0, vitest_1.it)('should not modify file when ErrorBoundary already has Sentry.captureException', async () => {
100
- const srcFile = path.join(fixturesDir, 'with-sentry-error-boundary.tsx');
101
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
102
- await (0, root_1.instrumentRoot)('root.tsx');
103
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
104
- // Should not add duplicate Sentry.captureException
105
- const captureExceptionOccurrences = (modifiedContent.match(/Sentry\.captureException/g) || []).length;
106
- (0, vitest_1.expect)(captureExceptionOccurrences).toBe(1);
107
- });
108
- (0, vitest_1.it)('should not add Sentry import when Sentry content already exists', async () => {
109
- const srcFile = path.join(fixturesDir, 'with-existing-sentry.tsx');
110
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
111
- await (0, root_1.instrumentRoot)('root.tsx');
112
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
113
- // Should not duplicate Sentry imports
114
- const sentryImportOccurrences = (modifiedContent.match(/import.*@sentry\/react-router/g) || []).length;
115
- (0, vitest_1.expect)(sentryImportOccurrences).toBe(1);
116
- });
117
- (0, vitest_1.it)('should add isRouteErrorResponse import when not present and ErrorBoundary is added', async () => {
118
- const srcFile = path.join(fixturesDir, 'no-isrouteerrorresponse.tsx');
119
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
120
- await (0, root_1.instrumentRoot)('root.tsx');
121
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
122
- (0, vitest_1.expect)(modifiedContent).toContain("import { Outlet, isRouteErrorResponse } from 'react-router';");
123
- (0, vitest_1.expect)(modifiedContent).toContain('export function ErrorBoundary({ error })');
124
- });
125
- (0, vitest_1.it)('should not add duplicate isRouteErrorResponse import when already present', async () => {
126
- const srcFile = path.join(fixturesDir, 'with-isrouteerrorresponse.tsx');
127
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
128
- await (0, root_1.instrumentRoot)('root.tsx');
129
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
130
- // Should not duplicate isRouteErrorResponse imports
131
- const isRouteErrorResponseOccurrences = (modifiedContent.match(/isRouteErrorResponse/g) || []).length;
132
- (0, vitest_1.expect)(isRouteErrorResponseOccurrences).toBe(2); // One import, one usage in template
133
- });
134
- (0, vitest_1.it)('should handle ErrorBoundary with alternative function declaration syntax', async () => {
135
- const srcFile = path.join(fixturesDir, 'function-expression-error-boundary.tsx');
136
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
137
- await (0, root_1.instrumentRoot)('root.tsx');
138
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
139
- (0, vitest_1.expect)(modifiedContent).toContain('import * as Sentry from "@sentry/react-router";');
140
- (0, vitest_1.expect)(modifiedContent).toContain('Sentry.captureException(error);');
141
- });
142
- (0, vitest_1.it)('should handle function declaration with separate export', async () => {
143
- const srcFile = path.join(fixturesDir, 'function-declaration-separate-export.tsx');
144
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
145
- await (0, root_1.instrumentRoot)('root.tsx');
146
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
147
- (0, vitest_1.expect)(modifiedContent).toContain('import * as Sentry from "@sentry/react-router";');
148
- (0, vitest_1.expect)(modifiedContent).toContain('Sentry.captureException(error);');
149
- // Should preserve function declaration syntax
150
- (0, vitest_1.expect)(modifiedContent).toMatch(/function ErrorBoundary\(/);
151
- (0, vitest_1.expect)(modifiedContent).toContain('export { ErrorBoundary }');
152
- });
153
- (0, vitest_1.it)('should handle ErrorBoundary with captureException imported directly', async () => {
154
- const srcFile = path.join(fixturesDir, 'with-direct-capture-exception.tsx');
155
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
156
- await (0, root_1.instrumentRoot)('root.tsx');
157
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
158
- // Should not add duplicate captureException calls
159
- const captureExceptionOccurrences = (modifiedContent.match(/captureException/g) || []).length;
160
- (0, vitest_1.expect)(captureExceptionOccurrences).toBe(2); // One import, one usage
161
- });
162
- (0, vitest_1.it)('should not modify an already properly configured file', async () => {
163
- const srcFile = path.join(fixturesDir, 'fully-configured.tsx');
164
- fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
165
- await (0, root_1.instrumentRoot)('root.tsx');
166
- const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
167
- // Should not add duplicate imports or modify existing Sentry configuration
168
- const sentryImportOccurrences = (modifiedContent.match(/import.*@sentry\/react-router/g) || []).length;
169
- (0, vitest_1.expect)(sentryImportOccurrences).toBe(1);
170
- const captureExceptionOccurrences = (modifiedContent.match(/Sentry\.captureException/g) || []).length;
171
- (0, vitest_1.expect)(captureExceptionOccurrences).toBe(1);
172
- const errorBoundaryOccurrences = (modifiedContent.match(/export function ErrorBoundary/g) || []).length;
173
- (0, vitest_1.expect)(errorBoundaryOccurrences).toBe(1);
174
- (0, vitest_1.expect)(modifiedContent).toContain("import * as Sentry from '@sentry/react-router';");
175
- (0, vitest_1.expect)(modifiedContent).toContain("import { Outlet, isRouteErrorResponse } from 'react-router';");
176
- });
177
- });
178
- //# sourceMappingURL=root.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"root.test.js","sourceRoot":"","sources":["../../../../test/react-router/codemods/root.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAyE;AACzE,uCAAyB;AACzB,2CAA6B;AAC7B,kEAAyE;AAEzE,WAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC7B,MAAM,IAAI,GAAG;QACX,GAAG,EAAE;YACH,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,OAAO,EAAE,WAAE,CAAC,EAAE,EAAE;SACjB;KACF,CAAC;IACF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,GAAG,IAAI;KACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,WAAE,CAAC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,CAAC;IACzC,KAAK,EAAE,WAAE,CAAC,EAAE,EAAE;CACf,CAAC,CAAC,CAAC;AAEJ,IAAA,iBAAQ,EAAC,gBAAgB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EAAC,eAAe,CAAC,CAAC,SAAS,CAC/B,8DAA8D,CAC/D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { instrumentRoot } from '../../../src/react-router/codemods/root';\n\nvi.mock('@clack/prompts', () => {\n const mock = {\n log: {\n warn: vi.fn(),\n info: vi.fn(),\n success: vi.fn(),\n },\n };\n return {\n default: mock,\n ...mock,\n };\n});\n\nvi.mock('../../../src/utils/debug', () => ({\n debug: vi.fn(),\n}));\n\ndescribe('instrumentRoot', () => {\n const fixturesDir = path.join(__dirname, 'fixtures', 'root');\n let tmpDir: string;\n let appDir: string;\n\n beforeEach(() => {\n vi.clearAllMocks();\n\n // Create unique tmp directory for each test\n tmpDir = path.join(\n fixturesDir,\n 'tmp',\n `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n appDir = path.join(tmpDir, 'app');\n\n // Ensure tmp and app directories exist\n fs.mkdirSync(appDir, { recursive: true });\n\n // Mock process.cwd() to return the tmp directory\n vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);\n });\n\n afterEach(() => {\n // Clean up tmp directory\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true });\n }\n vi.restoreAllMocks();\n });\n\n it('should add ErrorBoundary when no ErrorBoundary exists and no Sentry content', async () => {\n // Copy fixture to tmp directory for testing\n const srcFile = path.join(fixturesDir, 'no-error-boundary.tsx');\n\n // Create app directory and copy file\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n // Mock process.cwd() to return tmpDir\n\n await instrumentRoot('root.tsx');\n\n // Check that the file was modified correctly\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n expect(modifiedContent).toContain(\n \"import { Outlet, isRouteErrorResponse } from 'react-router';\",\n );\n expect(modifiedContent).toContain(\n 'export function ErrorBoundary({ error })',\n );\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n expect(modifiedContent).toContain('if (isRouteErrorResponse(error))');\n });\n\n it('should add Sentry.captureException to existing function declaration ErrorBoundary', async () => {\n const srcFile = path.join(fixturesDir, 'with-function-error-boundary.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n });\n\n it('should add Sentry.captureException to existing variable declaration ErrorBoundary', async () => {\n const srcFile = path.join(fixturesDir, 'with-variable-error-boundary.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n // Now properly handles variable declaration ErrorBoundary\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n });\n\n it('should not modify file when ErrorBoundary already has Sentry.captureException', async () => {\n const srcFile = path.join(fixturesDir, 'with-sentry-error-boundary.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n // Should not add duplicate Sentry.captureException\n const captureExceptionOccurrences = (\n modifiedContent.match(/Sentry\\.captureException/g) || []\n ).length;\n expect(captureExceptionOccurrences).toBe(1);\n });\n\n it('should not add Sentry import when Sentry content already exists', async () => {\n const srcFile = path.join(fixturesDir, 'with-existing-sentry.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n // Should not duplicate Sentry imports\n const sentryImportOccurrences = (\n modifiedContent.match(/import.*@sentry\\/react-router/g) || []\n ).length;\n expect(sentryImportOccurrences).toBe(1);\n });\n\n it('should add isRouteErrorResponse import when not present and ErrorBoundary is added', async () => {\n const srcFile = path.join(fixturesDir, 'no-isrouteerrorresponse.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n \"import { Outlet, isRouteErrorResponse } from 'react-router';\",\n );\n expect(modifiedContent).toContain(\n 'export function ErrorBoundary({ error })',\n );\n });\n\n it('should not add duplicate isRouteErrorResponse import when already present', async () => {\n const srcFile = path.join(fixturesDir, 'with-isrouteerrorresponse.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n // Should not duplicate isRouteErrorResponse imports\n const isRouteErrorResponseOccurrences = (\n modifiedContent.match(/isRouteErrorResponse/g) || []\n ).length;\n expect(isRouteErrorResponseOccurrences).toBe(2); // One import, one usage in template\n });\n\n it('should handle ErrorBoundary with alternative function declaration syntax', async () => {\n const srcFile = path.join(\n fixturesDir,\n 'function-expression-error-boundary.tsx',\n );\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n });\n\n it('should handle function declaration with separate export', async () => {\n const srcFile = path.join(\n fixturesDir,\n 'function-declaration-separate-export.tsx',\n );\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n\n // Should preserve function declaration syntax\n expect(modifiedContent).toMatch(/function ErrorBoundary\\(/);\n expect(modifiedContent).toContain('export { ErrorBoundary }');\n });\n\n it('should handle ErrorBoundary with captureException imported directly', async () => {\n const srcFile = path.join(fixturesDir, 'with-direct-capture-exception.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n // Should not add duplicate captureException calls\n const captureExceptionOccurrences = (\n modifiedContent.match(/captureException/g) || []\n ).length;\n expect(captureExceptionOccurrences).toBe(2); // One import, one usage\n });\n\n it('should not modify an already properly configured file', async () => {\n const srcFile = path.join(fixturesDir, 'fully-configured.tsx');\n\n fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));\n\n await instrumentRoot('root.tsx');\n\n const modifiedContent = fs.readFileSync(\n path.join(appDir, 'root.tsx'),\n 'utf8',\n );\n\n // Should not add duplicate imports or modify existing Sentry configuration\n const sentryImportOccurrences = (\n modifiedContent.match(/import.*@sentry\\/react-router/g) || []\n ).length;\n expect(sentryImportOccurrences).toBe(1);\n\n const captureExceptionOccurrences = (\n modifiedContent.match(/Sentry\\.captureException/g) || []\n ).length;\n expect(captureExceptionOccurrences).toBe(1);\n\n const errorBoundaryOccurrences = (\n modifiedContent.match(/export function ErrorBoundary/g) || []\n ).length;\n expect(errorBoundaryOccurrences).toBe(1);\n\n expect(modifiedContent).toContain(\n \"import * as Sentry from '@sentry/react-router';\",\n );\n expect(modifiedContent).toContain(\n \"import { Outlet, isRouteErrorResponse } from 'react-router';\",\n );\n });\n});\n"]}