nuxt / test-utils

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

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

Closed tobiasdiez closed 4 months ago

tobiasdiez commented 8 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 7 months ago

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

danielroe commented 7 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 7 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 7 months ago

My use cases are:

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

adamdehaven commented 5 months 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 5 months ago

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

adamdehaven commented 4 months ago

This is awesome and will be super useful for us.

Let me know if the Nuxt docs page needs to be updated and I’m happy to write something up and submit a PR

tobiasdiez commented 4 months ago

@danielroe Thanks for merging. I'll try to add tests when I find the time.

@adamdehaven Would be awesome if you could create a PR adding this option to the docs.

adamdehaven commented 4 months ago

PR to add the new host option, along with a usage example to the Nuxt docs: https://github.com/nuxt/nuxt/pull/28331

Barbapapazes commented 3 months ago

This is so cool! Thank you so much, I will give it a try asap.