-
Notifications
You must be signed in to change notification settings - Fork 83
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
Why do errors occur when using '@nuxt/test-utils/e2e' for API testing? #874
Comments
Hey there, @manpreet-compro! I'm here to help you with any bugs, questions, or contributions you might have. Let's tackle this together! The errors occur because the absence of an To resolve this, create a minimal <template>
<div>Welcome to Nuxt</div>
</template> This will satisfy the router's requirement and prevent the 404 errors related to the frontend routes. Additionally, ensure your import { defineVitestConfig } from '@nuxt/test-utils/config';
export default defineVitestConfig({
test: {
dir: './test/nuxt',
coverage: {
include: ['packages/nuxt/src/app'],
},
environment: 'nuxt',
setupFiles: [
'./test/setup-runtime.ts',
],
environmentOptions: {
nuxt: {
overrides: {
runtimeConfig: {
app: {
buildId: 'override',
},
},
experimental: {
appManifest: process.env.TEST_MANIFEST !== 'manifest-off',
},
},
},
},
},
}); For a more specific example of setting up server-side tests, refer to the following code snippet: import { fileURLToPath } from 'node:url'
import { $fetch, setup } from '@nuxt/test-utils/e2e'
import { describe, expect, it } from 'vitest'
await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
})
describe('app', async () => {
it('runs a test', async () => {
const html = await $fetch('/')
expect(html.slice(0, 15)).toMatchInlineSnapshot(`
"<!DOCTYPE html>"
`)
})
}) This should help you set up and run basic server-side tests using |
@manniL Thanks for moving this to test-utils. I've confirmed this works by adding If there is a requirement to hit a URL to confirm the server is up before continuing testing, it could be handled by accepting a configuration parameter to provide a specific URL to check instead of always checking the root URL. @dosu - Tagging in case you can provide more context. If agree to my comment, may be have this in backlog |
You can indeed configure import { describe, test } from 'vitest'
import { setup, $fetch } from '@nuxt/test-utils/e2e'
describe('My test', async () => {
await setup({
browser: {
url: 'http://custom-url-for-server-readiness-checks'
},
// other test context options
})
test('my test', () => {
// ...
})
}) This configuration will direct |
Summary (generated):
Here is a brief summary in English:
A developer is trying to set up end-to-end testing for server-side functionality in a Nuxt app using Nitro, but is encountering errors related to frontend routes despite setting
server
to true andbrowser
to false. The error is apparently due to the absence of anindex.vue
file in the/pages
directory, which is expected to contain application logic. The developer expects the setup to only run the server part and not be concerned with frontend parts.Discussed in nuxt/nuxt#27820
Originally posted by manpreet-compro June 25, 2024
I am working on a Nuxt app and trying to set up end-to-end testing for server-side functionality related to API endpoints I have developed using Nitro. However, I encounter errors related to frontend routes despite my expectation to run only the server part without involving the frontend.
Test server setup code
I am setting
server
to true andbrowser
to false. I am seeing the following errorI found out this error is related to frontend routes, particularly of absence of
index.vue
in my project under/pages
which is expected application logic. I expected this setup to run only the server part and not be concerned with the frontend part.Am I missing something? Any help will be appreciated
Following is vitest config file for reference
The text was updated successfully, but these errors were encountered: