- Introduced .editorconfig for consistent coding styles across the project. - Added .golangci.yml for Go linting configuration. - Updated AGENTS.md to clarify project structure and components. - Enhanced CONTRIBUTING.md with Makefile usage for common tasks. - Updated Dockerfiles to use Go 1.24 and improved build instructions. - Refined README.md and deployment documentation for clarity. - Added testing documentation in testing.md for backend and frontend tests. - Introduced Makefile for streamlined development commands and tasks.
3.2 KiB
3.2 KiB
Testing
Running tests
Backend (Go)
make test
Or directly:
go test ./...
Frontend (Vitest)
cd frontend-nuxt
npm test
The frontend uses Vitest with happy-dom as the test environment. Configuration is in frontend-nuxt/vitest.config.ts.
Test structure
Backend
Tests use the standard testing package with table-driven tests. Each test creates a temporary bbolt database via t.TempDir() so tests are fully isolated and require no external dependencies.
| File | What it covers |
|---|---|
internal/app/app_test.go |
Domain types (Coord.Name, Coord.Parent, Auths.Has), Topic pub/sub |
internal/app/migrations_test.go |
Migration on fresh DB, idempotency, version tracking |
internal/app/store/db_test.go |
All store CRUD operations (users, sessions, tokens, config, maps, grids, tiles, markers, OAuth states), context cancellation, edge cases |
internal/app/services/auth_test.go |
Login, session management, token validation, password changes, OAuth bootstrap |
internal/app/services/admin_test.go |
User CRUD, settings, map management, wipe |
internal/app/services/map_test.go |
Map data retrieval, characters, markers, tiles, config, grid storage, SSE watchers |
internal/app/services/client_test.go |
Content-type fix helper |
internal/app/handlers/handlers_test.go |
HTTP integration tests for all API endpoints using httptest (auth, admin, map data, error handling) |
Frontend
Frontend tests are located alongside the source code in __tests__/ directories:
| File | What it covers |
|---|---|
frontend-nuxt/composables/__tests__/useMapApi.test.ts |
Map API composable |
frontend-nuxt/composables/__tests__/useMapLogic.test.ts |
Map logic composable |
frontend-nuxt/composables/__tests__/useAppPaths.test.ts |
Application path helpers |
frontend-nuxt/lib/__tests__/Character.test.ts |
Character lib |
frontend-nuxt/lib/__tests__/Marker.test.ts |
Marker lib |
frontend-nuxt/lib/__tests__/UniqueList.test.ts |
UniqueList utility |
Nuxt auto-imports are mocked via frontend-nuxt/__mocks__/nuxt-imports.ts and the #imports alias in the Vitest config.
Writing new tests
Backend conventions
- Use table-driven tests where multiple input/output pairs make sense.
- Create a temporary database with
t.TempDir()andbbolt.Open()for isolation. - Use
t.Helper()in test helper functions. - Use
t.Cleanup()to close the database after the test.
Example pattern:
func TestMyFeature(t *testing.T) {
dir := t.TempDir()
db, err := bbolt.Open(filepath.Join(dir, "test.db"), 0600, nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { db.Close() })
st := store.New(db)
// ... test logic ...
}
For handler tests, use httptest.NewRecorder() and httptest.NewRequest() to simulate HTTP requests without starting a real server.
Frontend conventions
- Place tests in
__tests__/directories next to the source files. - Name test files
<source-name>.test.ts. - Use Vitest globals (
describe,it,expect).