@@ -5,41 +5,52 @@ import { test, expect } from '@playwright/test';
5
5
const remoteConfigUrl = 'https://sr-client-cfg.amplitude.com/' ;
6
6
const amplitudeVersion = process . env . AMPLITUDE_VERSION ;
7
7
const apiKey = process . env . API_KEY ;
8
- let redirectedServerUrl = process . env . REMOTE_CONFIG_URL || '' ;
8
+ const serverZone = process . env . SERVER_ZONE || 'US' ;
9
+
10
+ let redirectedServerUrl = null ;
11
+ if ( serverZone === 'STAGING' ) {
12
+ redirectedServerUrl = 'https://sr-client-cfg.stag2.amplitude.com/' ;
13
+ } else if ( serverZone === 'EU' ) {
14
+ redirectedServerUrl = 'https://sr-client-cfg.eu.amplitude.com/' ;
15
+ }
16
+ console . log ( `Redirecting to server URL: ${ redirectedServerUrl } ` ) ;
9
17
10
18
if ( redirectedServerUrl && ! redirectedServerUrl ?. endsWith ( '/' ) ) {
11
19
redirectedServerUrl += '/' ;
12
20
}
13
21
14
22
const LOCAL_SITE = 'http://localhost:5173' ;
15
23
16
- test . describe ( `Fetch remote config sdkVersion=${ amplitudeVersion || 'latest' } apiKey=${ apiKey || 'default' } ` , ( ) => {
24
+ test . describe ( `Fetch remote config: remoteConfigUrl= ${ redirectedServerUrl } sdkVersion=${ amplitudeVersion || 'latest' } apiKey=${ apiKey || 'default' } ` , ( ) => {
17
25
test ( 'should fetch remote config' , async ( { page } ) => {
18
26
// intercept the fetch request to the remote config
27
+ let fullRemoteConfigUrl = remoteConfigUrl ;
19
28
await page . route ( `${ remoteConfigUrl } **` , async ( route ) => {
20
29
if ( redirectedServerUrl ) {
21
30
// edit the request to redirect to the redirectedServerUrl
22
31
const request = route . request ( ) ;
23
32
const newUrl = request . url ( ) . replace ( remoteConfigUrl , redirectedServerUrl ) ;
33
+ fullRemoteConfigUrl = newUrl ;
24
34
await route . continue ( { url : newUrl } ) ;
25
35
} else {
36
+ fullRemoteConfigUrl = route . request ( ) . url ( ) ;
26
37
await route . continue ( ) ;
27
38
}
28
39
} ) ;
29
-
30
- const fetchRemoteConfigPromise = page . waitForResponse ( ` ${ remoteConfigUrl } *` ) ;
40
+ const responsePattern = redirectedServerUrl ? ` ${ redirectedServerUrl } **` : ` ${ remoteConfigUrl } **` ;
41
+ const fetchRemoteConfigPromise = page . waitForResponse ( responsePattern ) ;
31
42
let queryParams : Record < string , string > = { } ;
32
43
if ( amplitudeVersion ) {
33
44
queryParams . amplitudeVersion = amplitudeVersion ;
34
45
}
35
46
if ( apiKey ) {
36
47
queryParams . apiKey = apiKey ;
37
48
}
38
- // TODO: parameterize this
39
- queryParams . serverZone = 'STAGING' ;
49
+ queryParams . serverZone = serverZone ;
40
50
await page . goto ( `${ LOCAL_SITE } /remote-config-test.html?${ new URLSearchParams ( queryParams ) . toString ( ) } ` ) ;
41
51
const response = await fetchRemoteConfigPromise ;
42
52
const body = await response . json ( ) ;
53
+ console . log ( 'body' , body ) ;
43
54
expect ( body . configs . analyticsSDK ) . toBeDefined ( ) ;
44
55
} ) ;
45
56
} ) ;
0 commit comments