Skip to content

Commit fbdd611

Browse files
committed
fix tests
1 parent c298879 commit fbdd611

File tree

6 files changed

+104
-103
lines changed

6 files changed

+104
-103
lines changed

packages/sveltekit/src/client/browserTracingIntegration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BrowserTracing as OriginalBrowserTracing } from '@sentry/svelte';
22
import { svelteKitRoutingInstrumentation } from './router';
33

44
/**
5-
* A custom BrowserTracing integration for Next.js.
5+
* A custom BrowserTracing integration for Sveltekit.
66
*/
77
export class BrowserTracing extends OriginalBrowserTracing {
88
public constructor(options?: ConstructorParameters<typeof OriginalBrowserTracing>[0]) {

packages/sveltekit/src/server/rewriteFramesIntegration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export const rewriteFramesIntegration = defineIntegration(customRewriteFramesInt
3131
* module name to the original file name correctly, leading to individual error groups for
3232
* each module. Removing the `module` field makes the grouping algorithm fall back to the
3333
* `filename` field, which is correctly resolved and hence grouping works as expected.
34+
*
35+
* Exported for tests only.
3436
*/
35-
function rewriteFramesIteratee(frame: StackFrame): StackFrame {
37+
export function rewriteFramesIteratee(frame: StackFrame): StackFrame {
3638
if (!frame.filename) {
3739
return frame;
3840
}

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ describe('Sentry client SDK', () => {
6161
...tracingOptions,
6262
});
6363

64-
const integrationsToInit = svelteInit.mock.calls[0][0].integrations;
6564
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
66-
67-
expect(integrationsToInit).toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
6865
expect(browserTracing).toBeDefined();
6966
});
7067

@@ -77,10 +74,7 @@ describe('Sentry client SDK', () => {
7774
...tracingOptions,
7875
});
7976

80-
const integrationsToInit = svelteInit.mock.calls[0][0].integrations;
8177
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
82-
83-
expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
8478
expect(browserTracing).toBeUndefined();
8579
});
8680

@@ -96,10 +90,7 @@ describe('Sentry client SDK', () => {
9690
enableTracing: true,
9791
});
9892

99-
const integrationsToInit = svelteInit.mock.calls[0][0].integrations;
10093
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
101-
102-
expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
10394
expect(browserTracing).toBeUndefined();
10495

10596
// @ts-expect-error this is fine in the test
@@ -113,12 +104,9 @@ describe('Sentry client SDK', () => {
113104
enableTracing: true,
114105
});
115106

116-
const integrationsToInit = svelteInit.mock.calls[0][0].integrations;
117-
118107
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
119108
const options = browserTracing.options;
120109

121-
expect(integrationsToInit).toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
122110
expect(browserTracing).toBeDefined();
123111

124112
// This shows that the user-configured options are still here
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { RewriteFrames } from '@sentry/integrations';
2+
import type { Event, StackFrame } from '@sentry/types';
3+
import { basename } from '@sentry/utils';
4+
5+
import { rewriteFramesIteratee } from '../../src/server/rewriteFramesIntegration';
6+
import type { GlobalWithSentryValues } from '../../src/vite/injectGlobalValues';
7+
8+
describe('rewriteFramesIteratee', () => {
9+
it('removes the module property from the frame', () => {
10+
const frame: StackFrame = {
11+
filename: '/some/path/to/server/chunks/3-ab34d22f.js',
12+
module: '3-ab34d22f.js',
13+
};
14+
15+
const result = rewriteFramesIteratee(frame);
16+
17+
expect(result).not.toHaveProperty('module');
18+
});
19+
20+
it('does the same filename modification as the default RewriteFrames iteratee if no output dir is available', () => {
21+
const frame: StackFrame = {
22+
filename: '/some/path/to/server/chunks/3-ab34d22f.js',
23+
lineno: 1,
24+
colno: 1,
25+
module: '3-ab34d22f.js',
26+
};
27+
28+
// eslint-disable-next-line deprecation/deprecation
29+
const originalRewriteFrames = new RewriteFrames();
30+
// eslint-disable-next-line deprecation/deprecation
31+
const rewriteFrames = new RewriteFrames({ iteratee: rewriteFramesIteratee });
32+
33+
const event: Event = {
34+
exception: {
35+
values: [
36+
{
37+
stacktrace: {
38+
frames: [frame],
39+
},
40+
},
41+
],
42+
},
43+
};
44+
45+
const originalResult = originalRewriteFrames.processEvent(event);
46+
const result = rewriteFrames.processEvent(event);
47+
48+
expect(result.exception?.values?.[0]?.stacktrace?.frames?.[0]).toEqual({
49+
filename: 'app:///3-ab34d22f.js',
50+
lineno: 1,
51+
colno: 1,
52+
});
53+
54+
expect(result).toStrictEqual(originalResult);
55+
});
56+
57+
it.each([
58+
['adapter-node', 'build', '/absolute/path/to/build/server/chunks/3-ab34d22f.js', 'app:///chunks/3-ab34d22f.js'],
59+
[
60+
'adapter-auto',
61+
'.svelte-kit/output',
62+
'/absolute/path/to/.svelte-kit/output/server/entries/pages/page.ts.js',
63+
'app:///entries/pages/page.ts.js',
64+
],
65+
])(
66+
'removes the absolut path to the server output dir, if the output dir is available (%s)',
67+
(_, outputDir, frameFilename, modifiedFilename) => {
68+
(globalThis as unknown as GlobalWithSentryValues).__sentry_sveltekit_output_dir = outputDir;
69+
70+
const frame: StackFrame = {
71+
filename: frameFilename,
72+
lineno: 1,
73+
colno: 1,
74+
module: basename(frameFilename),
75+
};
76+
77+
const result = rewriteFramesIteratee({ ...frame });
78+
79+
expect(result).toStrictEqual({
80+
filename: modifiedFilename,
81+
lineno: 1,
82+
colno: 1,
83+
});
84+
85+
delete (globalThis as unknown as GlobalWithSentryValues).__sentry_sveltekit_output_dir;
86+
},
87+
);
88+
});

packages/sveltekit/test/server/sdk.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as SentryNode from '@sentry/node';
2-
import { SDK_VERSION } from '@sentry/node';
2+
import type { NodeClient} from '@sentry/node';
3+
import { SDK_VERSION, getClient } from '@sentry/node';
34
import { GLOBAL_OBJ } from '@sentry/utils';
45

56
import { init } from '../../src/server/sdk';
@@ -46,5 +47,14 @@ describe('Sentry server SDK', () => {
4647
// @ts-expect-error need access to protected _tags attribute
4748
expect(currentScope._tags).toEqual({ runtime: 'node' });
4849
});
50+
51+
it('adds rewriteFramesIntegration by default', () => {
52+
init({
53+
dsn: 'https://[email protected]/1337',
54+
});
55+
56+
const rewriteFramesIntegration = getClient<NodeClient>()?.getIntegrationByName('RewriteFrames');
57+
expect(rewriteFramesIntegration).toBeDefined();
58+
});
4959
});
5060
});
Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { RewriteFrames } from '@sentry/integrations';
2-
import type { Event, StackFrame } from '@sentry/types';
3-
import { basename } from '@sentry/utils';
4-
5-
import type { GlobalWithSentryValues } from '../../src/server/utils';
6-
import { getTracePropagationData, rewriteFramesIteratee } from '../../src/server/utils';
1+
import { getTracePropagationData } from '../../src/server/utils';
72

