Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gkampitakis/go-snaps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.4
Choose a base ref
...
head repository: gkampitakis/go-snaps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.5
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 5, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c578aa7 View commit details

Commits on Jul 19, 2024

  1. fix: resolve relative path of snapshot correct (#105)

    gkampitakis authored Jul 19, 2024
    Copy the full SHA
    91ca918 View commit details
Showing with 12 additions and 9 deletions.
  1. +3 −0 README.md
  2. +2 −2 snaps/matchSnapshot_test.go
  3. +4 −4 snaps/snapshot.go
  4. +3 −3 snaps/snapshot_test.go
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -353,3 +353,6 @@ This library used [Jest Snapshoting](https://jestjs.io/docs/snapshot-testing) an
> [!IMPORTANT]
> Snapshots should be treated as code. The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process
> [!NOTE]
> go-snaps doesn't handle CRLF line endings. If you are using Windows, you may need to convert the line endings to LF.
4 changes: 2 additions & 2 deletions snaps/matchSnapshot_test.go
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ func TestMatchSnapshot(t *testing.T) {
"+ Received + 2\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" +
"- hello world\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ bye world\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash(
"../__snapshots__/matchSnapshot_test.snap:2",
"__snapshots__/matchSnapshot_test.snap:2",
) +
"\n\x1b[0m"

@@ -227,7 +227,7 @@ func TestMatchSnapshot(t *testing.T) {
"- hello world----\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m- ---\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ bye world----\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ --\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash(
"../__snapshots__/matchSnapshot_test.snap:2",
"__snapshots__/matchSnapshot_test.snap:2",
) +
"\n\x1b[0m"

8 changes: 4 additions & 4 deletions snaps/snapshot.go
Original file line number Diff line number Diff line change
@@ -255,20 +255,20 @@ Returns the relative path of the caller and the snapshot path.
*/
func snapshotPath(c *config) (string, string) {
// skips current func, the wrapper match* and the exported Match* func
callerPath := baseCaller(3)
callerFilename := baseCaller(3)

dir := c.snapsDir
if !filepath.IsAbs(dir) {
dir = filepath.Join(filepath.Dir(callerPath), c.snapsDir)
dir = filepath.Join(filepath.Dir(callerFilename), c.snapsDir)
}

filename := c.filename
if filename == "" {
base := filepath.Base(callerPath)
base := filepath.Base(callerFilename)
filename = strings.TrimSuffix(base, filepath.Ext(base))
}
snapPath := filepath.Join(dir, filename+snapsExt)
snapPathRel, _ := filepath.Rel(callerPath, snapPath)
snapPathRel, _ := filepath.Rel(filepath.Dir(callerFilename), snapPath)

return snapPath, snapPathRel
}
6 changes: 3 additions & 3 deletions snaps/snapshot_test.go
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ func TestSnapPathAndFile(t *testing.T) {
}()

test.Contains(t, snapPath, filepath.FromSlash("/snaps/__snapshots__"))
test.Contains(t, snapPathRel, filepath.FromSlash("../__snapshots__/snapshot_test.snap"))
test.Contains(t, snapPathRel, filepath.FromSlash("__snapshots__/snapshot_test.snap"))
})

t.Run("should return path and file from config", func(t *testing.T) {
@@ -177,7 +177,7 @@ func TestSnapPathAndFile(t *testing.T) {

// returns the current file's path /snaps/*
test.Contains(t, snapPath, filepath.FromSlash("/snaps/my_snapshot_dir"))
test.Contains(t, snapPathRel, filepath.FromSlash("../my_snapshot_dir/my_file.snap"))
test.Contains(t, snapPathRel, filepath.FromSlash("my_snapshot_dir/my_file.snap"))
})

t.Run("should return absolute path", func(t *testing.T) {
@@ -198,7 +198,7 @@ func TestSnapPathAndFile(t *testing.T) {
}()

test.Contains(t, snapPath, filepath.FromSlash("/path_to/my_snapshot_dir"))
test.Contains(t, snapPathRel, filepath.FromSlash("/path_to/my_snapshot_dir/my_file.snap"))
test.Contains(t, snapPathRel, filepath.FromSlash("path_to/my_snapshot_dir/my_file.snap"))
})
}