Skip to content

Conversation

clydin
Copy link
Member

@clydin clydin commented Sep 16, 2025

Adds a Vite middleware to the Vitest runner to serve assets and global stylesheets that are part of the build output.

Previously, when running component tests with Vitest, any referenced assets (such as images in an <img> tag) or component stylesheets would result in a 404 error because the Vite server was not configured to serve them.

This change introduces a middleware that intercepts requests for non-script files. It checks against the build's output files and serves the corresponding asset directly from memory or disk. This ensures that the test environment accurately reflects the assets available during a real build, allowing components to render correctly for testing.

Closes #30440

Adds a Vite middleware to the Vitest runner to serve assets and global stylesheets that are part of the build output.

Previously, when running component tests with Vitest, any referenced assets (such as images in an `<img>` tag) or component stylesheets would result in a 404 error because the Vite server was not configured to serve them.

This change introduces a middleware that intercepts requests for non-script files. It checks against the build's output files and serves the corresponding asset directly from memory or disk. This ensures that the test environment accurately reflects the assets available during a real build, allowing components to render correctly for testing.
@clydin clydin added the target: major This PR is targeted for the next major release label Sep 16, 2025
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 16, 2025
@clydin clydin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 16, 2025
@clydin clydin merged commit dae7320 into angular:main Sep 16, 2025
35 checks passed
@clydin clydin deleted the unit-test/vitest-assets branch September 16, 2025 22:29
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/build:unit-test requires absolute paths

2 participants