In this episode, we dive into how to create and use a Dusk-specific environment file for your Laravel end-to-end tests. Since Dusk opens up a real browser to interact with your app just like a real user, you can't easily mock out things like API keys or secrets. Instead, you need to provide real (but safe for testing!) values.
You'll see how to copy your main .env
file and create a new one like .env.dusk.local
that you can tweak just for running Dusk tests. We walk through modifying it with test-specific secrets or API keys, then explain how Dusk actually handles swapping out the environment files behind the scenes—backing up your original and restoring it after the tests run.
To prove it's working, we even add a pause in the test so you can visually see the environment file swap take place in real time. By the end of this episode, you'll know how to keep your end-to-end test environment isolated and avoid running tests with your real API secrets. Up next: handling your test database setup!