1
+ import { SentryVitePluginOptions } from '@sentry/vite-plugin' ;
1
2
import { beforeEach , describe , expect , it , vi } from 'vitest' ;
2
3
import { makeSourceMapsVitePlugin } from '../../src/vite/sourceMaps' ;
3
- import * as sourceMaps from '../../src/vite/sourceMaps' ;
4
4
5
5
const mockedSentryVitePlugin = {
6
6
name : 'sentry-vite-debug-id-upload-plugin' ,
7
7
writeBundle : vi . fn ( ) ,
8
8
} ;
9
9
10
+ const sentryVitePluginSpy = vi . fn ( ( _options : SentryVitePluginOptions ) => [ mockedSentryVitePlugin ] ) ;
11
+
10
12
vi . mock ( '@sentry/vite-plugin' , async ( ) => {
11
13
const original = ( await vi . importActual ( '@sentry/vite-plugin' ) ) as any ;
12
14
13
15
return {
14
16
...original ,
15
- sentryVitePlugin : ( ) => [ mockedSentryVitePlugin ] ,
17
+ sentryVitePlugin : ( options : SentryVitePluginOptions ) => sentryVitePluginSpy ( options ) ,
16
18
} ;
17
19
} ) ;
18
20
@@ -21,7 +23,7 @@ beforeEach(() => {
21
23
} ) ;
22
24
23
25
describe ( 'makeSourceMapsVitePlugin()' , ( ) => {
24
- it ( 'returns a plugin to set `sourcemaps` to `true`' , async ( ) => {
26
+ it ( 'returns a plugin to set `sourcemaps` to `true`' , ( ) => {
25
27
const [ sourceMapsConfigPlugin , sentryVitePlugin ] = makeSourceMapsVitePlugin ( { } ) ;
26
28
27
29
expect ( sourceMapsConfigPlugin ?. name ) . toEqual ( 'sentry-solidstart-source-maps' ) ;
@@ -32,9 +34,7 @@ describe('makeSourceMapsVitePlugin()', () => {
32
34
expect ( sentryVitePlugin ) . toEqual ( mockedSentryVitePlugin ) ;
33
35
} ) ;
34
36
35
- it ( 'passes user-specified vite plugin options to vite plugin plugin' , async ( ) => {
36
- const makePluginSpy = vi . spyOn ( sourceMaps , 'makeSourceMapsVitePlugin' ) ;
37
-
37
+ it ( 'passes user-specified vite plugin options to vite plugin plugin' , ( ) => {
38
38
makeSourceMapsVitePlugin ( {
39
39
org : 'my-org' ,
40
40
authToken : 'my-token' ,
@@ -45,14 +45,42 @@ describe('makeSourceMapsVitePlugin()', () => {
45
45
} ,
46
46
} ) ;
47
47
48
- expect ( makePluginSpy ) . toHaveBeenCalledWith ( {
48
+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledWith (
49
+ expect . objectContaining ( {
50
+ org : 'my-org' ,
51
+ authToken : 'my-token' ,
52
+ sourcemaps : {
53
+ assets : [ 'foo/*.js' ] ,
54
+ ignore : [ 'bar/*.js' ] ,
55
+ filesToDeleteAfterUpload : [ 'baz/*.js' ] ,
56
+ } ,
57
+ } ) ,
58
+ ) ;
59
+ } ) ;
60
+
61
+ it ( 'should override options with unstable_sentryVitePluginOptions' , ( ) => {
62
+ makeSourceMapsVitePlugin ( {
49
63
org : 'my-org' ,
50
64
authToken : 'my-token' ,
51
65
sourcemaps : {
52
66
assets : [ 'foo/*.js' ] ,
53
- ignore : [ 'bar/*.js' ] ,
54
- filesToDeleteAfterUpload : [ 'baz/*.js' ] ,
67
+ } ,
68
+ unstable_sentryVitePluginOptions : {
69
+ org : 'unstable-org' ,
70
+ sourcemaps : {
71
+ assets : [ 'unstable/*.js' ] ,
72
+ } ,
55
73
} ,
56
74
} ) ;
75
+
76
+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledWith (
77
+ expect . objectContaining ( {
78
+ org : 'unstable-org' ,
79
+ authToken : 'my-token' ,
80
+ sourcemaps : {
81
+ assets : [ 'unstable/*.js' ] ,
82
+ } ,
83
+ } ) ,
84
+ ) ;
57
85
} ) ;
58
86
} ) ;
0 commit comments