|
1 | 1 | import { Transaction } from '@sentry/types';
|
2 |
| -import { getGlobalObject } from '@sentry/utils'; |
| 2 | +import { WINDOW } from '@sentry/utils'; |
3 | 3 | import { JSDOM } from 'jsdom';
|
4 | 4 | import { NEXT_DATA as NextData } from 'next/dist/next-server/lib/utils';
|
5 | 5 | import { default as Router } from 'next/router';
|
6 | 6 |
|
7 | 7 | import { nextRouterInstrumentation } from '../../src/performance/client';
|
8 | 8 |
|
9 |
| -const globalObject = getGlobalObject< |
10 |
| - Window & { |
11 |
| - __BUILD_MANIFEST?: { |
12 |
| - sortedPages?: string[]; |
13 |
| - }; |
14 |
| - } |
15 |
| ->(); |
| 9 | +const globalObject = WINDOW as typeof WINDOW & { |
| 10 | + __BUILD_MANIFEST?: { |
| 11 | + sortedPages?: string[]; |
| 12 | + }; |
| 13 | +}; |
16 | 14 |
|
17 | 15 | const originalBuildManifest = globalObject.__BUILD_MANIFEST;
|
18 | 16 | const originalBuildManifestRoutes = globalObject.__BUILD_MANIFEST?.sortedPages;
|
@@ -60,8 +58,8 @@ function createMockStartTransaction() {
|
60 | 58 | }
|
61 | 59 |
|
62 | 60 | describe('nextRouterInstrumentation', () => {
|
63 |
| - const originalGlobalDocument = getGlobalObject<Window>().document; |
64 |
| - const originalGlobalLocation = getGlobalObject<Window>().location; |
| 61 | + const originalGlobalDocument = WINDOW.document; |
| 62 | + const originalGlobalLocation = WINDOW.location; |
65 | 63 |
|
66 | 64 | function setUpNextPage(pageProperties: {
|
67 | 65 | url: string;
|
@@ -93,25 +91,25 @@ describe('nextRouterInstrumentation', () => {
|
93 | 91 | // The Next.js routing instrumentations requires a few things to be present on pageload:
|
94 | 92 | // 1. Access to window.document API for `window.document.getElementById`
|
95 | 93 | // 2. Access to window.location API for `window.location.pathname`
|
96 |
| - Object.defineProperty(global, 'document', { value: dom.window.document, writable: true }); |
97 |
| - Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true }); |
| 94 | + Object.defineProperty(WINDOW, 'document', { value: dom.window.document, writable: true }); |
| 95 | + Object.defineProperty(WINDOW, 'location', { value: dom.window.document.location, writable: true }); |
98 | 96 |
|
99 | 97 | // Define Next.js clientside build manifest with navigatable routes
|
100 |
| - (global as any).__BUILD_MANIFEST = { |
101 |
| - ...(global as any).__BUILD_MANIFEST, |
102 |
| - sortedPages: pageProperties.navigatableRoutes, |
| 98 | + globalObject.__BUILD_MANIFEST = { |
| 99 | + ...globalObject.__BUILD_MANIFEST, |
| 100 | + sortedPages: pageProperties.navigatableRoutes as string[], |
103 | 101 | };
|
104 | 102 | }
|
105 | 103 |
|
106 | 104 | afterEach(() => {
|
107 | 105 | // Clean up JSDom
|
108 |
| - Object.defineProperty(global, 'document', { value: originalGlobalDocument }); |
109 |
| - Object.defineProperty(global, 'location', { value: originalGlobalLocation }); |
| 106 | + Object.defineProperty(WINDOW, 'document', { value: originalGlobalDocument }); |
| 107 | + Object.defineProperty(WINDOW, 'location', { value: originalGlobalLocation }); |
110 | 108 |
|
111 | 109 | // Reset Next.js' __BUILD_MANIFEST
|
112 |
| - (global as any).__BUILD_MANIFEST = originalBuildManifest; |
113 |
| - if ((global as any).__BUILD_MANIFEST) { |
114 |
| - (global as any).__BUILD_MANIFEST.sortedPages = originalBuildManifestRoutes; |
| 110 | + globalObject.__BUILD_MANIFEST = originalBuildManifest; |
| 111 | + if (globalObject.__BUILD_MANIFEST) { |
| 112 | + globalObject.__BUILD_MANIFEST.sortedPages = originalBuildManifestRoutes as string[]; |
115 | 113 | }
|
116 | 114 |
|
117 | 115 | // Clear all event handlers
|
|
0 commit comments