|
1 | | -import { init, SDK_VERSION } from '@sentry/react'; |
2 | | -import { Integrations } from '@sentry/tracing'; |
| 1 | +import { BrowserTracing, init, SDK_VERSION } from '@sentry/react'; |
3 | 2 | import type { Integration } from '@sentry/types'; |
4 | 3 |
|
5 | 4 | import { init as gatsbyInit } from '../src/sdk'; |
@@ -58,79 +57,48 @@ describe('Initialize React SDK', () => { |
58 | 57 | }); |
59 | 58 | }); |
60 | 59 |
|
| 60 | +type TestArgs = [string, Integration[], GatsbyOptions, string[]]; |
| 61 | + |
61 | 62 | describe('Integrations from options', () => { |
62 | 63 | afterEach(() => reactInit.mockClear()); |
63 | 64 |
|
64 | 65 | test.each([ |
65 | 66 | ['tracing disabled, no integrations', [], {}, []], |
66 | 67 | ['tracing enabled, no integrations', [], { tracesSampleRate: 1 }, ['BrowserTracing']], |
67 | 68 | [ |
68 | | - 'tracing disabled, with Integrations.BrowserTracing as an array', |
| 69 | + 'tracing disabled, with BrowserTracing as an array', |
69 | 70 | [], |
70 | | - { integrations: [new Integrations.BrowserTracing()] }, |
| 71 | + { integrations: [new BrowserTracing()] }, |
71 | 72 | ['BrowserTracing'], |
72 | 73 | ], |
73 | 74 | [ |
74 | | - 'tracing disabled, with Integrations.BrowserTracing as a function', |
| 75 | + 'tracing disabled, with BrowserTracing as a function', |
75 | 76 | [], |
76 | 77 | { |
77 | | - integrations: () => [new Integrations.BrowserTracing()], |
| 78 | + integrations: () => [new BrowserTracing()], |
78 | 79 | }, |
79 | 80 | ['BrowserTracing'], |
80 | 81 | ], |
81 | 82 | [ |
82 | | - 'tracing enabled, with Integrations.BrowserTracing as an array', |
| 83 | + 'tracing enabled, with BrowserTracing as an array', |
83 | 84 | [], |
84 | | - { tracesSampleRate: 1, integrations: [new Integrations.BrowserTracing()] }, |
| 85 | + { tracesSampleRate: 1, integrations: [new BrowserTracing()] }, |
85 | 86 | ['BrowserTracing'], |
86 | 87 | ], |
87 | 88 | [ |
88 | | - 'tracing enabled, with Integrations.BrowserTracing as a function', |
| 89 | + 'tracing enabled, with BrowserTracing as a function', |
89 | 90 | [], |
90 | | - { tracesSampleRate: 1, integrations: () => [new Integrations.BrowserTracing()] }, |
| 91 | + { tracesSampleRate: 1, integrations: () => [new BrowserTracing()] }, |
91 | 92 | ['BrowserTracing'], |
92 | 93 | ], |
93 | | - [ |
94 | | - 'tracing enabled, with another integration as an array', |
95 | | - [], |
96 | | - { tracesSampleRate: 1, integrations: [new Integrations.Express()] }, |
97 | | - ['Express', 'BrowserTracing'], |
98 | | - ], |
99 | | - [ |
100 | | - 'tracing enabled, with another integration as a function', |
101 | | - [], |
102 | | - { tracesSampleRate: 1, integrations: () => [new Integrations.Express()] }, |
103 | | - ['Express', 'BrowserTracing'], |
104 | | - ], |
105 | | - [ |
106 | | - 'tracing disabled, with another integration as an array', |
107 | | - [], |
108 | | - { integrations: [new Integrations.Express()] }, |
109 | | - ['Express'], |
110 | | - ], |
111 | | - [ |
112 | | - 'tracing disabled, with another integration as a function', |
113 | | - [], |
114 | | - { integrations: () => [new Integrations.Express()] }, |
115 | | - ['Express'], |
116 | | - ], |
117 | | - [ |
118 | | - 'merges integrations with user integrations as a function', |
119 | | - [new Integrations.Mongo()], |
120 | | - { |
121 | | - tracesSampleRate: 1, |
122 | | - integrations: (defaultIntegrations: Integration[]): Integration[] => [ |
123 | | - ...defaultIntegrations, |
124 | | - new Integrations.Express(), |
125 | | - ], |
126 | | - }, |
127 | | - ['Mongo', 'Express', 'BrowserTracing'], |
128 | | - ], |
129 | | - ])('%s', (_testName, defaultIntegrations: Integration[], options: GatsbyOptions, expectedIntNames: string[]) => { |
130 | | - gatsbyInit(options); |
131 | | - const integrations: UserIntegrations = reactInit.mock.calls[0][0].integrations; |
132 | | - const arrIntegrations = Array.isArray(integrations) ? integrations : integrations(defaultIntegrations); |
133 | | - expect(arrIntegrations).toHaveLength(expectedIntNames.length); |
134 | | - arrIntegrations.map((integration, idx) => expect(integration.name).toStrictEqual(expectedIntNames[idx])); |
135 | | - }); |
| 94 | + ] as TestArgs[])( |
| 95 | + '%s', |
| 96 | + (_testName, defaultIntegrations: Integration[], options: GatsbyOptions, expectedIntNames: string[]) => { |
| 97 | + gatsbyInit(options); |
| 98 | + const integrations: UserIntegrations = reactInit.mock.calls[0][0].integrations; |
| 99 | + const arrIntegrations = Array.isArray(integrations) ? integrations : integrations(defaultIntegrations); |
| 100 | + expect(arrIntegrations).toHaveLength(expectedIntNames.length); |
| 101 | + arrIntegrations.map((integration, idx) => expect(integration.name).toStrictEqual(expectedIntNames[idx])); |
| 102 | + }, |
| 103 | + ); |
136 | 104 | }); |
0 commit comments