-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(nuxt): Update Nuxt version and add Nitro $fetch test #17713
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
Conversation
import { defineEventHandler } from '#imports'; | ||
|
||
export default defineEventHandler(async () => { | ||
const data = await $fetch('https://ungh.cc/orgs/unjs/repos'); |
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.
l/m: Never heard of ungh.cc
, do we want to depend on this in the e2e tests? Wonder if example.com is not better.
I remember we've had issues with example.com too tho, so not sure.
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'd recommend avoiding external requests entirely and just intercept the request in playwright. Examaple:
Lines 9 to 19 in 162143f
await page.route('**/foo', route => { | |
return route.fulfill({ | |
status: 200, | |
body: JSON.stringify({ | |
userNames: ['John', 'Jane'], | |
}), | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}); | |
}); |
(not sure how consistent we are with this in e2e tests but this is what we do in the browser integration tests)
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 the endpoint that Nitro uses in their examples: https://nitro.build/guide/fetch
But intercepting sounds like a good idea 👍
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.
Turns out it's not that straightforward to use page.route
here. As the request is not made by the browser but the nitro server, it is not intercepted. And I cannot just call another Nitro server route as Nitro does not create a separate requests when it's within the server. For the test however, I want to specifically test calling an external API and example.com
is okay for this case as the test does not fail if the endpoint cannot be reached. It's just about adding the span.
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
This PR adds the following:
$fetch
requestsapp.vue
file as this is not needed when using theapp/pages
directory (following the Nuxt docs)