nuxt / test-utils

🧪 Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
287 stars 74 forks source link

feat: allow to run e2e tests against existing server #803

Open tobiasdiez opened 3 months ago

tobiasdiez commented 3 months ago

Allow to pass the url of an already running server to setup and use this as the target instead of building and running a new server. This has two use cases:

  1. Run tests against a deployment of your application (i.e. "real" end-to-end tests)
  2. During local development, run tests against a already running dev server. This reduces the time to run tests and was wished for in eg https://github.com/nuxt/test-utils/issues/314#issuecomment-1983129269.

Usage:

setup({ endpoint: process.env.TEST_URL })

(or of course just using a hard-coded url)

tobiasdiez commented 2 months ago

@danielroe friendly ping. Is there anything a can improve in this PR?

danielroe commented 2 months ago

I love this and would like to get this or something like it merged, but just want to make sure we do it in the best way. Will review soon.

danielroe commented 2 months ago

@tobiasdiez Is the only use-case here avoiding restarting/rebuilding the server when running tests? (ie. if we can solve that issue, do you still think this is a needed feature?)

tobiasdiez commented 2 months ago

My use cases are:

Personally, the first use case is actually more important for me.

adamdehaven commented 1 week ago

This PR seems ideal for my use-case as well. We build for the nitro preset cloudflare-module which doesn't seem to be compatible out of the box with @nuxt/test-utils, meaning I have to override the preset when running tests to node-server.

Being able to do a build separately, running the build via wrangler, and then pointing the tests to the URL speeds things up exponentially.

The only issue I encounter is that it cannot seem to fetch the manifest:

passing test manifest error

@danielroe I'd be open to other ways of speeding up/reusing a build, but this PR seems promising other than the manifest error above

danielroe commented 7 hours ago

I think we'll go ahead with this approach. Would you be able to add a test? 🙏