-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsourceMaps.test.ts
139 lines (130 loc) · 4.03 KB
/
sourceMaps.test.ts
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
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { SentryNuxtModuleOptions } from '../../src/common/types';
import { getPluginOptions } from '../../src/vite/sourceMaps';
describe('getPluginOptions', () => {
beforeEach(() => {
vi.resetModules();
process.env = {};
});
it('uses environment variables when no moduleOptions are provided', () => {
const defaultEnv = {
SENTRY_ORG: 'default-org',
SENTRY_PROJECT: 'default-project',
SENTRY_AUTH_TOKEN: 'default-token',
};
process.env = { ...defaultEnv };
const options = getPluginOptions({} as SentryNuxtModuleOptions);
expect(options).toEqual(
expect.objectContaining({
org: 'default-org',
project: 'default-project',
authToken: 'default-token',
telemetry: true,
sourcemaps: expect.objectContaining({
rewriteSources: expect.any(Function),
}),
_metaOptions: expect.objectContaining({
telemetry: expect.objectContaining({
metaFramework: 'nuxt',
}),
}),
debug: false,
}),
);
});
it('returns default options when no moduleOptions are provided', () => {
const options = getPluginOptions({} as SentryNuxtModuleOptions);
expect(options.org).toBeUndefined();
expect(options.project).toBeUndefined();
expect(options.authToken).toBeUndefined();
expect(options).toEqual(
expect.objectContaining({
telemetry: true,
sourcemaps: expect.objectContaining({
rewriteSources: expect.any(Function),
}),
_metaOptions: expect.objectContaining({
telemetry: expect.objectContaining({
metaFramework: 'nuxt',
}),
}),
debug: false,
}),
);
});
it('merges custom moduleOptions with default options', () => {
const customOptions: SentryNuxtModuleOptions = {
sourceMapsUploadOptions: {
org: 'custom-org',
project: 'custom-project',
authToken: 'custom-token',
telemetry: false,
sourcemaps: {
assets: ['custom-assets/**/*'],
ignore: ['ignore-this.js'],
filesToDeleteAfterUpload: ['delete-this.js'],
},
},
debug: true,
};
const options = getPluginOptions(customOptions);
expect(options).toEqual(
expect.objectContaining({
org: 'custom-org',
project: 'custom-project',
authToken: 'custom-token',
telemetry: false,
sourcemaps: expect.objectContaining({
assets: ['custom-assets/**/*'],
ignore: ['ignore-this.js'],
filesToDeleteAfterUpload: ['delete-this.js'],
rewriteSources: expect.any(Function),
}),
_metaOptions: expect.objectContaining({
telemetry: expect.objectContaining({
metaFramework: 'nuxt',
}),
}),
debug: true,
}),
);
});
it('overrides options that were undefined with options from unstable_sentryRollupPluginOptions', () => {
const customOptions: SentryNuxtModuleOptions = {
sourceMapsUploadOptions: {
org: 'custom-org',
project: 'custom-project',
sourcemaps: {
assets: ['custom-assets/**/*'],
filesToDeleteAfterUpload: ['delete-this.js'],
},
},
debug: true,
unstable_sentryBundlerPluginOptions: {
org: 'unstable-org',
sourcemaps: {
assets: ['unstable-assets/**/*'],
},
release: {
name: 'test-release',
},
},
};
const options = getPluginOptions(customOptions);
expect(options).toEqual(
expect.objectContaining({
debug: true,
org: 'unstable-org',
project: 'custom-project',
sourcemaps: expect.objectContaining({
assets: ['unstable-assets/**/*'],
filesToDeleteAfterUpload: ['delete-this.js'],
rewriteSources: expect.any(Function),
}),
release: expect.objectContaining({
name: 'test-release',
}),
}),
);
});
});