@@ -14,6 +14,13 @@ process.env = {
14
14
SENTRY_AUTH_TOKEN : 'my-token' ,
15
15
} ;
16
16
17
+ const updateConfig = vi . fn ( ) ;
18
+ const injectScript = vi . fn ( ) ;
19
+ const config = {
20
+ root : new URL ( 'file://path/to/project' ) ,
21
+ outDir : new URL ( 'file://path/to/project/out' ) ,
22
+ } ;
23
+
17
24
describe ( 'sentryAstro integration' , ( ) => {
18
25
afterEach ( ( ) => {
19
26
vi . clearAllMocks ( ) ;
@@ -28,12 +35,10 @@ describe('sentryAstro integration', () => {
28
35
const integration = sentryAstro ( {
29
36
sourceMapsUploadOptions : { enabled : true , org : 'my-org' , project : 'my-project' , telemetry : false } ,
30
37
} ) ;
31
- const updateConfig = vi . fn ( ) ;
32
- const injectScript = vi . fn ( ) ;
33
38
34
39
expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
35
40
// @ts -expect-error - the hook exists and we only need to pass what we actually use
36
- await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript } ) ;
41
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
37
42
38
43
expect ( updateConfig ) . toHaveBeenCalledTimes ( 1 ) ;
39
44
expect ( updateConfig ) . toHaveBeenCalledWith ( {
@@ -51,32 +56,52 @@ describe('sentryAstro integration', () => {
51
56
org : 'my-org' ,
52
57
project : 'my-project' ,
53
58
telemetry : false ,
59
+ debug : false ,
60
+ sourcemaps : {
61
+ assets : [ 'out/**/*' ] ,
62
+ } ,
63
+ } ) ;
64
+ } ) ;
65
+
66
+ it ( 'falls back to default output dir, if out and root dir are not available' , async ( ) => {
67
+ const integration = sentryAstro ( {
68
+ sourceMapsUploadOptions : { enabled : true , org : 'my-org' , project : 'my-project' , telemetry : false } ,
69
+ } ) ;
70
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
71
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config : { } } ) ;
72
+
73
+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledTimes ( 1 ) ;
74
+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledWith ( {
75
+ authToken : 'my-token' ,
76
+ org : 'my-org' ,
77
+ project : 'my-project' ,
78
+ telemetry : false ,
79
+ debug : false ,
80
+ sourcemaps : {
81
+ assets : [ 'dist/**/*' ] ,
82
+ } ,
54
83
} ) ;
55
84
} ) ;
56
85
57
86
it ( "doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`" , async ( ) => {
58
87
const integration = sentryAstro ( {
59
88
sourceMapsUploadOptions : { enabled : false } ,
60
89
} ) ;
61
- const updateConfig = vi . fn ( ) ;
62
- const injectScript = vi . fn ( ) ;
63
90
64
91
expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
65
92
// @ts -expect-error - the hook exists and we only need to pass what we actually use
66
- await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript } ) ;
93
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
67
94
68
95
expect ( updateConfig ) . toHaveBeenCalledTimes ( 0 ) ;
69
96
expect ( sentryVitePluginSpy ) . toHaveBeenCalledTimes ( 0 ) ;
70
97
} ) ;
71
98
72
99
it ( 'injects client and server init scripts' , async ( ) => {
73
100
const integration = sentryAstro ( { } ) ;
74
- const updateConfig = vi . fn ( ) ;
75
- const injectScript = vi . fn ( ) ;
76
101
77
102
expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
78
103
// @ts -expect-error - the hook exists and we only need to pass what we actually use
79
- await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript } ) ;
104
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
80
105
81
106
expect ( injectScript ) . toHaveBeenCalledTimes ( 2 ) ;
82
107
expect ( injectScript ) . toHaveBeenCalledWith ( 'page' , expect . stringContaining ( 'Sentry.init' ) ) ;
@@ -89,12 +114,9 @@ describe('sentryAstro integration', () => {
89
114
serverInitPath : 'my-server-init-path.js' ,
90
115
} ) ;
91
116
92
- const updateConfig = vi . fn ( ) ;
93
- const injectScript = vi . fn ( ) ;
94
-
95
117
expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
96
118
// @ts -expect-error - the hook exists and we only need to pass what we actually use
97
- await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript } ) ;
119
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
98
120
99
121
expect ( injectScript ) . toHaveBeenCalledTimes ( 2 ) ;
100
122
expect ( injectScript ) . toHaveBeenCalledWith ( 'page' , expect . stringContaining ( 'my-client-init-path.js' ) ) ;
0 commit comments