Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@joeblew999
Copy link
Contributor

Summary

This PR adds two improvements for testing and integration:

1. Handler() Method

Exposes the internal HTTP handler for use with test frameworks and custom servers:

// Handler returns the underlying http.Handler for use with custom servers or testing.
func (v *V) Handler() http.Handler {
    return v.mux
}

Use cases:

  • Direct handler testing with gost-dom, httptest, etc.
  • Custom server integration (embedding Via in existing servers)
  • Middleware wrapping for auth, logging, etc.

2. SSE Closed Pipe Error Suppression

When browsers/clients close before SSE handlers detect the closure, Via logged noisy errors:

[error] msg="PatchElements failed: io: read/write on closed pipe"

Now checks if context is cancelled before logging, avoiding noise during normal shutdown and testing.

Testing

Successfully tested with gost-dom headless browser:

  • Full SSE/Datastar reactivity testing
  • Button clicks triggering server actions
  • ~50ms test execution (vs seconds with real browser)

Example test using the new Handler() method:

func TestMyPage(t *testing.T) {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    v := via.New()
    v.Page("/test", func(c *via.Context) { /* ... */ })

    b := browser.New(
        browser.WithScriptEngine(v8engine.DefaultEngine()),
        browser.WithContext(ctx),
        browser.WithHandler(v.Handler()), // New method!
    )
    defer b.Close()

    win, _ := b.Open("http://localhost/test")
    // assertions...
}

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 [email protected]

joeblew999 and others added 2 commits December 10, 2025 13:48
Exposes the underlying http.Handler to enable:
- Integration testing with gost-dom/browser for SSE/Datastar testing
- Custom server setups (e.g., embedding Via in existing applications)
- Standard Go httptest patterns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Don't log error when SSE fails to send patches if the connection was
already closed. This reduces noise in logs during shutdown and testing,
where browsers/clients close connections before server handlers finish.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@joaomdsg joaomdsg merged commit 6da518d into go-via:main Dec 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants