Skip to content

test: add Inertia tests and demo - #146

Merged
hwbrzzl merged 3 commits into
masterfrom
bowen/install-inertia-tests
Aug 26, 2026
Merged

test: add Inertia tests and demo#146
hwbrzzl merged 3 commits into
masterfrom
bowen/install-inertia-tests

Conversation

@goravel-coder

@goravel-coder goravel-coder commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds the Inertia integration — github.com/goravel/inertia dependency, service-provider registration, and generated facades.Inertia() facade — so apps can build server-driven Inertia pages with Goravel.
  • Ships a committed, installer-independent demo frontend (Vue 3 + Vite/TypeScript toolchain under resources/inertia/, official Goravel favicon, static asset routes) wired to /inertia/* routes covering deferred/merged props, session flash + validation errors, redirects, and location responses; the demo renders out of the box after go run ., and the page is viewable after running npm run dev (HMR) or npm run build (production bundle served from the gitignored public/build).
  • Adds two test suites: an HTTP suite (8 tests) exercising the full Inertia protocol including full-page vs JSON responses and version-mismatch 409 conflicts, and an installer suite verifying inertia:install scaffolding generation and committed-state restore (including removing the installer-generated public/favicon.png in teardown).

Why

This PR brings Inertia into the example repository as a first-class, copyable demonstration: it installs the package (dependency + provider + generated facade), wires a complete demo through config/inertia.go, a root template, an Inertia() middleware, a controller, and an /inertia/* route group, and commits the Vue 3/Vite frontend so framework users can run the demo immediately without the installer. Static /public and /build routes serve the favicon and production Vite manifest assets, while the goravelHot Vite plugin writes/removes public/hot for zero-config HMR during development.

The behavior is locked in with tests: the HTTP suite drives the full Inertia protocol (full-page HTML vs X-Inertia JSON, version-mismatch conflicts, deferred/merged props, session flash and validation errors, redirects, and location), and the installer suite runs inertia:install end-to-end and restores the committed toolchain and demo so the tree stays clean.

// routes/web.go
facades.Route().Middleware(appmiddleware.Inertia()).Prefix("inertia").Group(func(router route.Router) {
	inertiaController := controllers.NewInertiaController()
	router.Get("home", inertiaController.Home)
	router.Get("feed", inertiaController.Feed)
	router.Get("contact", inertiaController.Contact)
	router.Post("contact", inertiaController.StoreContact)
	router.Get("redirect", inertiaController.RedirectTo)
	router.Delete("redirect", inertiaController.RedirectTo)
	router.Get("location", inertiaController.LocationTo)
})

// app/http/controllers/inertia_controller.go
func (r *InertiaController) Home(ctx http.Context) http.Response {
	facades.Inertia().Defer(ctx, "stats", func() any { return map[string]any{"users": 1280} })
	return facades.Inertia().Render(ctx, "Welcome", map[string]any{"message": "Goravel + Inertia"})
}

func (r *InertiaController) StoreContact(ctx http.Context) http.Response {
	validator, err := ctx.Request().Validate(map[string]any{"email": "required|email"})
	if err != nil || validator.Fails() {
		if validator != nil {
			facades.Inertia().FlashErrors(ctx, validator.Errors())
		}
		return facades.Inertia().Redirect(ctx, "/inertia/contact")
	}
	ctx.Request().Session().Flash("success", "Saved!")
	return facades.Inertia().Redirect(ctx, "/inertia/contact")
}

@goravel-coder
goravel-coder requested a review from a team as a code owner August 22, 2026 07:38
@hwbrzzl
hwbrzzl force-pushed the bowen/install-inertia-tests branch from 3d951f5 to cf053d7 Compare August 24, 2026 10:49
Comment thread public/favicon.png Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread routes/web.go
// Inertia static assets: the committed root template links /public/favicon.png
// and the vite helper emits /build/... URLs from the production manifest.
facades.Route().Static("public", "./public")
facades.Route().Static("build", "./public/build")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the folder be generated in the repo? If no, why need this line?

Comment thread routes/web.go
facades.Route().StaticFile("echo.html", "./resources/views/echo.html")

// Inertia (session-based web routes; StartSession is already global)
facades.Route().Middleware(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an annotation, similar to: If you actually want to visit the page, npm run dev should be run in advance.

@hwbrzzl
hwbrzzl merged commit 0aa1e6b into master Aug 26, 2026
9 checks passed
@hwbrzzl
hwbrzzl deleted the bowen/install-inertia-tests branch August 26, 2026 02:17
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