The project uses Task for common development workflows. Here are the available test-related commands:
Starts the Vuego playground web server on http://localhost:8080
Runs the comprehensive test suite with coverage:
- Executes tests with race detection (
-race) - Fails fast on first error (
-failfast) - Collects coverage data across all packages
- Outputs coverage profile to
pkg.cov
Usage:
task testGenerates detailed coverage reports and documentation:
- Extracts source documentation with
go-fsck - Generates API documentation in
docs/api.md - Creates JSON coverage summary in
pkg.cov.json - Produces coverage report in
docs/testing-coverage.md
Usage:
task coverShows uncovered source lines from the last test run:
task uncoverRenders a sample template for manual testing:
task renderTests in this project use black box testing (package vuego_test) to test only the exported API. This allows running individual test files independently:
# Run a specific test file
go test -v stack_test.go
# Run a specific test function
go test -v -run TestStack_Push
# Run all tests in a file with race detection
go test -v -race stack_test.go# Run all tests
go test ./...
# Run all tests with coverage
go test -cover ./...
# Run with race detection and verbose output
go test -v -race ./...Test fixtures are organized in the testdata/ directory:
Contains paired test files for template rendering validation:
.vuego- Template files with directives (v-if, v-for, v-bind, etc.).json- Input data for the template.html- Expected output after rendering
Each test case consists of three files with the same base name:
testdata/fixtures/
├── v-for.vuego # Template with v-for directive
├── v-for.json # Test data (array/object to iterate)
└── v-for.html # Expected rendered HTML
The test framework automatically discovers all .vuego files in fixtures and validates:
- Template renders without errors
- Output HTML matches the expected
.htmlfile - DOM structure is equivalent (whitespace-normalized, attribute order-insensitive)
Contains full page templates and components for integration testing:
- Complete page layouts
- Reusable components in
components/subdirectory - Component composition and nesting tests
- Error case validation (e.g.,
required-error-test/)
Contains complex JSON data files for realistic rendering scenarios.
Follow the pattern Test[Receiver_]Function:
- Methods:
TestVue_Render,TestStack_Push - Functions:
TestNewVue,TestParseFor - Descriptive tests:
TestRequiredAttributeError,TestFixtures
All assertions use github.com/stretchr/testify/require:
func TestVue_Render(t *testing.T) {
vue := vuego.NewVue(os.DirFS("testdata/pages"))
var buf bytes.Buffer
err := vue.Render(&buf, "Index.vuego", nil)
require.NoError(t, err)
require.Contains(t, buf.String(), "expected content")
}To add a new fixture test:
- Create a
.vuegotemplate file intestdata/fixtures/ - Create a
.jsondata file with the same base name - Create a
.htmlfile with the expected output
The TestFixtures function will automatically discover and run your test.
Example:
# Create test files
echo '<div v-if="show">Hello</div>' > testdata/fixtures/my-test.vuego
echo '{"show": true}' > testdata/fixtures/my-test.json
echo '<div>Hello</div>' > testdata/fixtures/my-test.html
# Run the test
go test -v -run TestFixtures