Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VHS available as a library to be used in test suites and make possible programmatically detect golden file changes #462

Open
rija opened this issue Mar 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rija
Copy link

rija commented Mar 29, 2024

Is your feature request related to a problem? Please describe.

Hello, I intend to write regular go tests on CLI projects and we use GitLab for CI/CD (so VHS Github action won't help).

Describe the solution you'd like

I imagine something like below (I'm beginner at go so I apologise if it's not idiomatic, I'm quite open about how it could be done)

import (
	"github.com/charmbracelet/vhs"
	"testing"
)
...

func TestIntegrate(t *testing.T) {
	diff, err := vhs.PlayAndCompare("app.tape", "expected_behaviours.txt")
	if err != nil {
		t.Error(err.Error())
	}
	if diff != nil {
		t.Error(diff)
	}
}

Where app.tape will start with

Output a_special_name_the_library_can_find_automatically.txt
Hide
Type "go build -o hello . && clear"
Enter
Show
Type ./hello
Sleep 1s
...

Or instead of Output a tape directive that output the golden file only could be used (e.g: OutputGolden) or the library does it automatically internally

Describe alternatives you've considered

My current workaround is to execute the VHS cli (with a tape that generate a golden file) from the go test code and ReadFile the golden file before and after the call to VHS, then test whether the two files' content are the same.
It feels clumsy (messes up the git status) and comparing the two versions of golden files make the code verbose if to be done efficiently

Additional context
Add any other context or screenshots about the feature request here.

@rija rija added the enhancement New feature or request label Mar 29, 2024
@maaslalani
Copy link
Member

Hey! You might want to check out https://github.com/charmbracelet/vhs-action if you're using GitHub btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants