-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathstaticUrls.js
61 lines (46 loc) · 1.62 KB
/
staticUrls.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const puppeteer = require('puppeteer');
const staticURLsToVerify = [
'https://sonarwhal-staging.azurewebsites.net/',
'https://sonarwhal-staging.azurewebsites.net/search/?q=bla',
'https://sonarwhal-staging.azurewebsites.net/about/changelog/1',
'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
];
const backOffTime = 5000;
const maxRetries = 3;
const delay = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
const runPuppeteer = async (url) => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
const response = await page.goto(url);
console.log(
`${
response.status() === 200 ? '✅ Success' : '❌ Failure'
}! ${url} => Status: ${response.status()}`
);
await browser.close();
return response.status();
} catch (error) {
console.error('🚨 Something went wrong while executing Puppeteer: ', error);
await browser.close();
return 0;
}
};
const runStaticTests = async () => {
let success = true;
let retryCount = 0;
let resultStatus = null;
for (const url of staticURLsToVerify) {
resultStatus = await runPuppeteer(url);
while(resultStatus !== 200 && retryCount < maxRetries) {
console.log('Test failed, retrying... Attempt #' + (++retryCount));
await delay(backOffTime * retryCount);
resultStatus = await runPuppeteer(url);
}
success = success && resultStatus === 200;
}
return success;
};
module.exports = { runStaticTests };