Skip to content

Commit 6dfd218

Browse files
authored
feat(cli): accept -u as the short form of --snapshot-update (#1294)
1 parent 133323c commit 6dfd218

7 files changed

Lines changed: 23 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Performance: a `--parallel` run writing a report is about 1.9x faster and costs 1.8x less CPU. Every result row base64-encoded all nine of its fields separately and decoded them the same way — fourteen `base64` forks per test — so `--log-junit`, the usual CI setup, cost several times more than running the tests. Only the four fields that can hold arbitrary text are encoded now (#1289)
99
### Fixed
1010
- `bashunit watch` no longer takes an option's value as the path it polls. Only `-f/--filter` was known to consume a value, so `bashunit watch --tag slow tests/` polled a directory named `slow` and passed the real path to `--tag`; when the value happened to name a real directory it polled the wrong one without saying so. Options may now appear in any position (#1291)
11+
### Added
12+
- `-u` as the short form of `--snapshot-update`. Re-running with `-u` after a deliberate output change is the reflex jest and vitest already teach, and both spell it the same way (#1293)
1113

1214
### Removed
1315
- `bashunit learn`, the interactive tutorial. Nobody used it, and it was broken for most of the nine months it shipped without anyone reporting it. Learning bashunit belongs in the docs at https://bashunit.com, not in a subsystem inside the runner — which is also 6% of the distributable. Calling it now says it was removed and points there (#1256, #1258)

completions/_bashunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ _bashunit() {
104104
'(--list --dry-run)'{--list,--dry-run}'[Print the tests that would run, then exit]' \
105105
'--list-format[Rendering for --list]:format:(text json)' \
106106
'--list-tags[Print the tags of the selected files, one per line, then exit]' \
107-
'--snapshot-update[Rewrite existing snapshots from the actual value]' \
107+
'(-u --snapshot-update)'{-u,--snapshot-update}'[Rewrite existing snapshots from the actual value]' \
108108
'--no-snapshot-create[Fail instead of recording a missing snapshot]' \
109109
'--snapshot-prune[Delete snapshot files no test resolved]' \
110110
'--snapshot-report-unused[List snapshot files no test resolved]' \

completions/bashunit.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _BASHUNIT_COMPLETIONS_TEST_OPTS="--assert --boot --changed --coverage --coverage
2525
--report-json --report-junit --report-md --report-tap --rerun-failed --retry --run-all \
2626
--sandbox --sandbox-allow \
2727
--seed --shard --show-incomplete --show-output --show-skipped --simple \
28-
--skip-env-file --snapshot-prune --snapshot-report-unused --snapshot-update \
28+
--skip-env-file --snapshot-prune --snapshot-report-unused --snapshot-update -u \
2929
--pass-with-no-tests --stop-on-failure --strict --suite --tag \
3030
--test-timeout --verbose \
3131
--watch -R -S -a -e -f -h -j -l -p -r -s -vvv -w"

docs/command-line.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Cypress spell `--pass-with-no-tests`.
138138
| `--list`, `--dry-run` | Print the tests that would run, then exit |
139139
| `--list-format <fmt>` | Rendering for `--list`: `text` (default) or `json` |
140140
| `--list-tags` | Print the tags of the selected files, one per line, then exit |
141-
| `--snapshot-update` | Rewrite existing snapshots from the actual value |
141+
| `-u, --snapshot-update` | Rewrite existing snapshots from the actual value |
142142
| `--no-snapshot-create` | Fail on a missing snapshot instead of recording it |
143143
| `--snapshot-report-unused` | List snapshot files no test resolved (deletes nothing) |
144144
| `--snapshot-prune` | Delete the snapshot files no test resolved (full runs only) |
@@ -879,7 +879,7 @@ steps:
879879
880880
### Snapshot update
881881
882-
> `bashunit test --snapshot-update`
882+
> `bashunit test -u|--snapshot-update`
883883

884884
Re-record snapshots: every snapshot assertion whose file already exists is
885885
overwritten with the value this run produced, and reported as a recorded
@@ -894,9 +894,12 @@ never fails.
894894
Scope it with `--filter` to re-record a single test:
895895

896896
```bash
897-
./bashunit --snapshot-update --filter "renders the header" tests/
897+
./bashunit -u --filter "renders the header" tests/
898898
```
899899

900+
`-u` is the same short form jest and vitest use for their own update flag, so
901+
the reflex carries over.
902+
900903
Notes:
901904

902905
- A snapshot containing the placeholder (`::ignore::`, or

src/console/header.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Options:
155155
--list, --dry-run Print the tests that would run, then exit without running them
156156
--list-format <fmt> Rendering for --list: text (default) or json
157157
--list-tags Print the tags of the selected files, one per line, then exit
158-
--snapshot-update Rewrite existing snapshots from the actual value (combine with --filter)
158+
-u, --snapshot-update Rewrite existing snapshots from the actual value (combine with --filter)
159159
--no-snapshot-create Fail on a missing snapshot instead of recording it (for CI)
160160
--snapshot-report-unused List snapshot files no test resolved (full runs only, deletes nothing)
161161
--snapshot-prune Delete the snapshot files no test resolved (full runs only)

src/main/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function bashunit::main::cmd_test() {
317317
export -n BASHUNIT_LIST_TAGS
318318
export -n BASHUNIT_LIST_TESTS
319319
;;
320-
--snapshot-update)
320+
-u | --snapshot-update)
321321
BASHUNIT_SNAPSHOT_UPDATE=true
322322
export -n BASHUNIT_SNAPSHOT_UPDATE
323323
;;

tests/acceptance/bashunit_snapshot_update_test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ function test_snapshot_update_still_records_a_missing_snapshot() {
8282

8383
assert_same "alpha value" "$(cat "$SNAPSHOT_ALPHA")"
8484
}
85+
86+
# `-u` is what jest (`-u, --updateSnapshot`) and vitest (`-u, --update`) call
87+
# it, and re-running with it is reflex for anyone arriving from either. The
88+
# long form stays; this is the spelling that does not have to be looked up.
89+
function test_u_is_the_short_form_of_snapshot_update() {
90+
(cd "$WORKDIR" && "$BASHUNIT_BIN" --no-parallel --skip-env-file \
91+
-u snap.sh) >/dev/null 2>&1 || true
92+
93+
assert_same "alpha value" "$(cat "$SNAPSHOT_ALPHA")"
94+
assert_same "beta value" "$(cat "$SNAPSHOT_BETA")"
95+
}

0 commit comments

Comments
 (0)