83
const MOCK_REQUEST_EVENT: any = {
94
request: {
@@ -58,85 +53,3 @@ describe('getTracePropagationData', () => {
5853
expect(dynamicSamplingContext).toBeUndefined();
5954
});
6055
});
61-
62-
describe('rewriteFramesIteratee', () => {
63-
it('removes the module property from the frame', () => {
64-
const frame: StackFrame = {
65-
filename: '/some/path/to/server/chunks/3-ab34d22f.js',
66-
module: '3-ab34d22f.js',
67-
};
68-
69-
const result = rewriteFramesIteratee(frame);
70-
71-
expect(result).not.toHaveProperty('module');
72-
});
73-
74-
it('does the same filename modification as the default RewriteFrames iteratee if no output dir is available', () => {
75-
const frame: StackFrame = {
76-
filename: '/some/path/to/server/chunks/3-ab34d22f.js',
77-
lineno: 1,
78-
colno: 1,
79-
module: '3-ab34d22f.js',
80-
};
81-
82-
// eslint-disable-next-line deprecation/deprecation
83-
const originalRewriteFrames = new RewriteFrames();
84-
// eslint-disable-next-line deprecation/deprecation
85-
const rewriteFrames = new RewriteFrames({ iteratee: rewriteFramesIteratee });
86-
87-
const event: Event = {
88-
exception: {
89-
values: [
90-
{
91-
stacktrace: {
92-
frames: [frame],
93-
},
94-
},
95-
],
96-
},
97-
};
98-
99-
const originalResult = originalRewriteFrames.processEvent(event);
100-
const result = rewriteFrames.processEvent(event);
101-
102-
expect(result.exception?.values?.[0]?.stacktrace?.frames?.[0]).toEqual({
103-
filename: 'app:///3-ab34d22f.js',
104-
lineno: 1,
105-
colno: 1,
106-
});
107-
108-
expect(result).toStrictEqual(originalResult);
109-
});
110-
111-
it.each([
112-
['adapter-node', 'build', '/absolute/path/to/build/server/chunks/3-ab34d22f.js', 'app:///chunks/3-ab34d22f.js'],
113-
[
114-
'adapter-auto',
115-
'.svelte-kit/output',
116-
'/absolute/path/to/.svelte-kit/output/server/entries/pages/page.ts.js',
117-
'app:///entries/pages/page.ts.js',
118-
],
119-
])(
120-
'removes the absolut path to the server output dir, if the output dir is available (%s)',
121-
(_, outputDir, frameFilename, modifiedFilename) => {
122-
(globalThis as GlobalWithSentryValues).__sentry_sveltekit_output_dir = outputDir;
123-
124-
const frame: StackFrame = {
125-
filename: frameFilename,
126-
lineno: 1,
127-
colno: 1,
128-
module: basename(frameFilename),
129-
};
130-
131-
const result = rewriteFramesIteratee({ ...frame });
132-
133-
expect(result).toStrictEqual({
134-
filename: modifiedFilename,
135-
lineno: 1,
136-
colno: 1,
137-
});
138-
139-
delete (globalThis as GlobalWithSentryValues).__sentry_sveltekit_output_dir;
140-
},
141-
);
142-
});

0 commit comments

Comments
 (0)