Skip to content

Commit

Permalink
test(solid): Switch to explicit vitest imports (#13028)
Browse files Browse the repository at this point in the history
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 Solid SDK tests to do so.

ref #11084

This change also removes `environment: 'jsdom'` from the vite config as
it seems nothing needs this for solid. 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
AbhiPrasad authored Jul 24, 2024
1 parent 04a26a4 commit b2dded8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/solid/test/errorboundary.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import type * as SentryBrowser from '@sentry/browser';
import { createTransport, getCurrentScope, setCurrentClient } from '@sentry/core';
import { render } from '@solidjs/testing-library';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';

import { ErrorBoundary } from 'solid-js';
import { BrowserClient, withSentryErrorBoundary } from '../src';
Expand Down
3 changes: 2 additions & 1 deletion packages/solid/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { SDK_VERSION } from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';

import { vi } from 'vitest';
import { init as solidInit } from '../src/sdk';

const browserInit = vi.spyOn(SentryBrowser, 'init');
Expand Down
3 changes: 2 additions & 1 deletion packages/solid/test/solidrouter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { spanToJSON } from '@sentry/browser';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
Expand All @@ -10,7 +12,6 @@ import {
import type { MemoryHistory } from '@solidjs/router';
import { MemoryRouter, Navigate, Route, createMemoryHistory } from '@solidjs/router';
import { render } from '@solidjs/testing-library';
import { vi } from 'vitest';

import { BrowserClient } from '../src';
import { solidRouterBrowserTracingIntegration, withSentryRouterRouting } from '../src/solidrouter';
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["vitest/globals", "vite/client", "@testing-library/jest-dom"],
"types": ["vite/client", "@testing-library/jest-dom"],

// other package-specific, test-specific options
"jsx": "preserve",
Expand Down
1 change: 0 additions & 1 deletion packages/solid/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default {
plugins: [solidPlugin({ hot: !process.env.VITEST })],
test: {
...baseConfig.test,
environment: 'jsdom',
},
};

0 comments on commit b2dded8

Please sign in to comment.