11import { vi } from 'vitest' ;
22
3- import { makeCustomSentryVitePlugin } from '../../src/vite/sourceMaps' ;
3+ import type { Plugin } from 'vite' ;
4+ import { makeCustomSentryVitePlugins } from '../../src/vite/sourceMaps' ;
45
56const mockedSentryVitePlugin = {
6- buildStart : vi . fn ( ) ,
7- resolveId : vi . fn ( ) ,
8- renderChunk : vi . fn ( ) ,
9- transform : vi . fn ( ) . mockImplementation ( ( code : string , _id : string ) => code ) ,
7+ name : 'sentry-vite-debug-id-upload-plugin' ,
108 writeBundle : vi . fn ( ) ,
119} ;
1210
@@ -15,34 +13,45 @@ vi.mock('@sentry/vite-plugin', async () => {
1513
1614 return {
1715 ...original ,
18- sentryVitePlugin : ( ) => mockedSentryVitePlugin ,
16+ sentryVitePlugin : ( ) => [ mockedSentryVitePlugin ] ,
1917 } ;
2018} ) ;
2119
2220beforeEach ( ( ) => {
2321 vi . clearAllMocks ( ) ;
2422} ) ;
2523
24+ async function getCustomSentryViteUploadSourcemapsPlugin ( ) : Promise < Plugin | undefined > {
25+ const plugins = await makeCustomSentryVitePlugins ( {
26+ authToken : 'token' ,
27+ org : 'org' ,
28+ project : 'project' ,
29+ adapter : 'other' ,
30+ } ) ;
31+ return plugins . find ( plugin => plugin . name === 'sentry-upload-sveltekit-source-maps' ) ;
32+ }
33+
2634describe ( 'makeCustomSentryVitePlugin()' , ( ) => {
2735 it ( 'returns the custom sentry source maps plugin' , async ( ) => {
28- const plugin = await makeCustomSentryVitePlugin ( ) ;
29- expect ( plugin . name ) . toEqual ( 'sentry-upload-source-maps' ) ;
30- expect ( plugin . apply ) . toEqual ( 'build' ) ;
31- expect ( plugin . enforce ) . toEqual ( 'post' ) ;
32-
33- expect ( plugin . buildStart ) . toBeInstanceOf ( Function ) ;
34- expect ( plugin . resolveId ) . toBeInstanceOf ( Function ) ;
35- expect ( plugin . renderChunk ) . toBeInstanceOf ( Function ) ;
36- expect ( plugin . transform ) . toBeInstanceOf ( Function ) ;
37-
38- expect ( plugin . config ) . toBeInstanceOf ( Function ) ;
39- expect ( plugin . configResolved ) . toBeInstanceOf ( Function ) ;
40- expect ( plugin . closeBundle ) . toBeInstanceOf ( Function ) ;
36+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
37+ expect ( plugin ?. name ) . toEqual ( 'sentry-upload-sveltekit-source-maps' ) ;
38+ expect ( plugin ?. apply ) . toEqual ( 'build' ) ;
39+ expect ( plugin ?. enforce ) . toEqual ( 'post' ) ;
40+
41+ expect ( plugin ?. resolveId ) . toBeInstanceOf ( Function ) ;
42+ expect ( plugin ?. transform ) . toBeInstanceOf ( Function ) ;
43+
44+ expect ( plugin ?. config ) . toBeInstanceOf ( Function ) ;
45+ expect ( plugin ?. configResolved ) . toBeInstanceOf ( Function ) ;
46+
47+ // instead of writeBundle, this plugin uses closeBundle
48+ expect ( plugin ?. closeBundle ) . toBeInstanceOf ( Function ) ;
49+ expect ( plugin ?. writeBundle ) . toBeUndefined ( ) ;
4150 } ) ;
4251
4352 describe ( 'Custom sentry vite plugin' , ( ) => {
4453 it ( 'enables source map generation' , async ( ) => {
45- const plugin = await makeCustomSentryVitePlugin ( ) ;
54+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
4655 // @ts -expect-error this function exists!
4756 const sentrifiedConfig = plugin . config ( { build : { foo : { } } , test : { } } ) ;
4857 expect ( sentrifiedConfig ) . toEqual ( {
@@ -55,16 +64,18 @@ describe('makeCustomSentryVitePlugin()', () => {
5564 } ) ;
5665
5766 it ( 'injects the output dir into the server hooks file' , async ( ) => {
58- const plugin = await makeCustomSentryVitePlugin ( ) ;
67+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
5968 // @ts -expect-error this function exists!
60- const transformedCode = await plugin . transform ( 'foo' , '/src/hooks.server.ts' ) ;
61- const expectedtransformedCode = 'foo\n; import "\0sentry-inject-global-values-file";\n' ;
62- expect ( mockedSentryVitePlugin . transform ) . toHaveBeenCalledWith ( expectedtransformedCode , '/src/hooks.server.ts' ) ;
63- expect ( transformedCode ) . toEqual ( expectedtransformedCode ) ;
69+ const transformOutput = await plugin . transform ( 'foo' , '/src/hooks.server.ts' ) ;
70+ const transformedCode = transformOutput . code ;
71+ const transformedSourcemap = transformOutput . map ;
72+ const expectedTransformedCode = 'foo\n; import "\0sentry-inject-global-values-file";\n' ;
73+ expect ( transformedCode ) . toEqual ( expectedTransformedCode ) ;
74+ expect ( transformedSourcemap ) . toBeDefined ( ) ;
6475 } ) ;
6576
6677 it ( 'uploads source maps during the SSR build' , async ( ) => {
67- const plugin = await makeCustomSentryVitePlugin ( ) ;
78+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
6879 // @ts -expect-error this function exists!
6980 plugin . configResolved ( { build : { ssr : true } } ) ;
7081 // @ts -expect-error this function exists!
@@ -73,7 +84,7 @@ describe('makeCustomSentryVitePlugin()', () => {
7384 } ) ;
7485
7586 it ( "doesn't upload source maps during the non-SSR builds" , async ( ) => {
76- const plugin = await makeCustomSentryVitePlugin ( ) ;
87+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
7788
7889 // @ts -expect-error this function exists!
7990 plugin . configResolved ( { build : { ssr : false } } ) ;
@@ -91,7 +102,7 @@ describe('makeCustomSentryVitePlugin()', () => {
91102 const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
92103 const consoleLogSpy = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
93104
94- const plugin = await makeCustomSentryVitePlugin ( ) ;
105+ const plugin = await getCustomSentryViteUploadSourcemapsPlugin ( ) ;
95106
96107 // @ts -expect-error this function exists!
97108 expect ( plugin . closeBundle ) . not . toThrow ( ) ;
0 commit comments