nuxt / nuxt/test-utils

Why do errors occur when using '@nuxt/test-utils/e2e' for API testing?

Open
#874 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug vitest-environment
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

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 and browser to false. The error is apparently due to the absence of an index.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 https://github.com/nuxt/nuxt/discussions/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

await setup({
    rootDir: fileURLToPath(new URL('../..', import.meta.url)),
    server: true,
    browser: false,
    dev: true,
    setupTimeout: 600 * 1000
  });

I am setting server to true and browser to false. I am seeing the following error

25 06 2024_20 41 31_REC

I 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

import { defineVitestConfig } from '@nuxt/test-utils/config';

export default defineVitestConfig({
  test: {
    reporters: 'verbose',
    passWithNoTests: true
  }
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @nuxt/test-utils/e2e setup shown in the issue and the referenced Vitest configuration. Reproduce the server=true and browser=false case with and without /pages/index.vue, then compare the result with the related discussion. Done would be a documented explanation or an agreed change clarifying whether server-only API tests should require frontend routes.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs
Domain
api, backend, testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.