Skip to content

Commit 46b30a0

Browse files
author
Reno
authored
test: Bootstrap integ/smoke tests (#137)
1 parent ae26974 commit 46b30a0

File tree

8 files changed

+1189
-1104
lines changed

8 files changed

+1189
-1104
lines changed

package-lock.json

Lines changed: 1050 additions & 1103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@
4747
"postinteg:local:nightwatch:chrome": "kill $(lsof -t -i:8080)",
4848
"preinteg:local:nightwatch:firefox": "http-server ./build/dev -s &",
4949
"integ:local:nightwatch:firefox": "nightwatch -e firefox",
50-
"postinteg:local:nightwatch:firefox": "kill $(lsof -t -i:8080)"
50+
"postinteg:local:nightwatch:firefox": "kill $(lsof -t -i:8080)",
51+
"smoke:local": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT npx playwright test --config=playwright.local.config.ts --headed",
52+
"smoke": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT npx playwright test --headed",
53+
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT npx playwright test"
5154
},
5255
"devDependencies": {
5356
"@babel/plugin-transform-runtime": "^7.16.0",
5457
"@babel/preset-env": "~7.6.3",
58+
"@playwright/test": "^1.21.1",
5559
"@types/jest": "^27.0.2",
5660
"@types/ua-parser-js": "^0.7.35",
5761
"@types/uuid": "^8.3.0",

playwright.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// playwright.config.js
2+
// @ts-check
3+
const { devices } = require('@playwright/test');
4+
5+
const config = {
6+
forbidOnly: !!process.env.CI,
7+
testDir: 'src/__smoke-test__',
8+
retries: process.env.CI ? 2 : 0,
9+
use: {
10+
trace: 'on-first-retry'
11+
},
12+
projects: [
13+
{
14+
name: 'chromium',
15+
use: { ...devices['Desktop Chrome'] }
16+
}
17+
]
18+
};
19+
20+
module.exports = config;

playwright.local.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// playwright.local.config.js
2+
// @ts-check
3+
const { devices } = require('@playwright/test');
4+
5+
const config = {
6+
forbidOnly: !!process.env.CI,
7+
testDir: 'src/__smoke-test__',
8+
retries: process.env.CI ? 2 : 0,
9+
webServer: {
10+
command: 'npm run server',
11+
url: 'http://localhost:8080/',
12+
timeout: 120 * 1000,
13+
reuseExistingServer: !process.env.CI
14+
},
15+
use: {
16+
trace: 'on-first-retry'
17+
},
18+
projects: [
19+
{
20+
name: 'chromium',
21+
use: { ...devices['Desktop Chrome'] }
22+
}
23+
]
24+
};
25+
26+
module.exports = config;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { test, expect } from '@playwright/test';
2+
import {
3+
PERFORMANCE_NAVIGATION_EVENT_TYPE,
4+
PERFORMANCE_RESOURCE_EVENT_TYPE,
5+
PAGE_VIEW_EVENT_TYPE,
6+
SESSION_START_EVENT_TYPE
7+
} from '../plugins/utils/constant';
8+
9+
// Environment variables set through CLI command
10+
const ENDPOINT = process.env.ENDPOINT;
11+
const MONITOR_ID = process.env.MONITOR;
12+
const TEST_URL = process.env.URL || 'http://localhost:8080/smoke.html';
13+
14+
const TARGET_URL = ENDPOINT + MONITOR_ID + '/';
15+
16+
function getEventsByType(requestBody, eventType) {
17+
return requestBody.RumEvents.filter((e) => e.type === eventType);
18+
}
19+
20+
/**
21+
* Returns true if the request is a successful PutRumEvents request
22+
*/
23+
function isDataPlaneRequest(response): boolean {
24+
const request = response.request();
25+
return (
26+
request.method() === 'POST' &&
27+
response.status() === 200 &&
28+
response.url() === TARGET_URL
29+
);
30+
}
31+
32+
// Run the tests in parallel
33+
test.describe.configure({ mode: 'parallel' });
34+
35+
test('when web client calls PutRumEvents then the response code is 200', async ({
36+
page
37+
}) => {
38+
// Open page
39+
await page.goto(TEST_URL);
40+
41+
// Test will timeout if no successful dataplane request is found
42+
await page.waitForResponse(async (response) =>
43+
isDataPlaneRequest(response)
44+
);
45+
});
46+
47+
test('when web client calls PutRumEvents then the payload contains all events', async ({
48+
page
49+
}) => {
50+
// Expected number of events per type
51+
const SESSION_START_COUNT = 1;
52+
const PAGEVIEW_COUNT = 1;
53+
const NAVIGATION_COUNT = 1;
54+
const RESOURCE_EVENT_COUNT = 1;
55+
56+
// Open page
57+
await page.goto(TEST_URL);
58+
59+
// Test will timeout if no successful dataplane request is found
60+
const response = await page.waitForResponse(async (response) =>
61+
isDataPlaneRequest(response)
62+
);
63+
64+
// Parse payload to verify event count
65+
const requestBody = JSON.parse(response.request().postData());
66+
67+
const session = getEventsByType(requestBody, SESSION_START_EVENT_TYPE);
68+
const navigation = getEventsByType(
69+
requestBody,
70+
PERFORMANCE_NAVIGATION_EVENT_TYPE
71+
);
72+
const pageView = getEventsByType(requestBody, PAGE_VIEW_EVENT_TYPE);
73+
const resource = getEventsByType(
74+
requestBody,
75+
PERFORMANCE_RESOURCE_EVENT_TYPE
76+
);
77+
78+
// Verify no events are dropped
79+
expect(session.length).toEqual(SESSION_START_COUNT);
80+
expect(pageView.length).toEqual(PAGEVIEW_COUNT);
81+
expect(navigation.length).toEqual(NAVIGATION_COUNT);
82+
expect(resource.length).toEqual(RESOURCE_EVENT_COUNT);
83+
});

src/plugins/utils/constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ export const JS_ERROR_EVENT_TYPE = 'com.amazon.rum.js_error_event';
2727

2828
// Page view event
2929
export const PAGE_VIEW_EVENT_TYPE = 'com.amazon.rum.page_view_event';
30+
31+
// Session start event
32+
export const SESSION_START_EVENT_TYPE = 'com.amazon.rum.session_start_event';

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"**/__tests__",
1313
"**/__integ__",
1414
"**/__mocks__",
15+
"**/__smoke-test__",
1516
"src/index-browser.ts",
1617
"src/loader",
1718
"src/test-utils"

tsconfig.webpack.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"**/__tests__",
1515
"**/__integ__",
1616
"**/__mocks__",
17+
"**/__smoke-test__",
1718
"src/index.ts",
1819
"src/loader",
1920
"src/test-utils"

0 commit comments

Comments
 (0)