Skip to content

Commit b78c4cd

Browse files
committed
update @sentry/svelte to us vitest
1 parent bae57d3 commit b78c4cd

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

packages/svelte/jest.config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/svelte/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
},
5555
"devDependencies": {
5656
"@testing-library/svelte": "^3.2.1",
57-
"svelte": "3.49.0",
58-
"svelte-jester": "^2.3.2"
57+
"@sveltejs/vite-plugin-svelte": "latest",
58+
"svelte": "3.49.0"
5959
},
6060
"scripts": {
6161
"build": "run-p build:transpile build:types",
@@ -73,8 +73,8 @@
7373
"clean": "rimraf build coverage sentry-svelte-*.tgz",
7474
"fix": "eslint . --format stylish --fix",
7575
"lint": "eslint . --format stylish",
76-
"test": "jest",
77-
"test:watch": "jest --watch",
76+
"test": "vitest",
77+
"test:watch": "vitest --watch",
7878
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push --sig"
7979
},
8080
"volta": {

packages/svelte/test/performance.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ import { act, render } from '@testing-library/svelte';
33

44
// linter doesn't like Svelte component imports
55
import DummyComponent from './components/Dummy.svelte';
6+
import { vi } from 'vitest';
67

78
let returnUndefinedTransaction = false;
89

910
const testTransaction: { spans: any[]; startChild: jest.Mock; end: jest.Mock; isRecording: () => boolean } = {
1011
spans: [],
11-
startChild: jest.fn(),
12-
end: jest.fn(),
12+
startChild: vi.fn(),
13+
end: vi.fn(),
1314
isRecording: () => true,
1415
};
15-
const testUpdateSpan = { end: jest.fn() };
16+
const testUpdateSpan = { end: vi.fn() };
1617
const testInitSpan: any = {
1718
transaction: testTransaction,
18-
end: jest.fn(),
19-
startChild: jest.fn(),
19+
end: vi.fn(),
20+
startChild: vi.fn(),
2021
isRecording: () => true,
2122
};
2223

23-
jest.mock('@sentry/core', () => {
24-
const original = jest.requireActual('@sentry/core');
24+
vi.mock('@sentry/core', () => {
25+
const original = vi.importActual('@sentry/core');
2526
return {
2627
...original,
2728
getCurrentScope(): Scope {
@@ -36,7 +37,7 @@ jest.mock('@sentry/core', () => {
3637

3738
describe('Sentry.trackComponent()', () => {
3839
beforeEach(() => {
39-
jest.resetAllMocks();
40+
vi.resetAllMocks();
4041
testTransaction.spans = [];
4142

4243
testTransaction.startChild.mockImplementation(spanCtx => {
@@ -49,7 +50,7 @@ describe('Sentry.trackComponent()', () => {
4950
return testUpdateSpan;
5051
});
5152

52-
testInitSpan.end = jest.fn();
53+
testInitSpan.end = vi.fn();
5354
testInitSpan.isRecording = () => true;
5455
returnUndefinedTransaction = false;
5556
});

packages/svelte/test/sdk.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import * as SentryBrowser from '@sentry/browser';
33
import type { EventProcessor } from '@sentry/types';
44

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

78
let passedEventProcessor: EventProcessor | undefined;
89

9-
const browserInit = jest.spyOn(SentryBrowser, 'init');
10-
const addEventProcessor = jest
10+
const browserInit = vi.spyOn(SentryBrowser, 'init');
11+
const addEventProcessor = vi
1112
.spyOn(SentryBrowser, 'addEventProcessor')
1213
.mockImplementation((eventProcessor: EventProcessor) => {
1314
passedEventProcessor = eventProcessor;
@@ -16,7 +17,7 @@ const addEventProcessor = jest
1617

1718
describe('Initialize Svelte SDk', () => {
1819
beforeEach(() => {
19-
jest.clearAllMocks();
20+
vi.clearAllMocks();
2021
});
2122

2223
it('has the correct metadata', () => {
@@ -74,7 +75,7 @@ describe('Initialize Svelte SDk', () => {
7475
describe('detectAndReportSvelteKit()', () => {
7576
const originalHtmlBody = document.body.innerHTML;
7677
beforeEach(() => {
77-
jest.clearAllMocks();
78+
vi.clearAllMocks();
7879
document.body.innerHTML = originalHtmlBody;
7980
passedEventProcessor = undefined;
8081
});

packages/svelte/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { UserConfig } from 'vitest';
2+
import { svelte } from '@sveltejs/vite-plugin-svelte';
3+
import baseConfig from '../../vite/vite.config';
4+
5+
export default {
6+
...baseConfig,
7+
plugins: [
8+
svelte({ hot: !process.env.VITEST }),
9+
],
10+
test: {
11+
// test exists, no idea why TS doesn't recognize it
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13+
...(baseConfig as UserConfig & { test: any }).test,
14+
environment: 'jsdom',
15+
},
16+
};

0 commit comments

Comments
 (0)