Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sail + Dusk not picking up Dusk specific .env file (.env.dusk.local) #667

Closed
chrismacp opened this issue Feb 14, 2024 · 9 comments
Closed

Comments

@chrismacp
Copy link

Sail Version

1.27.4

Laravel Version

v10.44.0

PHP Version

v8.3.2-1

Operating System

Linux

OS Version

ubuntu22.04.1+deb.sury.org+1

Description

Hi,
Not sure if this is a Sail issue or a Dusk issue, I decided to register the problem here.

In the Laravel Dusk documentation is states that you can create a seperate ENV file for Dusk testing by naming it .env.dusk.{environment}.

When I do this it appears that the ENV values that were set in .env.local are still used by the system and the dusk specific file is ignored.

This may be something to do with the combination of SAIL + Dusk? I couldn't find a clear example of this working anywhere online but he documentation seems to suggest it should work.

Steps To Reproduce

I created a repo with a test that shows the problem. See the instructions in this commit (copied below as well).

Reproduction

Requirements: check out https://github.com/chrismacp/dusk-bug.git

  1. Start the sail app:
./vendor/bin/sail up
  1. Open the .env file in your IDE so you can watch it change as the ENV is updated by Dusk.

  2. Run e2e test

./vendor/bin/sail dusk
  1. See that:
  • 1 test fails in tests/Browser/EnvTest
  • The first test in the same test file passes when it shouldn't
@driesvints
Copy link
Member

Does it work if you run Dusk outside Sail?

@chrismacp
Copy link
Author

I can't run it outside of Sail as Sail is my dev environment. I mean I could if I installed everything locally I suppose but the whole point of using Sail was so that I could run my dev environment in containers so it's the same across machines.

I'll try and have a go at setting it up just to see what happens.

@chrismacp
Copy link
Author

chrismacp commented Feb 15, 2024

Just to add to the original problem description. The repo I created is a fresh Sail project install with only a test and a controller/view added so the problem shouldn't be anything unique to my project.

@chrismacp
Copy link
Author

@driesvints I created a non-sail project and I see the same problem occuring there, so I guess this is a Dusk problem. I'll raise the bug there instead.

@driesvints
Copy link
Member

Does laravel/dusk#851 help?

@chrismacp
Copy link
Author

I was actually trying the solutions out in that thread and some stackoverflow answers too. I have not seen any change to the environment at all in my test.

It's weird as I can visibly see the .env file is updated by Dusk when I run the tests, however the DB_DATABASE env var never changes.

I have tried the following

  • Creating a phpunit.dusk.xml as indicated in some answers.
  • Supplying --env=local or --env=dusk.local when running Dusk
  • Supplying all Database configuration options in the .env.dusk.local as well as just overriding individual variables.

@chrismacp
Copy link
Author

Just to ensure i'm not going mad, is the following an accurate description of how this should work?

  1. Start app: sail up
    • This is using the .env.local environment file by default (I have one set up).
  2. Run Dusk: sail dusk
    • This should detect the .env.dusk.local and merge it into .env.local
    • The running Sail app (from point 1) should detect an environment change and reinitialise its config to the merged values above.
    • Therefore both the process running the tests and the process running the app are using the same environment.

@chrismacp
Copy link
Author

I think I fixed the problem. Most likely my own doing (sorry!)

I think the .env.local file I have is causing the problem. When I delete it, leaving me with just the .env and .env.dusk.local then the tests have the correct merged environment.

I guess this file is causing confusion. I thought it was being used to create the initial .env file automatically but I realised that it was the app creation/install the at generates the initial .env file. From that point on I was assuming the wrong action was taking place.

Anyway it's working now. We can close this as there is no problem. I'm not sure why the .env.local is breaking stuff but I've spent too long on this already.

@driesvints
Copy link
Member

Ah good that you figured that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants