Skip to content

Commit

Permalink
chore: add example for using update option (#81)
Browse files Browse the repository at this point in the history
and minor docs clean up
  • Loading branch information
gkampitakis authored Nov 2, 2023
1 parent ade9455 commit 875f35a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Go
on:
pull_request:
paths-ignore:
- 'images/**'
- '**/*.md'
- "images/**"
- "**/*.md"
branches:
- main
push:
paths-ignore:
- 'images/**'
- '**/*.md'
- "images/**"
- "**/*.md"
branches:
- main

Expand All @@ -26,7 +26,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: 'latest'
version: "latest"
args: -c ./golangci.yml
- name: Format lint
run: |
Expand All @@ -38,6 +38,10 @@ jobs:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@
<img src="./images/logo.svg" alt="Logo" width="400"/>
</p>

<br>

<p align="center">
<img src="./images/diff.png" alt="App Preview Diff"/>
<img src="./images/new_snapshot.png" alt="App Preview New" width="500"/>
</p>

> matchJSON and matchers are still under development that means their API can change. Use with caution and please share feedback for improvements.
## Highlights
## Contents

- [Installation](#installation)
- [MatchSnapshot](#matchsnapshot)
Expand Down Expand Up @@ -211,7 +202,7 @@ You can see more [examples](./examples/matchJSON_test.go#L96).

- the directory where snapshots are stored, _relative or absolute path_
- the filename where snapshots are stored
- programmatically control whether to update snapshots
- programmatically control whether to update snapshots. _You can find an example usage at [examples](./examples/examples_test.go:14)_

```go
t.Run("snapshot tests", func(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions examples/__snapshots__/examples_test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

[TestUpdateWithFlag/test_-_0 - 1]
lore ipsum dolor sit amet
---

[TestUpdateWithFlag/test_-_1 - 1]
consectetur adipiscing elit
---

[TestUpdateWithFlag/test_-_2 - 1]
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
---

[TestUpdateWithFlag/test_-_3 - 1]
Ut enim ad minim veniam, quis nostrud laboris nisi ut aliquip ex ea commodo consequat.
---
30 changes: 30 additions & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package examples

import (
"flag"
"fmt"
"testing"

"github.com/gkampitakis/go-snaps/snaps"
)

// You can use -update flag to control if you want to update the snapshots
// go test ./... -v -update
var updateSnapshot = flag.Bool("update", false, "update snapshots flag")

func TestUpdateWithFlag(t *testing.T) {
snaps := snaps.WithConfig(snaps.Update(*updateSnapshot))

inputs := []string{
"lore ipsum dolor sit amet",
"consectetur adipiscing elit",
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
"Ut enim ad minim veniam, quis nostrud laboris nisi ut aliquip ex ea commodo consequat.",
}

for i, input := range inputs {
t.Run(fmt.Sprintf("test - %d", i), func(t *testing.T) {
snaps.MatchSnapshot(t, input)
})
}
}

0 comments on commit 875f35a

Please sign in to comment.