Skip to content

Commit 3c66fc4

Browse files
chore: playwright remote config smoke tests (#1277)
1 parent 5d8cbbd commit 3c66fc4

File tree

8 files changed

+383
-22
lines changed

8 files changed

+383
-22
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: E2E Tests
1414
runs-on: ubuntu-latest
1515
container:
16-
image: mcr.microsoft.com/playwright:v1.52.0
16+
image: mcr.microsoft.com/playwright:v1.55.0
1717

1818
steps:
1919
- name: Check out git repository

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:examples": "jest --env=jsdom --coverage=false examples --setupFiles ./jest.setup.examples.js",
3232
"test:unit": "lerna run test --stream --ignore @amplitude/analytics-*-test",
3333
"test:e2e": "lerna run test --stream --scope @amplitude/analytics-*-test",
34+
"test:e2e:remote-config": "sh packages/e2e-remote-config/remote-config-test.sh",
3435
"test:playwright": "lerna run test:playwright --stream",
3536
"test:playwright:ui": "playwright test --ui",
3637
"test:playwright:debug": "playwright test --debug",
@@ -41,7 +42,8 @@
4142
"devDependencies": {
4243
"@commitlint/cli": "^17.3.0",
4344
"@commitlint/config-conventional": "^17.3.0",
44-
"@playwright/test": "^1.52.0",
45+
"@nx/workspace": "^21.2.1",
46+
"@playwright/test": "1.55.0",
4547
"@types/jest": "^29.2.4",
4648
"@types/node": "^18.11.14",
4749
"@typescript-eslint/eslint-plugin": "^5.46.1",
@@ -57,24 +59,23 @@
5759
"eslint-plugin-playwright": "^2.2.0",
5860
"express": "^4.18.2",
5961
"fake-indexeddb": "4.0.2",
62+
"glob": "^10.3.10",
6063
"husky": "^8.0.2",
6164
"jest": "^29.3.1",
6265
"jest-environment-jsdom": "^29.3.1",
6366
"lerna": "^8.1.5",
6467
"lint-staged": "^13.1.0",
6568
"morgan": "^1.10.0",
6669
"nodemon": "^3.0.1",
70+
"nx": "^21.2.1",
6771
"prettier": "^2.8.1",
6872
"rimraf": "^3.0.2",
6973
"ts-jest": "^29.0.3",
74+
"tslib": "^2.4.1",
7075
"typedoc": "^0.23.22",
7176
"typescript": "^4.9.4",
7277
"vite": "^6.3.4",
73-
"yargs": "^17.7.1",
74-
"nx": "^21.2.1",
75-
"@nx/workspace": "^21.2.1",
76-
"glob": "^10.3.10",
77-
"tslib": "^2.4.1"
78+
"yargs": "^17.7.1"
7879
},
7980
"lint-staged": {
8081
"*.ts": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<p align="center">
2+
<a href="https://amplitude.com" target="_blank" align="center">
3+
<img src="https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg" width="280">
4+
</a>
5+
<br />
6+
</p>
7+
8+
# E2E Remote Config
9+
10+
A place for E2E tests that test the Remote Config functionality. Tests against a matrix of SDK versions and API Keys.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# STAGING
2+
API_KEY="52fbe5356dc7490756a9c26591f2bb37"
3+
AMPLITUDE_VERSION="2.22.2"
4+
SERVER_ZONE="STAGING"
5+
SERVER_ZONE=$SERVER_ZONE API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
6+
7+
# API_KEY empty
8+
API_KEY="657954c4c37e22e8dc2af0413ac01e2b"
9+
SERVER_ZONE="US"
10+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
11+
12+
# 2.11.0 -- first mionor version to support remote config for autocapture
13+
AMPLITUDE_VERSION="2.11.13"
14+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
15+
16+
# 2.13.3 -- first minor version to set remote config fetch default=true
17+
AMPLITUDE_VERSION="2.13.3"
18+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
19+
20+
# 2.17.12 -- first minor version to use the new Remote Config client
21+
AMPLITUDE_VERSION="2.22.2"
22+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
23+
24+
# API_KEY nested
25+
API_KEY="77de0b7de6157d5e7ca409c81778f28e"
26+
AMPLITUDE_VERSION="2.11.13"
27+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
28+
29+
AMPLITUDE_VERSION="2.13.3"
30+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
31+
32+
AMPLITUDE_VERSION="2.22.2"
33+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
34+
35+
# API_KEY default
36+
API_KEY="aafc4dd16b5bf88b1cf21693d97665d3"
37+
AMPLITUDE_VERSION="2.11.13"
38+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
39+
40+
AMPLITUDE_VERSION="2.13.3"
41+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
42+
43+
AMPLITUDE_VERSION="2.22.2"
44+
API_KEY=$API_KEY AMPLITUDE_VERSION=$AMPLITUDE_VERSION npx playwright test packages/e2e-remote-config/test/e2e/fetch-remote-config.spec.ts
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, no-restricted-globals */
4+
5+
// parse query params
6+
const remoteConfigUrl = 'https://sr-client-cfg.amplitude.com/';
7+
const amplitudeVersion = process.env.AMPLITUDE_VERSION;
8+
const apiKey = process.env.API_KEY;
9+
const serverZone = process.env.SERVER_ZONE || 'US';
10+
11+
let redirectedServerUrl = null;
12+
if (serverZone === 'STAGING') {
13+
redirectedServerUrl = 'https://sr-client-cfg.stag2.amplitude.com/';
14+
} else if (serverZone === 'EU') {
15+
redirectedServerUrl = 'https://sr-client-cfg.eu.amplitude.com/';
16+
}
17+
18+
if (redirectedServerUrl && !redirectedServerUrl?.endsWith('/')) {
19+
redirectedServerUrl += '/';
20+
}
21+
22+
const LOCAL_SITE = 'http://localhost:5173';
23+
24+
test.describe(`Fetch remote config: remoteConfigUrl=${redirectedServerUrl} sdkVersion=${amplitudeVersion || 'latest'} apiKey=${apiKey || 'default'}`, () => {
25+
test('should fetch remote config', async ({ page }) => {
26+
// intercept the fetch request to the remote config
27+
let fullRemoteConfigUrl = remoteConfigUrl;
28+
await page.route(`${remoteConfigUrl}**`, async (route) => {
29+
if (redirectedServerUrl) {
30+
// edit the request to redirect to the redirectedServerUrl
31+
const request = route.request();
32+
const newUrl = request.url().replace(remoteConfigUrl, redirectedServerUrl);
33+
fullRemoteConfigUrl = newUrl;
34+
await route.continue({ url: newUrl });
35+
} else {
36+
fullRemoteConfigUrl = route.request().url();
37+
await route.continue();
38+
}
39+
});
40+
const responsePattern = redirectedServerUrl ? `${redirectedServerUrl}**` : `${remoteConfigUrl}**`;
41+
const fetchRemoteConfigPromise = page.waitForResponse(responsePattern);
42+
43+
// open the page with parameters to define version, api key and server zone
44+
let queryParams: Record<string, string> = {};
45+
if (amplitudeVersion) {
46+
queryParams.amplitudeVersion = amplitudeVersion;
47+
}
48+
if (apiKey) {
49+
queryParams.apiKey = apiKey;
50+
}
51+
queryParams.serverZone = serverZone;
52+
await page.goto(`${LOCAL_SITE}/remote-config-test.html?${new URLSearchParams(queryParams).toString()}`);
53+
const response = await fetchRemoteConfigPromise;
54+
const body = await response.json();
55+
expect(body.configs.analyticsSDK).toBeDefined();
56+
57+
// perform an interaction on the page to confirm it's still interactable
58+
const interactiveButton = page.locator('#interactive-button');
59+
const interactiveContent = page.locator('#interactive-content');
60+
await expect(interactiveContent).toHaveText('This is the interactive section.');
61+
await interactiveButton.click();
62+
await expect(interactiveContent).toHaveText('Interactive content has been changed.');
63+
});
64+
});

test-server/autocapture/element-interactions.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ <h2>Content Changing Button</h2>
265265
import.meta.env.VITE_AMPLITUDE_USER_ID || 'amplitude-typescript test user',
266266
{
267267
fetchRemoteConfig: false,
268-
autocapture: true,
268+
autocapture: {
269+
elementInteractions: true,
270+
frustrationInteractions,
271+
},
269272
}
270273
);
271274

0 commit comments

Comments
 (0)