-
Notifications
You must be signed in to change notification settings - Fork 70
Add integration test for staging env w/ Puppeteer #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
799002a
New: integration test for staging env w/ Puppeteer
LeoSL 2ededd4
Convert Promises chain to async/await syntax
LeoSL 6d54958
Execute a deeper and isolated scanner test
LeoSL 441db95
Simplify static test run
LeoSL b3cc36d
Delete integration-tests_deprecated.js
LeoSL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { runStaticTests } = require('./staticUrls'); | ||
const { runScannerTest } = require('./scanner'); | ||
|
||
console.log('Integration tests are running...'); | ||
|
||
const runIntegrationTests = async () => { | ||
let error = false; | ||
|
||
for (const test of [runStaticTests, runScannerTest]) { | ||
const errorFound = await test(); | ||
|
||
if (errorFound) { | ||
error = true; | ||
} | ||
} | ||
|
||
console.log(`${ | ||
error ? | ||
'🚨 Integration tests completed with errors.' : | ||
'🏁 Integration tests completed successfully!' | ||
}`); | ||
}; | ||
|
||
runIntegrationTests(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const puppeteer = require('puppeteer'); | ||
|
||
const runScannerTest = async () => { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
|
||
await page.goto('https://sonarwhal-staging.azurewebsites.net/scanner/'); | ||
await page.type('#scanner-page-scan', 'https://leosl.github.io/'); | ||
|
||
const [response] = await Promise.all([ | ||
page.waitForNavigation(), | ||
page.click('.button--red') | ||
]); | ||
|
||
await browser.close(); | ||
|
||
console.log( | ||
`🧾 Scanner test executed with ${ | ||
response.status() === 200 ? '✅ success' : '❌ failure' | ||
}! => Status: ${response.status()}` | ||
); | ||
|
||
return response.status() !== 200; | ||
}; | ||
|
||
module.exports = { runScannerTest }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 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 errorFound = false; | ||
|
||
for (const url of staticURLsToVerify) { | ||
const resultStatus = await runPuppeteer(url); | ||
|
||
if (resultStatus !== 200) { | ||
errorFound = true; | ||
} | ||
} | ||
|
||
return errorFound; | ||
}; | ||
|
||
module.exports = { runStaticTests }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.