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(svelte): Switch to explicit vitest imports #13026

Merged
merged 1 commit into from
Jul 24, 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
2 changes: 2 additions & 0 deletions packages/svelte/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { withSentryConfig } from '../src/config';
import { FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID, componentTrackingPreprocessor } from '../src/preprocessors';
import type { SentryPreprocessorGroup, SentrySvelteConfigOptions, SvelteConfig } from '../src/types';
Expand Down
24 changes: 15 additions & 9 deletions packages/svelte/test/performance.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* @vitest-environment jsdom
*/

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

import { act, render } from '@testing-library/svelte';
import { getClient, getCurrentScope, getIsolationScope, init, startSpan } from '../src';

import type { TransactionEvent } from '@sentry/types';
import { vi } from 'vitest';
// linter doesn't like Svelte component imports

// @ts-expect-error svelte import
import DummyComponent from './components/Dummy.svelte';

const PUBLIC_DSN = 'https://username@domain/123';
Expand Down Expand Up @@ -40,7 +46,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(2);

const rootSpanId = transaction.contexts?.trace?.span_id;
Expand Down Expand Up @@ -95,7 +101,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(3);

const rootSpanId = transaction.contexts?.trace?.span_id;
Expand Down Expand Up @@ -159,7 +165,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(1);

expect(transaction.spans![0]?.op).toEqual('ui.svelte.init');
Expand All @@ -175,7 +181,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(1);

expect(transaction.spans![0]?.op).toEqual('ui.svelte.update');
Expand All @@ -191,7 +197,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(0);
});

Expand All @@ -207,7 +213,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;
expect(transaction.spans).toHaveLength(2);

expect(transaction.spans![0]?.description).toEqual('<CustomComponentName>');
Expand Down Expand Up @@ -238,7 +244,7 @@ describe('Sentry.trackComponent()', () => {
await getClient()?.flush();

expect(transactions).toHaveLength(1);
const transaction = transactions[0];
const transaction = transactions[0]!;

// One update span is triggered by the initial rendering, but the second one is not captured
expect(transaction.spans).toHaveLength(2);
Expand Down
10 changes: 6 additions & 4 deletions packages/svelte/test/preprocessors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import * as svelteCompiler from 'svelte/compiler';

import {
Expand Down Expand Up @@ -117,9 +119,9 @@ describe('componentTrackingPreprocessor', () => {
return { ...cmp, newCode: res.code, map: res.map };
});

expect(cmp2.newCode).toEqual(cmp2.originalCode);
expect(cmp2?.newCode).toEqual(cmp2?.originalCode);

expectComponentCodeToBeModified([cmp1, cmp3], { trackInit: true, trackUpdates: true });
expectComponentCodeToBeModified([cmp1!, cmp3!], { trackInit: true, trackUpdates: true });
});

it('doesnt inject the function call to the same component more than once', () => {
Expand Down Expand Up @@ -155,8 +157,8 @@ describe('componentTrackingPreprocessor', () => {
return { ...cmp, newCode: res.code, map: res.map };
});

expectComponentCodeToBeModified([cmp11, cmp2], { trackInit: true, trackUpdates: true });
expect(cmp12.newCode).toEqual(cmp12.originalCode);
expectComponentCodeToBeModified([cmp11!, cmp2!], { trackInit: true, trackUpdates: true });
expect(cmp12!.newCode).toEqual(cmp12!.originalCode);
});

it('doesnt inject the function call to a module context script block', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/svelte/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* @vitest-environment jsdom
*/

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

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

import { vi } from 'vitest';
import { detectAndReportSvelteKit, init as svelteInit, isSvelteKitApp } from '../src/sdk';

let passedEventProcessor: EventProcessor | undefined;
Expand Down
3 changes: 0 additions & 3 deletions packages/svelte/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"include": ["test/**/*", "vite.config.ts"],

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["vitest/globals"]

// other package-specific, test-specific options
}
}
1 change: 0 additions & 1 deletion packages/svelte/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default {
plugins: [svelte({ hot: !process.env.VITEST })],
test: {
...baseConfig.test,
environment: 'jsdom',
alias: [{ find: /^svelte$/, replacement: 'svelte/internal' }],
},
};
Loading