-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(astro): Switch to explicit vitest imports (#13093)
As per https://vitest.dev/config/#globals > By default, vitest does not provide global APIs for explicitness I think we should follow vitest defaults here and explicitly import in the APIs that we need. This refactors our Astro SDK tests to do so. I also went ahead and fixed up some TS errors in some tests. This change also removes `environment: 'jsdom'` from the vite config as it seems nothing needs this for astro. This should means that our tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour.
- Loading branch information
1 parent
71af30f
commit b7e62c4
Showing
7 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import type { BrowserClient } from '@sentry/browser'; | ||
import { | ||
browserTracingIntegration, | ||
|
@@ -8,9 +10,8 @@ import { | |
} from '@sentry/browser'; | ||
import * as SentryBrowser from '@sentry/browser'; | ||
import { SDK_VERSION, getClient } from '@sentry/browser'; | ||
import { vi } from 'vitest'; | ||
|
||
import { init } from '../../../astro/src/client/sdk'; | ||
import { init } from '../../src/client/sdk'; | ||
|
||
const browserInit = vi.spyOn(SentryBrowser, 'init'); | ||
|
||
|
@@ -66,7 +67,7 @@ describe('Sentry client SDK', () => { | |
...tracingOptions, | ||
}); | ||
|
||
const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations; | ||
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations; | ||
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing'); | ||
|
||
expect(integrationsToInit).toContainEqual(expect.objectContaining({ name: 'BrowserTracing' })); | ||
|
@@ -82,28 +83,28 @@ describe('Sentry client SDK', () => { | |
...tracingOptions, | ||
}); | ||
|
||
const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations || []; | ||
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || []; | ||
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing'); | ||
|
||
expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' })); | ||
expect(browserTracing).toBeUndefined(); | ||
}); | ||
|
||
it("doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => { | ||
globalThis.__SENTRY_TRACING__ = false; | ||
(globalThis as any).__SENTRY_TRACING__ = false; | ||
|
||
init({ | ||
dsn: 'https://[email protected]/1337', | ||
enableTracing: true, | ||
}); | ||
|
||
const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations || []; | ||
const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || []; | ||
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing'); | ||
|
||
expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' })); | ||
expect(browserTracing).toBeUndefined(); | ||
|
||
delete globalThis.__SENTRY_TRACING__; | ||
delete (globalThis as any).__SENTRY_TRACING__; | ||
}); | ||
|
||
it('Overrides the automatically default browserTracingIntegration instance with a a user-provided browserTracingIntegration instance', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,5 @@ export default { | |
...baseConfig, | ||
test: { | ||
...baseConfig.test, | ||
environment: 'jsdom', | ||
}, | ||
}; |