pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Browser testing doesn't work for domain based routing

Open chrispage1 opened this issue 4 months ago • 10 comments

What Happened

Hi,

I installed PestPHP 4 for its browser testing but my project uses domain based routing.

I can completely see how this presents an issue and why this is problematic, I considered overriding the domain to the temporary server URL but I don't know it until its happened as the port is dynamic.

Is there a workaround for this?

How to Reproduce

Pull down the test project and run the tests

Sample Repository

https://github.com/chrispage1/pest4-testing

Pest Version

4.0.0

PHP Version

8.4.11

Operation System

macOS

Notes

No response

chrispage1 avatar Aug 21 '25 11:08 chrispage1

currently having fun at laravel live dk, can you try to come up with a pull request for that? check the laravel http server class, and see if you can "by pass" that check.

nunomaduro avatar Aug 21 '25 11:08 nunomaduro

currently having fun at laravel live dk, can you try to come up with a pull request for that? check the laravel http server class, and see if you can "by pass" that check.

Will do Nuno 🫡 Hope you're enjoying Laravel Live!

chrispage1 avatar Aug 21 '25 12:08 chrispage1

Hey @nunomaduro - I've raised a PR in the Laravel project as this seems like a logical place to do it!

chrispage1 avatar Aug 21 '25 13:08 chrispage1

I found this issue after creating a PR in the browser plugin which overrides the host header as @nunomaduro mentioned before. I don't want to boast my PR here but thought it could help in deciding what approach would suit this issue best.

ju5t avatar Aug 25 '25 12:08 ju5t

I found this issue after creating a PR in the browser plugin which overrides the host header as @nunomaduro mentioned before. I don't want to boast my PR here but thought it could help in deciding what approach would suit this issue best.

Ah I do like you're implementation here! It does make sense that it's perhaps better to specify the hostname rather than ignore altogether as that is then another level of testing.

chrispage1 avatar Aug 25 '25 21:08 chrispage1

We also have domain based routing (several domains) in a monorepo. In our existing playwright tests we had fixtures for each domain that would set things like the base url for all requests.

calebdw avatar Sep 02 '25 18:09 calebdw

It was added https://github.com/pestphp/pest-plugin-browser/commit/d917f1b30107e3608833d18794749dd6995f0d9d and removed again https://github.com/pestphp/pest-plugin-browser/commit/45e762f14cc20072d85c83cc2513cbeac6fe6584. What is the current state of supporting multi domain projects @nunomaduro ?

okaufmann avatar Oct 16 '25 13:10 okaufmann

We also have domain based routing (several domains) in a monorepo. In our existing playwright tests we had fixtures for each domain that would set things like the base url for all requests.

Do you reckon there is a way to do this with Pest 4, even as a workaround? I imagine navigating between different subdomains would not work? Could you give us an idea of what those fixtures looked like?

pindab0ter avatar Nov 22 '25 15:11 pindab0ter

I don't think there is a workaround at the moment. The way this plugin is structured means you don't have access to the Symfony request that gets passed to the HTTP server they boot up. And you need that to set a Host header.

My PR did all that, but it got removed later without any feedback, which is a shame, but it is what it is.

ju5t avatar Nov 22 '25 16:11 ju5t

We also have domain based routing (several domains) in a monorepo. In our existing playwright tests we had fixtures for each domain that would set things like the base url for all requests.

Can you please share or give an idea how to set up fixtures like these?

abrardev99 avatar Dec 01 '25 10:12 abrardev99