Skip to content

[Bug]: fread on 0 bytes files causes 500 error during browser testing #1635

@giorgiopogliani

Description

@giorgiopogliani

What Happened

After i build my assets all the browser tests fail with this error.

FAILED Tests\Tenant\Customers\CustomerBrowserTest > it can edit a customer through the browser
Timeout 5000ms exceeded. A screenshot of the page has been saved to [Tests/Browser/Screenshots/it_can_edit_a_customer_through_the_browser].

The generated screenshot is a white page. After digging deeper with the help of claude it found an issue on some js routes. Some files of 0 bytes here the reported explanation:

The error only happens in Pest Browser because it uses an in-process Amp HTTP server (LaravelHttpServer) that has a bug: it calls fread($file, 0) on JS files to rewrite
asset URLs. PHP 8.4 throws a ValueError on fread with length 0, so instead of returning an empty 200, it crashes with a 500.

After its patch in src/Drivers/LaravelHttpServer.php i applied temporarly in my vendor files that check the size of the file before the fread and tests are passing correctly.

How to Reproduce

Any browser tests that checks rendered javascript using vite 8 prod build. Not sure it happens also with vite 7. I also use shadcn vue and claude is saying the some index.ts that just re-exports components becomes empty files during the build.

Sample Repository

No response

Pest Version

4.3.2

PHP Version

8.4

Operation System

macOS

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions