Skip to content

Commit cccaa88

Browse files
committed
feat(svelte): Add Basic Error and Performance instrumentation
Wraps Browser SDK functionality
1 parent 487810a commit cccaa88

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint": "run-s lint:prettier lint:eslint",
4444
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
4545
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
46-
"test": "jest --passWithNoTests",
46+
"test": "jest",
4747
"test:watch": "jest --watch"
4848
},
4949
"volta": {

packages/svelte/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default null;
1+
export * from '@sentry/browser';
2+
3+
export { init } from './sdk';

packages/svelte/src/sdk.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
2+
3+
/**
4+
* Inits the Svelte SDK
5+
*/
6+
export function init(options: BrowserOptions): void {
7+
options._metadata = options._metadata || {};
8+
options._metadata.sdk = {
9+
name: 'sentry.javascript.svelte',
10+
packages: [
11+
{
12+
name: 'npm:@sentry/svelte',
13+
version: SDK_VERSION,
14+
},
15+
],
16+
version: SDK_VERSION,
17+
};
18+
19+
browserInit(options);
20+
}

packages/svelte/test/sdk.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { init as svelteInit } from '../src/sdk';
2+
import { init as browserInitRaw, SDK_VERSION } from '@sentry/browser';
3+
4+
const browserInit = browserInitRaw as jest.Mock;
5+
jest.mock('@sentry/browser');
6+
7+
describe('Initialize Svelte SDk', () => {
8+
afterAll(() => {
9+
jest.clearAllMocks();
10+
});
11+
12+
it('has the correct metadata', () => {
13+
svelteInit({
14+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
15+
});
16+
17+
const expectedMetadata = {
18+
_metadata: {
19+
sdk: {
20+
name: 'sentry.javascript.svelte',
21+
packages: [{ name: 'npm:@sentry/svelte', version: SDK_VERSION }],
22+
version: SDK_VERSION,
23+
},
24+
},
25+
};
26+
27+
expect(browserInit).toHaveBeenCalledTimes(1);
28+
expect(browserInit).toHaveBeenCalledWith(expect.objectContaining(expectedMetadata));
29+
});
30+
});

0 commit comments

Comments
 (0)