|
| 1 | +#!/usr/bin/env bats |
| 2 | +# Integration tests for scripts/update.sh: drive the whole "Update dependencies" |
| 3 | +# step against a fixture directory with `pnpm` stubbed, and assert on the |
| 4 | +# commands it invokes (recorded in $PNPM_LOG). |
| 5 | + |
| 6 | +SCRIPT="${BATS_TEST_DIRNAME}/../scripts/update.sh" |
| 7 | + |
| 8 | +setup() { |
| 9 | + TMP="$(mktemp -d)" |
| 10 | + # Put the pnpm stub first on PATH. |
| 11 | + mkdir -p "$TMP/bin" |
| 12 | + cp "${BATS_TEST_DIRNAME}/stubs/pnpm" "$TMP/bin/pnpm" |
| 13 | + chmod +x "$TMP/bin/pnpm" |
| 14 | + PATH="$TMP/bin:$PATH" |
| 15 | + export PNPM_LOG="$TMP/pnpm.log" |
| 16 | + : > "$PNPM_LOG" |
| 17 | + cd "$TMP" |
| 18 | + |
| 19 | + # Defaults matching the action's inputs; individual tests override via `export`. |
| 20 | + export UPDATE_DEPS=latest |
| 21 | + export REFRESH_LOCKFILE=false |
| 22 | + export EXCLUDE='' |
| 23 | + export INCLUDE_GITHUB_ACTIONS=false |
| 24 | + export CHANGESETS=true |
| 25 | + export UPDATE_PNPM=false |
| 26 | + export NODE='' |
| 27 | + printf '%s' '{"name":"fixture","devEngines":{"runtime":{"name":"node","version":"^24.4.0"}}}' > package.json |
| 28 | +} |
| 29 | + |
| 30 | +teardown() { |
| 31 | + rm -rf "$TMP" |
| 32 | +} |
| 33 | + |
| 34 | +@test "latest update: pins the runtime major, updates recursively with changeset" { |
| 35 | + run bash "$SCRIPT" |
| 36 | + [ "$status" -eq 0 ] |
| 37 | + grep -Fqx 'runtime set node 24' "$PNPM_LOG" |
| 38 | + grep -Fqx 'update --recursive --latest --changeset' "$PNPM_LOG" |
| 39 | +} |
| 40 | + |
| 41 | +@test "invalid update-deps fails" { |
| 42 | + export UPDATE_DEPS=bogus |
| 43 | + run bash "$SCRIPT" |
| 44 | + [ "$status" -ne 0 ] |
| 45 | + [[ "$output" == *"::error::"* ]] |
| 46 | +} |
| 47 | + |
| 48 | +@test "update-deps=false runs a plain install, not update" { |
| 49 | + export UPDATE_DEPS=false |
| 50 | + run bash "$SCRIPT" |
| 51 | + [ "$status" -eq 0 ] |
| 52 | + grep -Fqx 'install' "$PNPM_LOG" |
| 53 | + ! grep -Fq -- '--recursive' "$PNPM_LOG" |
| 54 | +} |
| 55 | + |
| 56 | +@test "update-deps=false with github-actions warns that it is skipped" { |
| 57 | + export UPDATE_DEPS=false INCLUDE_GITHUB_ACTIONS=true |
| 58 | + run bash "$SCRIPT" |
| 59 | + [[ "$output" == *"::notice::"* ]] |
| 60 | + [[ "$output" == *"github-actions updates are skipped"* ]] |
| 61 | +} |
| 62 | + |
| 63 | +@test "changesets=false passes --no-changeset" { |
| 64 | + export CHANGESETS=false |
| 65 | + run bash "$SCRIPT" |
| 66 | + grep -Fq -- '--no-changeset' "$PNPM_LOG" |
| 67 | +} |
| 68 | + |
| 69 | +@test "unsupported pnpm skips the changeset flag with a notice" { |
| 70 | + export STUB_SUPPORTS_CHANGESET=0 |
| 71 | + run bash "$SCRIPT" |
| 72 | + [ "$status" -eq 0 ] |
| 73 | + ! grep -Fq -- '--changeset' "$PNPM_LOG" |
| 74 | + ! grep -Fq -- '--no-changeset' "$PNPM_LOG" |
| 75 | + [[ "$output" == *"has no --changeset flag"* ]] |
| 76 | +} |
| 77 | + |
| 78 | +@test "github-actions=true adds --include-github-actions" { |
| 79 | + export INCLUDE_GITHUB_ACTIONS=true |
| 80 | + run bash "$SCRIPT" |
| 81 | + grep -Fq -- '--include-github-actions' "$PNPM_LOG" |
| 82 | +} |
| 83 | + |
| 84 | +@test "exclude patterns become negation selectors" { |
| 85 | + export EXCLUDE='webpack @types/*' |
| 86 | + run bash "$SCRIPT" |
| 87 | + grep -Fqx 'update --recursive --latest --changeset !webpack !@types/*' "$PNPM_LOG" |
| 88 | +} |
| 89 | + |
| 90 | +@test "explicit node version is used verbatim" { |
| 91 | + export NODE=22 |
| 92 | + run bash "$SCRIPT" |
| 93 | + grep -Fqx 'runtime set node 22' "$PNPM_LOG" |
| 94 | +} |
| 95 | + |
| 96 | +@test "node=false skips the runtime update" { |
| 97 | + export NODE=false |
| 98 | + run bash "$SCRIPT" |
| 99 | + ! grep -Fq 'runtime set node' "$PNPM_LOG" |
| 100 | +} |
| 101 | + |
| 102 | +@test "no pinned runtime skips the runtime update with a message" { |
| 103 | + printf '%s' '{"name":"fixture"}' > package.json |
| 104 | + run bash "$SCRIPT" |
| 105 | + [ "$status" -eq 0 ] |
| 106 | + ! grep -Fq 'runtime set node' "$PNPM_LOG" |
| 107 | + [[ "$output" == *"No Node.js version pinned"* ]] |
| 108 | +} |
| 109 | + |
| 110 | +@test "refresh-lockfile removes the lockfile and node_modules" { |
| 111 | + export REFRESH_LOCKFILE=true |
| 112 | + touch pnpm-lock.yaml |
| 113 | + mkdir -p node_modules/.pnpm |
| 114 | + run bash "$SCRIPT" |
| 115 | + [ "$status" -eq 0 ] |
| 116 | + [ ! -e pnpm-lock.yaml ] |
| 117 | + [ ! -e node_modules ] |
| 118 | +} |
| 119 | + |
| 120 | +@test "update-pnpm default stays on the pinned major from pnpm --version" { |
| 121 | + export STUB_PNPM_VERSION=11.5.0 |
| 122 | + export UPDATE_PNPM='' |
| 123 | + run bash "$SCRIPT" |
| 124 | + grep -Fqx 'self-update 11' "$PNPM_LOG" |
| 125 | +} |
| 126 | + |
| 127 | +@test "update-pnpm explicit dist-tag is passed through" { |
| 128 | + export UPDATE_PNPM=next-12 |
| 129 | + run bash "$SCRIPT" |
| 130 | + grep -Fqx 'self-update next-12' "$PNPM_LOG" |
| 131 | +} |
| 132 | + |
| 133 | +@test "update-pnpm=false skips self-update" { |
| 134 | + export UPDATE_PNPM=false |
| 135 | + run bash "$SCRIPT" |
| 136 | + ! grep -Fq 'self-update' "$PNPM_LOG" |
| 137 | +} |
0 commit comments