1
- import { type Page , expect , test } from '@playwright/test' ;
1
+ import { type Page , expect , test , chromium } from '@playwright/test' ;
2
2
3
3
async function getRouteData ( page : Page ) : Promise < any > {
4
4
return page . evaluate ( 'window.__remixContext.state.loaderData' ) . catch ( err => {
@@ -20,20 +20,8 @@ async function extractTraceAndBaggageFromMeta(
20
20
return { sentryTrace : sentryTraceContent , sentryBaggage : sentryBaggageContent } ;
21
21
}
22
22
23
- async function mockExampleRoute ( page : Page ) : Promise < void > {
24
- await page . route ( 'https://example.com/**/*' , route => {
25
- return route . fulfill ( {
26
- status : 200 ,
27
- body : JSON . stringify ( {
28
- foo : 'bar' ,
29
- } ) ,
30
- } ) ;
31
- } ) ;
32
- }
33
-
34
23
test ( 'should inject `sentry-trace` and `baggage` into root loader returning an empty object.' , async ( { page } ) => {
35
24
await page . goto ( '/?type=empty' ) ;
36
-
37
25
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
38
26
39
27
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -49,7 +37,6 @@ test('should inject `sentry-trace` and `baggage` into root loader returning an e
49
37
50
38
test ( 'should inject `sentry-trace` and `baggage` into root loader returning a plain object.' , async ( { page } ) => {
51
39
await page . goto ( '/?type=plain' ) ;
52
-
53
40
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
54
41
55
42
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -67,7 +54,6 @@ test('should inject `sentry-trace` and `baggage` into root loader returning a pl
67
54
68
55
test ( 'should inject `sentry-trace` and `baggage` into root loader returning a `JSON response`.' , async ( { page } ) => {
69
56
await page . goto ( '/?type=json' ) ;
70
-
71
57
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
72
58
73
59
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -85,7 +71,6 @@ test('should inject `sentry-trace` and `baggage` into root loader returning a `J
85
71
86
72
test ( 'should inject `sentry-trace` and `baggage` into root loader returning a deferred response' , async ( { page } ) => {
87
73
await page . goto ( '/?type=defer' ) ;
88
-
89
74
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
90
75
91
76
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -101,7 +86,6 @@ test('should inject `sentry-trace` and `baggage` into root loader returning a de
101
86
102
87
test ( 'should inject `sentry-trace` and `baggage` into root loader returning `null`.' , async ( { page } ) => {
103
88
await page . goto ( '/?type=null' ) ;
104
-
105
89
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
106
90
107
91
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -117,7 +101,6 @@ test('should inject `sentry-trace` and `baggage` into root loader returning `nul
117
101
118
102
test ( 'should inject `sentry-trace` and `baggage` into root loader returning `undefined`.' , async ( { page } ) => {
119
103
await page . goto ( '/?type=undefined' ) ;
120
-
121
104
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
122
105
123
106
expect ( sentryTrace ) . toMatch ( / .+ / ) ;
@@ -134,9 +117,7 @@ test('should inject `sentry-trace` and `baggage` into root loader returning `und
134
117
test ( 'should inject `sentry-trace` and `baggage` into root loader throwing a redirection to a plain object.' , async ( {
135
118
page,
136
119
} ) => {
137
- await mockExampleRoute ( page ) ;
138
120
await page . goto ( '/?type=throwRedirect' ) ;
139
-
140
121
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
141
122
142
123
// We should be successfully redirected to the path.
@@ -155,10 +136,9 @@ test('should inject `sentry-trace` and `baggage` into root loader throwing a red
155
136
156
137
test ( 'should inject `sentry-trace` and `baggage` into root loader returning a redirection to valid path.' , async ( {
157
138
page,
139
+ baseURL,
158
140
} ) => {
159
- await mockExampleRoute ( page ) ;
160
- await page . goto ( '/?type=returnRedirect' ) ;
161
-
141
+ await page . goto ( `${ baseURL } /?type=returnRedirect` ) ;
162
142
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
163
143
164
144
// We should be successfully redirected to the path.
@@ -175,27 +155,24 @@ test('should inject `sentry-trace` and `baggage` into root loader returning a re
175
155
} ) ;
176
156
} ) ;
177
157
178
- test ( 'should return redirect to an external path with no baggage and trace injected.' , async ( { page } ) => {
179
- await mockExampleRoute ( page ) ;
180
- await page . goto ( '/?type=returnRedirectToExternal' ) ;
158
+ test ( 'should return redirect to an external path with no baggage and trace injected.' , async ( { page, baseURL } ) => {
159
+ await page . goto ( `${ baseURL } /?type=returnRedirectToExternal` ) ;
181
160
182
- const { sentryTrace , sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
161
+ expect ( page . url ( ) ) . toEqual ( expect . stringContaining ( 'docs.sentry.io' ) ) ;
183
162
184
- // We should be successfully redirected to the external path.
185
- expect ( page . url ( ) ) . toEqual ( expect . stringContaining ( 'https://example.com' ) ) ;
163
+ const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
186
164
187
165
expect ( sentryTrace ) . toBeUndefined ( ) ;
188
166
expect ( sentryBaggage ) . toBeUndefined ( ) ;
189
167
} ) ;
190
168
191
- test ( 'should throw redirect to an external path with no baggage and trace injected.' , async ( { page } ) => {
192
- await mockExampleRoute ( page ) ;
193
- await page . goto ( '/?type=throwRedirectToExternal' ) ;
194
-
195
- const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
169
+ test ( 'should throw redirect to an external path with no baggage and trace injected.' , async ( { page, baseURL } ) => {
170
+ await page . goto ( `${ baseURL } /?type=throwRedirectToExternal` ) ;
196
171
197
172
// We should be successfully redirected to the external path.
198
- expect ( page . url ( ) ) . toEqual ( expect . stringContaining ( 'https://example.com' ) ) ;
173
+ expect ( page . url ( ) ) . toEqual ( expect . stringContaining ( 'docs.sentry.io' ) ) ;
174
+
175
+ const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta ( page ) ;
199
176
200
177
expect ( sentryTrace ) . toBeUndefined ( ) ;
201
178
expect ( sentryBaggage ) . toBeUndefined ( ) ;
0 commit comments