Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sveltekit): Switch to explicit vitest imports #12960

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* @vitest-environment jsdom
*/

/* eslint-disable @typescript-eslint/unbound-method */
import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { Span } from '@sentry/types';
import { writable } from 'svelte/store';
import { vi } from 'vitest';

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

Expand Down
6 changes: 6 additions & 0 deletions packages/sveltekit/test/client/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it } from 'vitest';

import { init } from '../../src/client/index';

describe('instruments fetch', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/client/handleError.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import * as SentrySvelte from '@sentry/svelte';
import type { HandleClientError, NavigationEvent } from '@sveltejs/kit';
import { vi } from 'vitest';

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

Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/client/load.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 * as SentrySvelte from '@sentry/svelte';
import type { Load } from '@sveltejs/kit';
import { redirect } from '@sveltejs/kit';
import { vi } from 'vitest';

import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { wrapLoadWithSentry } from '../../src/client/load';
Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import type { BrowserClient } from '@sentry/svelte';
import * as SentrySvelte from '@sentry/svelte';
import { SDK_VERSION, getClient, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/svelte';
import { vi } from 'vitest';

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

Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/common/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { isHttpError, isRedirect } from '../../src/common/utils';

describe('isRedirect', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import * as SentryClient from '../src/client';
import * as SentryServer from '../src/server';

Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/server/handle.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeEach, describe, expect, it } from 'vitest';

import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
getRootSpan,
Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/server/handleError.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import * as SentryNode from '@sentry/node';
import type { HandleServerError, RequestEvent } from '@sveltejs/kit';
import { vi } from 'vitest';

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

Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/server/load.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Expand All @@ -8,7 +10,6 @@ import * as SentryNode from '@sentry/node';
import type { Event } from '@sentry/types';
import type { Load, ServerLoad } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import { vi } from 'vitest';

import { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../../src/server/load';
import { getDefaultNodeClientOptions } from '../utils';
Expand Down
3 changes: 2 additions & 1 deletion packages/sveltekit/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import * as SentryNode from '@sentry/node';
import type { NodeClient } from '@sentry/node';
import { SDK_VERSION, getClient } from '@sentry/node';

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

const nodeInit = vi.spyOn(SentryNode, 'init');
Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/server/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { getTracePropagationData } from '../../src/server/utils';

const MOCK_REQUEST_EVENT: any = {
Expand Down
3 changes: 1 addition & 2 deletions packages/sveltekit/test/vite/autoInstrument.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { canWrapLoad, makeAutoInstrumentationPlugin } from '../../src/vite/autoInstrument';

Expand All @@ -12,7 +12,6 @@ let fileContent: string | undefined;
vi.mock('fs', async () => {
const actual = await vi.importActual('fs');
return {
// @ts-expect-error this exists, I promise!
...actual,
promises: {
// @ts-expect-error this also exists, I promise!
Expand Down
4 changes: 2 additions & 2 deletions packages/sveltekit/test/vite/detectAdapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { detectAdapter } from '../../src/vite/detectAdapter';

let existsFile = true;
const pkgJson = {
dependencies: {},
dependencies: {} as Record<string, string>,
};
describe('detectAdapter', () => {
beforeEach(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/vite/injectGlobalValues.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { getGlobalValueInjectionCode } from '../../src/vite/injectGlobalValues';

describe('getGlobalValueInjectionCode', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import type { Plugin } from 'vite';
import * as autoInstrument from '../../src/vite/autoInstrument';
Expand All @@ -8,7 +8,6 @@ import * as sourceMaps from '../../src/vite/sourceMaps';
vi.mock('fs', async () => {
const actual = await vi.importActual('fs');
return {
// @ts-expect-error this exists, I promise!
...actual,
promises: {
// @ts-expect-error this also exists, I promise!
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/test/vite/sourceMaps.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { Plugin } from 'vite';
import { makeCustomSentryVitePlugins } from '../../src/vite/sourceMaps';
Expand Down
8 changes: 4 additions & 4 deletions packages/sveltekit/test/vite/svelteConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { SupportedSvelteKitAdapters } from '../../src/vite/detectAdapter';
import { getAdapterOutputDir, getHooksFileName, loadSvelteConfig } from '../../src/vite/svelteConfig';

let existsFile;
let existsFile: any;

describe('loadSvelteConfig', () => {
vi.mock('fs', () => {
Expand All @@ -25,7 +25,7 @@ describe('loadSvelteConfig', () => {
// url apparently doesn't exist in the test environment, therefore we mock it:
vi.mock('url', () => {
return {
pathToFileURL: path => {
pathToFileURL: (path: string) => {
return {
href: path,
};
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('loadSvelteConfig', () => {
describe('getAdapterOutputDir', () => {
const mockedAdapter = {
name: 'mocked-adapter',
adapt(builder) {
adapt(builder: any) {
builder.writeClient('customBuildDir');
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node", "vitest/globals"]
"types": ["node"]
}
}
1 change: 0 additions & 1 deletion packages/sveltekit/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default {
// test exists, no idea why TS doesn't recognize it
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(baseConfig as UserConfig & { test: any }).test,
environment: 'jsdom',
setupFiles: ['./test/vitest.setup.ts'],
alias: [
{
Expand Down
Loading