[9.x] Handle requests in test (rather than separate server process) #1170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, Dusk makes requests to a separate server process. This has a few downsides:
_dusk/
routes rather than using normal factories/setup.env.dusk
handling is necessaryRefreshDatabase
, aren't availableThis proof-of-concept adds an HTTP server and custom web driver implementation that lets us handle the entire Dusk lifecycle inside our test process. This allows us to treat incoming browser requests as though they were the same as
$this->get(...)
or$this->post(...)
right in the test case.Considerations
For the most part, this is a pretty minimal change for the impact it could have. That said, there are a few things to consider:
https://demo-app.test/profile
intohttp://localhost:8099/profile
. This doesn't account for things like domain-routing. Probably the easiest solution is to just pass the entire request as a query string, so something likehttp://localhost:8099/?url=https://demo-app.test/profile
. This shouldn't be that hard, but might need some further thought.Laravel\Dusk\Http\Controllers\UserController
which is no longer necessary with this approach, and the logic around.env.dusk
that is also not necessary. Before I go ahead and make the diff that much larger, I'd like a little bit of community/maintainer feedback.If anyone out there has a big Dusk testsuite that they want to try this with, I'd love some real-world feedback!
How to test
If you don't have
repositories
key in yourcomposer.json
file, add one, and then add my fork to it.Then, install my branch:
Finally, if you
DuskTestCase
implements thedriver()
method, you need to swapFacebook\WebDriver\Remote\RemoteWebDriver
forLaravel\Dusk\Driver\AsyncWebDriver
.