Skip to content

Commit

Permalink
docs: improve readme code formatting and grammar (#85)
Browse files Browse the repository at this point in the history
* docs: improve readme code formatting
* docs: improve grammar
  • Loading branch information
G-Rath committed Dec 19, 2023
1 parent 8565c6c commit 9677416
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ import (
)

func TestExample(t *testing.T) {

snaps.MatchSnapshot(t ,"Hello World")

snaps.MatchSnapshot(t, "Hello World")
}
```

Expand Down Expand Up @@ -96,7 +94,7 @@ successfully on `json.Marshal`.
```go
func TestJSON(t *testing.T) {
type User struct {
Age int
Age int
Email string
}

Expand Down Expand Up @@ -229,10 +227,10 @@ You can update your failing snapshots by setting `UPDATE_SNAPS` env variable to
UPDATE_SNAPS=true go test ./...
```

If you don't want to update all failing snapshots, or you want to update one of
them you can you use the `-run` flag to target the test/s you want.
If you don't want to update all failing snapshots, or you want to update only one of
them you can you use the `-run` flag to target the test(s) you want.

For more information for `go test` flags you can run
For more information on `go test` flags you can run

```go
go help testflag
Expand All @@ -247,15 +245,15 @@ go help testflag

`go-snaps` can identify obsolete snapshots.

In order to enable this functionality you need to use the `TestMain(t*testing.M)`
and call `snaps.Clean(t)`. This will also print a **Snapshot Summary**. (if running tests
In order to enable this functionality you need to use `TestMain(t*testing.M)` to
call `snaps.Clean(t)` after your tests have run. This will also print a **Snapshot Summary**. (if running tests
with verbose flag `-v`)

If you want to remove the obsolete snap files and snapshots you can run
tests with `UPDATE_SNAPS=clean` env variable.

The reason for using `TestMain`, is because `go-snaps` needs to be sure that all tests
are finished so it can keep track which snapshots were not called.
The reason for using `TestMain` is because `go-snaps` needs to be sure that all tests
are finished so it can keep track of which snapshots were not called.

**Example:**

Expand All @@ -274,7 +272,7 @@ For more information around [TestMain](https://pkg.go.dev/testing#hdr-Main).

### Sort Snapshots

By default `go-snaps` is appending new snaps to the file and in case of parallel tests the order is random. If you want snaps to be sorted in deterministic order you need to use `TestMain` per package
By default `go-snaps` appends new snaps to the snapshot file and in case of parallel tests the order is random. If you want snaps to be sorted in deterministic order you need to use `TestMain` per package:

```go
func TestMain(t *testing.M) {
Expand All @@ -299,7 +297,7 @@ for obsolete snapshots.

## Running Tests on CI

When `go-snaps` detects that it runs on CI it will automatically fail when snapshots are missing. This is done to ensure new snapshots are committed alongside the tests and assertions are successful.
When `go-snaps` detects that it is running in CI it will automatically fail when snapshots are missing. This is done to ensure new snapshots are committed alongside the tests and assertions are successful.

> `go-snaps` uses [ciinfo](https://github.com/gkampitakis/ciinfo) for detecting if it runs on CI environment.
Expand All @@ -324,8 +322,7 @@ Snapshots have the form
---
```

`TestID` is the test name plus an increasing number ( allowing to do multiple calls
of `MatchSnapshot` inside a test ).
`TestID` is the test name plus an increasing number to allow multiple calls of `MatchSnapshot` in a single test.

```txt
[TestSimple/should_make_a_map_snapshot - 1]
Expand Down

0 comments on commit 9677416

Please sign in to comment.