Skip to content

Commit 44e8038

Browse files
authored
test(sveltekit): Switch to explicit vitest imports (#12960)
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 SvelteKit SDK tests to do so. This change also removes `environment: 'jsdom'` from the sveltekit global vite config in favour of explicitly adding jsdom environment via the `@vitest-environment` pragma to the specific test file that needs it. This should means that our server tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour.
1 parent 27b3a3e commit 44e8038

20 files changed

+44
-20
lines changed

packages/sveltekit/test/client/browserTracingIntegration.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
15
/* eslint-disable @typescript-eslint/unbound-method */
6+
import { beforeEach, describe, expect, it, vi } from 'vitest';
7+
28
import type { Span } from '@sentry/types';
39
import { writable } from 'svelte/store';
4-
import { vi } from 'vitest';
510

611
import { navigating, page } from '$app/stores';
712

packages/sveltekit/test/client/fetch.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { beforeEach, describe, expect, it } from 'vitest';
6+
17
import { init } from '../../src/client/index';
28

39
describe('instruments fetch', () => {

packages/sveltekit/test/client/handleError.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
13
import * as SentrySvelte from '@sentry/svelte';
24
import type { HandleClientError, NavigationEvent } from '@sveltejs/kit';
3-
import { vi } from 'vitest';
45

56
import { handleErrorWithSentry } from '../../src/client/handleError';
67

packages/sveltekit/test/client/load.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
13
import * as SentrySvelte from '@sentry/svelte';
24
import type { Load } from '@sveltejs/kit';
35
import { redirect } from '@sveltejs/kit';
4-
import { vi } from 'vitest';
56

67
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
78
import { wrapLoadWithSentry } from '../../src/client/load';

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
13
import type { BrowserClient } from '@sentry/svelte';
24
import * as SentrySvelte from '@sentry/svelte';
35
import { SDK_VERSION, getClient, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/svelte';
4-
import { vi } from 'vitest';
56

67
import { init } from '../../src/client';
78

packages/sveltekit/test/common/utils.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { isHttpError, isRedirect } from '../../src/common/utils';
24

35
describe('isRedirect', () => {

packages/sveltekit/test/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import * as SentryClient from '../src/client';
24
import * as SentryServer from '../src/server';
35

packages/sveltekit/test/server/handle.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { beforeEach, describe, expect, it } from 'vitest';
2+
13
import {
24
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
35
getRootSpan,

packages/sveltekit/test/server/handleError.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
13
import * as SentryNode from '@sentry/node';
24
import type { HandleServerError, RequestEvent } from '@sveltejs/kit';
3-
import { vi } from 'vitest';
45

56
import { handleErrorWithSentry } from '../../src/server/handleError';
67

packages/sveltekit/test/server/load.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
13
import {
24
SEMANTIC_ATTRIBUTE_SENTRY_OP,
35
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -8,7 +10,6 @@ import * as SentryNode from '@sentry/node';
810
import type { Event } from '@sentry/types';
911
import type { Load, ServerLoad } from '@sveltejs/kit';
1012
import { error, redirect } from '@sveltejs/kit';
11-
import { vi } from 'vitest';
1213

1314
import { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../../src/server/load';
1415
import { getDefaultNodeClientOptions } from '../utils';

0 commit comments

Comments
 (0)