Skip to content
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

Fix test runner, smarter server #168

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Fix test runner, smarter server #168

merged 1 commit into from
Feb 13, 2024

Conversation

klebba
Copy link
Collaborator

@klebba klebba commented Feb 13, 2024

Fixes #167

@klebba klebba requested a review from theengineear February 13, 2024 22:35
@klebba klebba self-assigned this Feb 13, 2024

server.listen(process.env.PORT || 8080, () => {
const { address, port } = server.address();
Server.origin = `http://[${address}]:${port}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use introspection to generate the origin component necessary to qualify the path and leverage URL above for smarter path parsing.

static requestListener(request, response) {
if (request.method === 'GET') {
const fileUrl = request.url;
const filePath = path.resolve(`${root}/${fileUrl}`);
const url = new URL(request.url, Server.origin);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adopting URL here we can easily extract pathname and fix the confusion around paths which incorporate query params. Easy peasy.

@@ -3,7 +3,17 @@ import puppeteer from 'puppeteer';
(async () => {
try {
// Open our browser.
const browser = await puppeteer.launch({ timeout: 10000 });
const browser = await puppeteer.launch({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just a few flags I borrowed from another project (Profiler)

timeout: 10000,
// opt-in to the new Chrome headless implementation
// ref: https://developer.chrome.com/articles/new-headless/
headless: 'new',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we using the new, new. Cool.

args: [
// Disables interactive prompt: Do you want to the application Chromium.app to accept incoming network connections?
// ref: https://github.com/puppeteer/puppeteer/issues/4752#issuecomment-586599843
'--disable-features=DialMediaRouteProvider',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Collaborator

@theengineear theengineear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround @klebba!

@klebba klebba merged commit 9f03e5d into main Feb 13, 2024
1 check passed
@klebba klebba deleted the fix-tests branch February 13, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Puppeteer tests seem to no longer work when run locally.
2 participants