-
Notifications
You must be signed in to change notification settings - Fork 36
/
script.js
38 lines (29 loc) · 1.07 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const startTime = Date.now();
const puppeteer = require("puppeteer");
const { startAppServer } = require("../demo-app/server");
const newTrackerClient = require("react-render-tracker/headless-browser-client");
async function runReactScenarioSet(run) {
const [browser, server] = await Promise.all([
puppeteer.launch({ headless: "new" }),
startAppServer(),
]);
await run(async function runReactScenario(url, scenario) {
const page = await browser.newPage();
const rrt = await newTrackerClient(page);
await page.goto(new URL(url, server.host).href);
await scenario({ browser, page, rrt });
await page.close();
});
await browser.close();
await server.close();
}
runReactScenarioSet(async runReactScenario => {
await runReactScenario("/", async ({ page, rrt }) => {
const eventCountBeforeAction = await rrt.getEventCount();
// do some actions
await page.click("button");
// dump events after an action
console.log(await rrt.getEvents(eventCountBeforeAction));
});
console.log("DONE in", Date.now() - startTime, "ms");
});