-
Notifications
You must be signed in to change notification settings - Fork 921
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 initial test framework with TS #638
base: master
Are you sure you want to change the base?
Conversation
This looks great! I'm excited to be able to run some tests here to verify things look correct across different versions of Prerender and different versions of Chrome. I'll add a few minor comments as I look though things more closely. Thanks for doing this! |
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 think the package-lock.json is out of sync after this change and will need to be updated. Shouldn't be an issue but we'll want to make sure those match if we pin these.
process.exit(); | ||
}, 500); | ||
return new Promise((resolve, reject) => { | ||
this.appServerReference = this.app.listen(this.expressOptions, () => { |
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 do like this better for being able to start/stop for tests, but since the lib/index.js
used to call app.listen and then server.start()
would actually start the Chrome server, does that make this a breaking change requiring a major version bump? I'd argue no one would actually include lib/index.js
without calling server.start()
since that would have been useless, but just a thought.
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 a very good point, thanks! Actually we can still keep it backwards compatible, if i'm not mistaken. The lib/index.js
is not an entry point of the app, so it may be good as is now. However the ./index.js
is a de-facto entry point, where I added the server.start()
invocation now. And the server.js
still does what we need, if I didn't mess it up :)
What do you think?
This is super awesome. I like how the tests are set up. Simple and clear with the input/output files. The only thing I'd change would just be a few function names in the tests to be a bit more verbose to more easily understand at a glance:
Since you are starting an express server to serve the input files from a URL, I feel like it reads a little easier like:
It doesn't have to be exactly that, but something like that. Thoughts? |
It looks like this doesn't run on Node v10 (I tested with
Looks like that should be an easy change to get working with Node v10. |
Right, sorry for that. I was using v14 and forgot to test on v10. Fixed now. |
I double checked |
Good call! I did a similar structure now. I still kept the test server URL to be appended automatically to What do you think? |
e908d85
to
4abd93e
Compare
This PR adds the foundations of a test framework where we can send requests through the Prerender server and compare the results to an expected output in a lenient way.
The PR is quite large, but has atomic commits, so it's easy to review it commit-by-commit:
pin dependencies
: Some initial cleanup of the dependencies before refactoradd programmatic start-stop
: Adds the possibility to programmatically start and stop the Prerender server without side effects (almost... needs some more refactor to be truly side effect-less). Also removes theprocess.exit
calls that makes tests difficult. I did the refactor the least intrusive way I possibly could and tried to use the same coding style. My thinking is that any bigger refactor to that part should only come when there are adequate tests available.fix leaked timeouts
: Fixes two setTimeout calls that were blocking the server to properly exit on request.add initial tests with TS
: This adds the actual test suite. Only tests a few flows for now, but it's quite easy to extend.