1+ import { SentryVitePluginOptions } from '@sentry/vite-plugin' ;
12import { beforeEach , describe , expect , it , vi } from 'vitest' ;
23import { makeSourceMapsVitePlugin } from '../../src/vite/sourceMaps' ;
3- import * as sourceMaps from '../../src/vite/sourceMaps' ;
44
55const mockedSentryVitePlugin = {
66 name : 'sentry-vite-debug-id-upload-plugin' ,
77 writeBundle : vi . fn ( ) ,
88} ;
99
10+ const sentryVitePluginSpy = vi . fn ( ( _options : SentryVitePluginOptions ) => [ mockedSentryVitePlugin ] ) ;
11+
1012vi . mock ( '@sentry/vite-plugin' , async ( ) => {
1113 const original = ( await vi . importActual ( '@sentry/vite-plugin' ) ) as any ;
1214
1315 return {
1416 ...original ,
15- sentryVitePlugin : ( ) => [ mockedSentryVitePlugin ] ,
17+ sentryVitePlugin : ( options : SentryVitePluginOptions ) => sentryVitePluginSpy ( options ) ,
1618 } ;
1719} ) ;
1820
@@ -21,7 +23,7 @@ beforeEach(() => {
2123} ) ;
2224
2325describe ( 'makeSourceMapsVitePlugin()' , ( ) => {
24- it ( 'returns a plugin to set `sourcemaps` to `true`' , async ( ) => {
26+ it ( 'returns a plugin to set `sourcemaps` to `true`' , ( ) => {
2527 const [ sourceMapsConfigPlugin , sentryVitePlugin ] = makeSourceMapsVitePlugin ( { } ) ;
2628
2729 expect ( sourceMapsConfigPlugin ?. name ) . toEqual ( 'sentry-solidstart-source-maps' ) ;
@@ -32,9 +34,7 @@ describe('makeSourceMapsVitePlugin()', () => {
3234 expect ( sentryVitePlugin ) . toEqual ( mockedSentryVitePlugin ) ;
3335 } ) ;
3436
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' , ( ) => {
3838 makeSourceMapsVitePlugin ( {
3939 org : 'my-org' ,
4040 authToken : 'my-token' ,
@@ -45,14 +45,42 @@ describe('makeSourceMapsVitePlugin()', () => {
4545 } ,
4646 } ) ;
4747
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 ( {
4963 org : 'my-org' ,
5064 authToken : 'my-token' ,
5165 sourcemaps : {
5266 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+ } ,
5573 } ,
5674 } ) ;
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+ ) ;
5785 } ) ;
5886} ) ;
0 commit comments