Migrate only once with Laravel dusk

Wrangled with this for a while today and running migrations in conjunction with migrations seems to do the trick. A snapshot of my test is as follows:

<?php

namespace Tests\Browser;

use App\User;
use Tests\DuskTestCase;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class DefaultTest extends DuskTestCase
{
    use DatabaseMigrations, DatabaseTransactions;

    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function test_something()
    {
        //Add test stuff here
    }
}

I've got a couple of factories in my actual test and they seem to run through the migrations with the data destroyed after the test as expected.


It is not possible to run DatabaseTransactions in combination with dusk for the moment.

https://github.com/laravel/dusk/issues/110

The creation of the user record and the use of it in the browser are done in two different processes. This means the created user is part of a database transaction which is not committed and thus not accessible by the browser process.

Database migrations work. So you should use those. Also make sure you run a seperate testing database so you don't mess with your production/development database.

https://laravel.com/docs/5.4/dusk#environment-handling

To force Dusk to use its own environment file when running tests, create a .env.dusk.{environment} file in the root of your project. For example, if you will be initiating the dusk command from your local environment, you should create a .env.dusk.local file.

When running tests, Dusk will back-up your .env file and rename your Dusk environment to .env. Once the tests have completed, your .env file will be restored.

The provided answer works because DatabaseMigrations work. The use DatabaseTransactions is not relevant.