From 875f35aaca1e181d24cb4a1c730690aac71c5792 Mon Sep 17 00:00:00 2001 From: Georgios Kampitakis <50364739+gkampitakis@users.noreply.github.com> Date: Thu, 2 Nov 2023 20:36:00 +0000 Subject: [PATCH] chore: add example for using update option (#81) and minor docs clean up --- .github/workflows/go.yml | 14 +++++++---- README.md | 13 ++-------- examples/__snapshots__/examples_test.snap | 16 ++++++++++++ examples/examples_test.go | 30 +++++++++++++++++++++++ 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100755 examples/__snapshots__/examples_test.snap create mode 100644 examples/examples_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e3afe18..3a29459 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 @@ -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: | @@ -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 diff --git a/README.md b/README.md index 0588a2d..a7a81c5 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,7 @@ Logo

-
- -

-App Preview Diff -App Preview New -

- -> 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) @@ -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) { diff --git a/examples/__snapshots__/examples_test.snap b/examples/__snapshots__/examples_test.snap new file mode 100755 index 0000000..65490ec --- /dev/null +++ b/examples/__snapshots__/examples_test.snap @@ -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. +--- diff --git a/examples/examples_test.go b/examples/examples_test.go new file mode 100644 index 0000000..622bafe --- /dev/null +++ b/examples/examples_test.go @@ -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) + }) + } +}