Skip to content

Commit 901fd79

Browse files
committed
New: integration test for staging env w/ Puppeteer
- Installs Puppeteer as a dev dependency on package.json. - Requests a collection of webhint.io staging URLs and saves the response in a Map() object. - Iterates over the Map and checks if is there any status different from 200 or another unknown error. - If there is any error, throws it to interrupt the test execution
1 parent 70e8bb2 commit 901fd79

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

helpers/integration-tests.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const puppeteer = require('puppeteer');
2+
3+
const URLsToVerify = [
4+
'https://sonarwhal-staging.azurewebsites.net/',
5+
'https://sonarwhal-staging.azurewebsites.net/scanner/',
6+
'https://sonarwhal-staging.azurewebsites.net/search/?q=bla',
7+
'https://sonarwhal-staging.azurewebsites.net/about/changelog/1',
8+
'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
9+
];
10+
11+
puppeteer.launch()
12+
.then((browser) => {
13+
const responseCollection = new Promise((resolve) => {
14+
const responses = new Map();
15+
16+
URLsToVerify.forEach((url, index) => {
17+
browser.newPage()
18+
.then((page) => {
19+
page.goto(url)
20+
.then((response) => {
21+
responses.set(url, response.status());
22+
})
23+
.catch((error) => {
24+
responses.set(url, `❌ ${error}`);
25+
})
26+
.finally(() => {
27+
if (index === (URLsToVerify.length - 1)) {
28+
resolve(responses);
29+
browser.close();
30+
}
31+
});
32+
})
33+
.catch((err) => {
34+
console.log(`Error on Puppeteer's newPage() function. Info: ${err}`);
35+
});
36+
});
37+
});
38+
39+
responseCollection.then((responses) => {
40+
for (const [url, response] of responses) {
41+
if (response !== 200) {
42+
const error = typeof response === 'number' ? `RESPONSE STATUS => ${response}` : response;
43+
44+
throw new Error(`❌ Test failed! A request to the URL ${url} has returned the following error: ${error}`);
45+
}
46+
47+
console.log(`✅ Success! ${url} => Status: ${response}`);
48+
}
49+
});
50+
})
51+
.catch((err) => {
52+
console.log(`Error on launching Puppeteer. Info: ${err}`);
53+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"mktemp": "^1.0.0",
5959
"normalize-path": "^3.0.0",
6060
"npm-run-all": "^4.1.3",
61+
"puppeteer": "1.20.0",
6162
"remove-markdown": "^0.3.0",
6263
"shelljs": "^0.8.3",
6364
"stylelint": "^11.0.0",

0 commit comments

Comments
 (0)