c_fitzmaurice's avatar

Laravel Mix is breaking a Feature test?

So I have a new Laravel 5.4 install on Valet and I'm trying to start to write tests.

The test is very straight forward and the view is working great in the browser and the stock Laravel Auth routes are working great. I'm at a loss as to why this is failing when I run phpunit

public function testGetLoginUrl()
{
    $response = $this->get('/login');

    $response->assertStatus(200);
}

The test fails here:

1) Tests\Feature\AuthTest::testGetLoginUrl
Expected status code 200 but received 500.
Failed asserting that false is true.

With the following in the the log file:

[2017-03-06 15:52:52] testing.ERROR: Exception: The Mix manifest does not exist. in /Users/Colin/Sites/mynewwebsite/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:579
Stack trace:
#0 /Users/Colin/Sites/mynewwebsite/storage/framework/views/88246e21a9b3de4c7945c5bb4e0e978721851d91.php(16): mix('/css/app.css')
...
...
0 likes
10 replies
ejdelmonico's avatar

Assuming that the test file is standard, are you using versioning? You are getting a page error because of assets not found in the manifest file. Also, make sure you upgrade to the latest Mix.

c_fitzmaurice's avatar

@ejdelmonico I'm using the default webpack.mix.js file that ships Laravel and has versioning in it. I have upgraded all composer packages and npm packages, including Mix ("laravel-mix": "^0.8.8",). When viewing my site in the browser it works great with the mix('/css/app.css') and mix('/js/app.js') calls. It's even working with Dusk. And yes, I am using a test class generated with an artisan cmd.

ejdelmonico's avatar

Hmm, that is really odd. Try clearing all caches through artisan. It's a crap shoot, but I have seen stranger things.

c_fitzmaurice's avatar

@bashy It gets the file when I cURL it too.

I also just ran laravel new trialApp, then php artisan make:auth and changed the default test case to the /login url and made sure the default app.blade.php was using the mix() calls and it also failed. If anyone wants to quickly try to replicate this.

Is there something I have to do to test Mix with phpunit that I am missing?

bashy's avatar

I've not had to do anything but it could of changed in a release on laravel/laravel

1 like
ejdelmonico's avatar

Do any of the ExampleTest files work ( Features/ExampleTest or Unit/ExampleTest)?

ejdelmonico's avatar

I was just wondering if something didn't install properly. Another thing I have done in past when having issues with a manifest file is to trash everything that npm run dev produces in the public directory and re-run it. So, that would be to remove the

  • css/
  • js/
  • fonts/
  • mix-manifest.json

It's worth a shot.

This is whats probably causing the issue and why I suggested above:

 if (! $manifest) {
            if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
                throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);
        }

It still seems like you didn't add version() to your webpack.mix.js file. Like this:

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .version();

and then use mix('someFile') in your blade file.

spar_x's avatar

I just ran into this same problem.. had my head scratching for 20 minutes!

I figured out the problem was that public_path() was returning "source" instead of what you normally expect from public_path(). It worked fine from the web but when running "phpunit" it gave this odd error.

Still can't really figure out why this behaviour happened. But I then realized I was using some sort of global phpunit to run it from the root.

I then tried running it as ./vendor/bin/phpunit and bam error went away

Please or to participate in this conversation.