pestphp / pestphp/pest

[Bug]: VITE 8 - fread on 0 bytes files causes 500 error during browser testing

Open
#1,635 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Drivers/LaravelHttpServer.php and reproduce the failure with a PHP 8.4 browser test using a Vite 8 production build containing a zero-byte JavaScript file. Trace the asset URL rewriting path around fread, then run the affected browser tests and confirm empty assets return successfully instead of producing a 500 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, vite
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.