Make browser tests read the built assets even with the dev server running - #340
Closed
paulocastellano wants to merge 1 commit into
Closed
paulocastellano wants to merge 1 commit into
paulocastellano wants to merge 1 commit into
Conversation
…ning
tests/BrowserTestCase already says these tests load the built Vite assets,
but it only turned off the manifest fake. Laravel still prefers public/hot
when it exists, so on any machine with `npm run dev` running the browser
tests silently loaded the app from the Vite dev server instead of the build
that `npm run build` had just produced.
That is enough on its own to make three tests fail locally while CI, which
has no hot file, stays green. The dev server resolves
`import.meta.glob('../../lang/*.json')` lazily at runtime, and the
laravel-vue-i18n Vite plugin deletes lang/php_*.json when a build finishes,
so the page rendered raw translation keys -- "auth.legal" instead of the
sentence with the Terms of Service and Privacy Policy links, and the raw
repurposes.health.source_missing key instead of the banner.
Pointing the hot file at a path that can never exist makes the browser tests
use the manifest unconditionally, which is what they claim to do and what CI
has been doing all along.
AuthLegalLinksTest the login screen shows the legal sentence
AuthLegalLinksTest the register screen shows the legal sentence
RepurposeAccountHealthTest a repurpose whose source was deleted ...
The HTTP server the browser plugin runs lives in the test process
(Pest\Browser\Drivers\LaravelHttpServer resolves the kernel out of the same
container), so a setUp() override reaches the rendered page.
Contributor
Author
|
Folded into #339 so the dead-code removal ships with a browser suite that is actually green locally. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three browser tests fail on any machine with
npm run devrunning, and pass in CI. Same root cause for all three.What was happening
tests/BrowserTestCasesays in its own docblock that these tests load the built Vite assets, but$fakesVite = falseonly turns off the manifest fake. Laravel's Vite helper still preferspublic/hotwhenever that file exists — and it exists on every machine runningnpm run dev. So the browser tests were loading the app from the Vite dev server, not from the buildnpm run buildhad just produced.That alone would be tolerable. What makes it fail is the interaction with i18n:
resources/js/app.ts:63resolves translations lazily withimport.meta.glob('../../lang/*.json').lang/php_*.jsonis generated by thelaravel-vue-i18n/viteplugin and gitignored (.gitignore:6).npm run buildwhilenpm run devis up and the dev server's runtime glob resolves nothing.The page then renders raw translation keys. From the failure screenshot:
auth.login.title,auth.login.email,auth.legal. SoassertVisible('@legal-links')passed (the div is there) whileassertSeeLink('Terms of Service')could not find the links, andRepurposeAccountHealthTestsaw the literalrepurposes.health.source_missinginstead of the banner sentence.CI has no hot file, so it always used the manifest and never saw any of this.
The fix
Pointing the hot file at a path that can never exist makes the browser tests use the manifest unconditionally — what the class already claimed to do, and what CI has been doing all along. No effect in CI, where the hot file is absent either way.
This works because the HTTP server the browser plugin runs lives in the test process:
Pest\Browser\Drivers\LaravelHttpServer::handleRequest()resolves the kernel out of the same container, so asetUp()override reaches the rendered page.Verification
php artisan test tests/Browser --compact, withnpm run devrunning:vendor/bin/pintpasses.BrowserTestCaseis only extended bytests/Browser(tests/Pest.php:32), so nothing else is touched.