Skip to content

Commit 0ae8573

Browse files
LeoSLantross
authored andcommitted
New: Integration test for staging env w/ Puppeteer
- Install Puppeteer as a dev dependency on package.json. - Request a collection of webhint.io staging URLs and save the response in a Map() object. - Iterate over the Map and check if there is any status different from 200 or another unknown error. - If there is any error, throw it to interrupt the test execution. - - - - - - - - - - Fix #810 Close #843
1 parent 92fc43c commit 0ae8573

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

helpers/integration-tests/index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { runStaticTests } = require('./staticUrls');
2+
const { runScannerTest } = require('./scanner');
3+
4+
console.log('Integration tests are running...');
5+
6+
const runIntegrationTests = async () => {
7+
let error = false;
8+
9+
for (const test of [runStaticTests, runScannerTest]) {
10+
const errorFound = await test();
11+
12+
if (errorFound) {
13+
error = true;
14+
}
15+
}
16+
17+
console.log(`${
18+
error ?
19+
'🚨 Integration tests completed with errors.' :
20+
'🏁 Integration tests completed successfully!'
21+
}`);
22+
};
23+
24+
runIntegrationTests();

helpers/integration-tests/scanner.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const puppeteer = require('puppeteer');
2+
3+
const runScannerTest = async () => {
4+
const browser = await puppeteer.launch();
5+
const page = await browser.newPage();
6+
7+
await page.goto('https://sonarwhal-staging.azurewebsites.net/scanner/');
8+
await page.type('#scanner-page-scan', 'https://leosl.github.io/');
9+
10+
const [response] = await Promise.all([
11+
page.waitForNavigation(),
12+
page.click('.button--red')
13+
]);
14+
15+
await browser.close();
16+
17+
console.log(
18+
`🧾 Scanner test executed with ${
19+
response.status() === 200 ? '✅ success' : '❌ failure'
20+
}! => Status: ${response.status()}`
21+
);
22+
23+
return response.status() !== 200;
24+
};
25+
26+
module.exports = { runScannerTest };
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const puppeteer = require('puppeteer');
2+
3+
const staticURLsToVerify = [
4+
'https://sonarwhal-staging.azurewebsites.net/',
5+
'https://sonarwhal-staging.azurewebsites.net/search/?q=bla',
6+
'https://sonarwhal-staging.azurewebsites.net/about/changelog/1',
7+
'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
8+
];
9+
10+
const runPuppeteer = async (url) => {
11+
const browser = await puppeteer.launch();
12+
13+
try {
14+
const page = await browser.newPage();
15+
const response = await page.goto(url);
16+
17+
console.log(
18+
`${
19+
response.status() === 200 ? '✅ Success' : '❌ Failure'
20+
}! ${url} => Status: ${response.status()}`
21+
);
22+
23+
await browser.close();
24+
25+
return response.status();
26+
} catch (error) {
27+
console.error('🚨 Something went wrong while executing Puppeteer: ', error);
28+
await browser.close();
29+
30+
return 0;
31+
}
32+
};
33+
34+
const runStaticTests = async () => {
35+
let errorFound = false;
36+
37+
for (const url of staticURLsToVerify) {
38+
const resultStatus = await runPuppeteer(url);
39+
40+
if (resultStatus !== 200) {
41+
errorFound = true;
42+
}
43+
}
44+
45+
return errorFound;
46+
};
47+
48+
module.exports = { runStaticTests };

package.json

+1
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)