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

Investigate how to test Netlify Edge Functions #842

Closed
smoya opened this issue Jun 28, 2022 · 19 comments · Fixed by #2493
Closed

Investigate how to test Netlify Edge Functions #842

smoya opened this issue Jun 28, 2022 · 19 comments · Fixed by #2493

Comments

@smoya
Copy link
Member

smoya commented Jun 28, 2022

Reason/Context

We do have a Netlify Edge Function already in https://github.com/asyncapi/website/tree/master/netlify/edge-functions.
But there are no tests yet. We need to investigate how we can test that, since the runtime is Deno and there are some additions Netlify does on their runtime.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Oct 27, 2022
@smoya
Copy link
Member Author

smoya commented Oct 27, 2022

Still relevant

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Feb 25, 2023
@smoya
Copy link
Member Author

smoya commented Feb 27, 2023

still relevant

@github-actions github-actions bot removed the stale label Feb 28, 2023
@Maniktherana
Copy link

I can pick this up. I'm working on a Netlify function for the newsletter subscriptions so it will fit right in.

@smoya
Copy link
Member Author

smoya commented Feb 28, 2023

I can pick this up. I'm working on a Netlify function for the newsletter subscriptions so it will fit right in.

Awesome! Please feel free to ask any questions or request for help!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Jun 29, 2023
@akshatnema akshatnema removed the stale label Dec 7, 2023
@Shurtu-gal
Copy link
Contributor

@smoya found this
Let try it first to see if it works.

@smoya
Copy link
Member Author

smoya commented Dec 7, 2023

@smoya found this
Let try it first to see if it works.

Looks promising! 🙌

@akkshitgupta
Copy link
Contributor

Hey @Shurtu-gal are you working on this issue? If not, I would like to work.

@Shurtu-gal
Copy link
Contributor

Yep still working. Would be glad to receive your opinions too.
Btw @smoya tried the method, turns out it only works for functions not edge ones as they run on Deno runtime.

Have posted this in forum too. I will try to find some new avenues also.

@smoya
Copy link
Member Author

smoya commented Dec 11, 2023

Yep still working. Would be glad to receive your opinions too. Btw @smoya tried the method, turns out it only works for functions not edge ones as they run on Deno runtime.

Have posted this in forum too. I will try to find some new avenues also.

Yeah they run in Deno, I can confirm this to you. But can't we just run the tests on Deno?

About the answer they gave to you:

I believe the only way to test those would be using Netlify CLI. You’d have to start Netlify CLI, use a headless browser like Puppeteer, visit the path with the Edge Functions, and check for expected response.

it will do the job of course, but too overengineered for what we need here. With a simple unit test we are fine.

Anyway, if there is no alternative, we might want to run those tests through any headless browser (like puppeteer does indeed). Not ideal tbh.

@Shurtu-gal
Copy link
Contributor

Yeah, cool will sift through the solutions and would see if can get a Deno test framework up and running. The puppeteer one can be the backup solution if nothing works.

@smoya
Copy link
Member Author

smoya commented Dec 11, 2023

Yeah, cool will sift through the solutions and would see if can get a Deno test framework up and running. The puppeteer one can be the backup solution if nothing works.

Anyway, I think we don't even need deno for that 🤔
Maybe we can just mock the Request and the Context params in a unit test. For the Request, it is an standard Fetch API Request object, and the context could be mocked based on Netlify docs: https://docs.netlify.com/edge-functions/api/. In addition, we would need to mock the fetch API (I think jest already allows you to do so).

Does it make sense? At the end, we want to test if the URL rewrites are done properly without the need of running this as a functional test under a real (headless) browser. The latest could run periodically somewhere but I believe not in CI on each PR because of the overhead.

@Shurtu-gal
Copy link
Contributor

Shurtu-gal commented Dec 11, 2023

Maybe we can just mock the Request and the Context params in a unit test.

However, this can only work with the deployed Netlify link right?

@smoya
Copy link
Member Author

smoya commented Dec 11, 2023

Maybe we can just mock the Request and the Context params in a unit test.

However, this can only work with the deployed Netlify link right?

If we mock the Fetch API, no real request will be done.
Meaning we could just add some expectations on the calls the code does, like this call to fetch() and also this call to context.next() and match request headers, URL, etc among other checks.

@Shurtu-gal
Copy link
Contributor

Done the work, you can check here :-
The sample PR :- ash17290#1
Workflow in action :- https://github.com/ash17290/website/actions/workflows/netlify-edge-functions-test.yml

If its fine I will make a PR @smoya

@smoya
Copy link
Member Author

smoya commented Dec 12, 2023

Done the work, you can check here :-
The sample PR :- ash17290#1
Workflow in action :- https://github.com/ash17290/website/actions/workflows/netlify-edge-functions-test.yml

If its fine I will make a PR @smoya

Nice! I will check asap. Most probably tomorrow. Hope that works to you.

Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants