-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add integration test for staging env w/ Puppeteer #843
Conversation
f4febc7
to
6c457a7
Compare
helpers/integration-tests.js
Outdated
.finally(() => { | ||
if (index === (URLsToVerify.length - 1)) { | ||
resolve(responses); | ||
browser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browser.close()
returns a Promise.
I'm thinking of 2 possibilities, if you have a better one please go for it:
- Add the condition after
responses.set()
. Although we might end up with a bit more nesting 🤔 - Use
async/await
inside afor..of
and test the pages one by one. This might make the code a bit easier even if it means the test will take a few more seconds (which is fine TBH).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to keep the responses in a Map
.
As @molant says, you should use async/await
inside a for..of
and after each scan, print the status (that way we can see if it is failing more than one url) and after all the urls are scanned, throw and error if there was any exception (or maybe it is enough if we return an exitCode !== 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, IMO, we should check that running a scan is working too.
helpers/integration-tests.js
Outdated
.finally(() => { | ||
if (index === (URLsToVerify.length - 1)) { | ||
resolve(responses); | ||
browser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to keep the responses in a Map
.
As @molant says, you should use async/await
inside a for..of
and after each scan, print the status (that way we can see if it is failing more than one url) and after all the urls are scanned, throw and error if there was any exception (or maybe it is enough if we return an exitCode !== 0)
@sarvaje Can you please clarify what you mean by "check that running a scan is working"? |
Sorry hehehe. I mean going to the Some times, everything looks good, but then when you scan an url, something is broken. |
There are a couple methods in puppeteer that make this relatively easy:
Because we are going to navigate to a page we will probably have to use await page.goto('/scanner/');
await page.type('selector for input', 'url to analyze');
const [result] = await Promise.all([
page.waitForNavigation(),
page.click('selector for button')
]);
// check result here |
6c457a7
to
2e49c25
Compare
@molant I've rebased from upstream master and did the following:
Let me know if the changes sound good to you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good @LeoSL !
I just have one comment that I hope you can check for me. Otherwise this is almost done!
@@ -0,0 +1,53 @@ | |||
const puppeteer = require('puppeteer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need this file 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I forgot that one! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this file is still in the PR
return new Promise((resolve) => { | ||
let errorFound = false; | ||
|
||
staticURLsToVerify.forEach(async (url, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe .forEach
doesn't await
so all the items in the array are called at the same time and thus starting multiple different instances of the browser. When testing this how many separate chrome windows did you see? Was it just one being opened and closed or several?
If you saw multiple instances then we should probably change this to something like this:
const runStaticTests = async () => {
let errorFound = false;
for (const url of staticURLsToVerify) {
const resultStatus = await runPuppeteer(url);
if (resultStatus !== 200) {
errorFound = true;
}
}
return errorFound;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@molant I'm running the Chrome headless version so I don't observe the windows popping up - thus I can't answer your question about the instances.
When running on the CLI they appear pretty much sequential on all my tests. I'm assuming that if they're being fired sequentially the printing (console.log) order would change on an ad hoc basis.
If you're strong about the for..of
I can check it out later but I believe it would require a lot of other logic changes because I wouldn't have access to the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I suspected forEach
doesn't await
, I've been bitten by this in the past 😅
With the code I posted earlier you don't need access to the index. Because the urls are being analyzed sequentially, as soon as the for..of
ends you can return errorFound
. We also add the keyword async
so no need to create a Promise
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great, thanks @molant
I will do the fixes later today! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@molant Done!
- 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
- Also, run both static and scanner tests sequentially to a better console logging experience
2e49c25
to
441db95
Compare
Sorry, @molant forgot again to remove. Now I believe everything looks fine! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one NIT, but nothing blocking.
@molant Looks like we two approvals now. Is there anything else you wanted or is this good to merge? |
Good to merge. Haven't had the time to merge today. Can you please take care of it?
…________________________________
From: Tony Ross <[email protected]>
Sent: Monday, October 14, 2019 13:20
To: webhintio/webhint.io
Cc: Antón Molleda; Mention
Subject: Re: [webhintio/webhint.io] Add integration test for staging env w/ Puppeteer (#843)
@molant<https://github.com/molant> Looks like we two approvals now. Is there anything else you wanted or is this good to merge?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#843>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAEUDAVEGYOAST5C2AG376DQOTIBFANCNFSM4I5YVAXQ>.
|
Pull request checklist
Make sure you:
Short description of the change(s)
Fix #810
Map() object.
another unknown error.
🕹 How to test
Run the script
node helpers/integration-tests.js
✅If you want to see the script finding an error you can add a bad URL to the URL collection.
Example:
http://pudim.com.br/xunda.jpg