-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (46 loc) · 1.69 KB
/
index.js
File metadata and controls
55 lines (46 loc) · 1.69 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const puppeteer = require('puppeteer');
const terminalImage = require('terminal-image');
const URL = process.env.URL || 'http://localhost:20041/best-electric-scooters';
const DATASET = process.env.DATASET || 'buyclick-url';
const SCREENSHOTS = process.argv.includes('--screenshots');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
width: 1028,
height: 800,
});
await page.goto(URL);
const appSelector = '#app';
await page.waitForSelector(appSelector);
// Extract the exit urls
const exitUrls = await page.evaluate((DATASET) => {
const snakeToCamel = str => str.replace(/([-_]\w)/g, g => g[1].toUpperCase());
const elements = Array.from(document.querySelectorAll(`[data-${DATASET}]`));
return elements.map(el => {
return el.dataset[snakeToCamel(DATASET)];
});
}, DATASET);
let missingParams = 0;
exitUrls.forEach(url => {
console.log(`Checking ${url}`);
const params = new URLSearchParams(url);
for (const [key, value] of params.entries()) {
if (key && key != 'wm') {
console.assert(Boolean(value), `${key} is empty`);
missingParams = value ? missingParams : missingParams + 1;
}
}
})
console.log(`There are ${exitUrls.length} buy urls set`);
console.log(`There are ${missingParams} missing params`);
if (SCREENSHOTS) {
let imgBuff = await page.screenshot({
fullPage: false
});
console.log(await terminalImage.buffer(imgBuff, {
height: 800
}));
}
await browser.close();
})();