Skip to content

Commit 2e49c25

Browse files
committed
Execute a deeper and isolated scanner test
1 parent cfd9f2f commit 2e49c25

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

helpers/integration-tests/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { runStaticTests } = require('./staticUrls');
2+
const { runScannerTest } = require('./scanner');
3+
4+
console.log('Integration tests are running...');
5+
6+
const runIntegrationTests = async () => {
7+
const errorFound = await Promise.all([
8+
runStaticTests(),
9+
runScannerTest()
10+
]);
11+
12+
console.log(`${
13+
errorFound ?
14+
'🚨 Integration tests completed with errors.' :
15+
'🏁 Integration tests completed successfully!'
16+
}`);
17+
};
18+
19+
runIntegrationTests();
Lines changed: 26 additions & 0 deletions
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 };

helpers/integration-tests.js renamed to helpers/integration-tests/staticUrls.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const puppeteer = require('puppeteer');
22

3-
const URLsToVerify = [
3+
const staticURLsToVerify = [
44
'https://sonarwhal-staging.azurewebsites.net/',
5-
'https://sonarwhal-staging.azurewebsites.net/scanner/',
5+
'http://pudim.com.br/xunda.jpg',
66
'https://sonarwhal-staging.azurewebsites.net/search/?q=bla',
77
'https://sonarwhal-staging.azurewebsites.net/about/changelog/1',
88
'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
@@ -24,17 +24,22 @@ const runPuppeteer = async (url) => {
2424
return response.status();
2525
};
2626

27-
console.log('⏳ Integration tests are running...');
27+
const runStaticTests = () => {
28+
return new Promise((resolve) => {
29+
let errorFound = false;
2830

29-
URLsToVerify.forEach(async (url, index) => {
30-
let errorFound = false;
31-
const resultStatus = await runPuppeteer(url);
31+
staticURLsToVerify.forEach(async (url, index) => {
32+
const resultStatus = await runPuppeteer(url);
3233

33-
if (resultStatus !== 200) {
34-
errorFound = true;
35-
}
34+
if (resultStatus !== 200) {
35+
errorFound = true;
36+
}
3637

37-
if (index === URLsToVerify.length - 1 && errorFound) {
38-
throw new Error('🚨 Integration test has failed!');
39-
}
40-
});
38+
if (index === staticURLsToVerify.length - 1) {
39+
resolve(errorFound);
40+
}
41+
});
42+
});
43+
};
44+
45+
module.exports = { runStaticTests };

0 commit comments

Comments
 (0)