-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathwithSentry.test.ts
More file actions
149 lines (137 loc) · 4.77 KB
/
withSentry.test.ts
File metadata and controls
149 lines (137 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import type { Nitro } from 'nitropack';
import type { Plugin } from 'vite';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { withSentry } from '../../src/config';
const userDefinedNitroRollupBeforeHookMock = vi.fn();
const userDefinedNitroCloseHookMock = vi.fn();
const addInstrumentationFileToBuildMock = vi.fn();
const addSentryTopImportMock = vi.fn();
vi.mock('../../src/config/addInstrumentation', () => ({
addInstrumentationFileToBuild: (...args: unknown[]) => addInstrumentationFileToBuildMock(...args),
addSentryTopImport: (...args: unknown[]) => addSentryTopImportMock(...args),
}));
beforeEach(() => {
vi.clearAllMocks();
});
describe('withSentry()', () => {
const solidStartConfig = {
middleware: './src/middleware.ts',
server: {
hooks: {
close: userDefinedNitroCloseHookMock,
'rollup:before': userDefinedNitroRollupBeforeHookMock,
},
},
};
const nitroOptions: Nitro = {
options: {
buildDir: '/path/to/buildDir',
output: {
serverDir: '/path/to/serverDir',
},
preset: 'vercel',
},
};
it('adds a nitro hook to add the instrumentation file to the build if no plugin options are provided', async () => {
const config = withSentry(solidStartConfig, {});
await config?.server.hooks['rollup:before'](nitroOptions);
expect(addInstrumentationFileToBuildMock).toHaveBeenCalledWith(nitroOptions);
expect(userDefinedNitroRollupBeforeHookMock).toHaveBeenCalledWith(nitroOptions);
});
it('adds a nitro hook to add the instrumentation file as top level import to the server entry file when configured in autoInjectServerSentry', async () => {
const config = withSentry(solidStartConfig, { autoInjectServerSentry: 'top-level-import' });
await config?.server.hooks['rollup:before'](nitroOptions);
await config?.server.hooks['close'](nitroOptions);
expect(addSentryTopImportMock).toHaveBeenCalledWith(
expect.objectContaining({
options: {
buildDir: '/path/to/buildDir',
output: {
serverDir: '/path/to/serverDir',
},
preset: 'vercel',
},
}),
);
expect(userDefinedNitroCloseHookMock).toHaveBeenCalled();
});
it('does not add the instrumentation file as top level import if autoInjectServerSentry is undefined', async () => {
const config = withSentry(solidStartConfig, { autoInjectServerSentry: undefined });
await config?.server.hooks['rollup:before'](nitroOptions);
await config?.server.hooks['close'](nitroOptions);
expect(addSentryTopImportMock).not.toHaveBeenCalled();
expect(userDefinedNitroCloseHookMock).toHaveBeenCalled();
});
it('adds the sentry solidstart vite plugin', () => {
const config = withSentry(solidStartConfig, {
project: 'project',
org: 'org',
authToken: 'token',
});
const names = config?.vite.plugins.flat().map((plugin: Plugin) => plugin.name);
expect(names).toEqual([
'sentry-solidstart-build-instrumentation-file',
'sentry-telemetry-plugin',
'sentry-vite-injection-plugin',
'sentry-release-management-plugin',
'sentry-vite-debug-id-upload-plugin',
'sentry-file-deletion-plugin',
'sentry-solidstart-update-source-map-setting',
]);
});
it('extends the passed in vite config object', () => {
const config = withSentry(
{
...solidStartConfig,
vite: {
plugins: [{ name: 'my-test-plugin' }],
},
},
{
project: 'project',
org: 'org',
authToken: 'token',
},
);
const names = config?.vite.plugins.flat().map((plugin: Plugin) => plugin.name);
expect(names).toEqual([
'sentry-solidstart-build-instrumentation-file',
'sentry-telemetry-plugin',
'sentry-vite-injection-plugin',
'sentry-release-management-plugin',
'sentry-vite-debug-id-upload-plugin',
'sentry-file-deletion-plugin',
'sentry-solidstart-update-source-map-setting',
'my-test-plugin',
]);
});
it('extends the passed in vite function config', () => {
const config = withSentry(
{
...solidStartConfig,
vite() {
return { plugins: [{ name: 'my-test-plugin' }] };
},
},
{
project: 'project',
org: 'org',
authToken: 'token',
},
);
const names = config
?.vite()
.plugins.flat()
.map((plugin: Plugin) => plugin.name);
expect(names).toEqual([
'sentry-solidstart-build-instrumentation-file',
'sentry-telemetry-plugin',
'sentry-vite-injection-plugin',
'sentry-release-management-plugin',
'sentry-vite-debug-id-upload-plugin',
'sentry-file-deletion-plugin',
'sentry-solidstart-update-source-map-setting',
'my-test-plugin',
]);
});
});