Skip to content

Commit

Permalink
Try out cram/prysk for CLI integration testing (vercel#1829)
Browse files Browse the repository at this point in the history
Add some `prysk`-based integration tests. They're minimal for now, but we can expand them as we work on CLI UX. 

This PR also fixes an incorrect error that was printed out from `turbo logout`, found via CLI test.

These are not yet wired to CI. I'd like to let them bake for a bit to make sure they are useful before we start gating releases on them. They can be run via `make integration-tests` in the `cli` package.

[Prysk](https://github.com/Nicoretti/prysk)
  • Loading branch information
Greg Soltis authored Sep 8, 2022
1 parent 28310c4 commit bfb6193
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.t]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

Expand Down
3 changes: 2 additions & 1 deletion cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/turbo-new.exe
/turbo.exe

/scripts/turbo-*
/scripts/turbo-*
/.cram_env
13 changes: 13 additions & 0 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,16 @@ clean-build:
clean-demo:
rm -rf node_modules
rm -rf demo

CRAM_ENV := .cram_env

$(CRAM_ENV)/bin/pip:
python3 -m venv $(CRAM_ENV)

$(CRAM_ENV)/bin/prysk: $(CRAM_ENV)/bin/pip
$(CRAM_ENV)/bin/pip install prysk

INTEGRATION_TEST_FILES = $(shell find integration_tests -name "*.t")

integration-tests: $(CRAM_ENV)/bin/prysk turbo $(INTEGRATION_TEST_FILES)
$(CRAM_ENV)/bin/prysk $(INTEGRATION_TEST_FILES)
14 changes: 14 additions & 0 deletions cli/integration_tests/logged_in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

read -r -d '' CONFIG <<- EOF
{
"token": "normal-user-token"
}
EOF

USER_CONFIG_HOME=$(mktemp -d -t turbo-XXXXXXXXXX)
# duplicate over to XDG var so that turbo picks it up
export XDG_CONFIG_HOME=$USER_CONFIG_HOME

mkdir -p $USER_CONFIG_HOME/turborepo
echo $CONFIG > $USER_CONFIG_HOME/turborepo/config.json
12 changes: 12 additions & 0 deletions cli/integration_tests/logout.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Setup
$ . ${TESTDIR}/setup.sh
$ . ${TESTDIR}/logged_in.sh

Logout while logged in
$ ${TURBO} logout
>>> Logged out

Logout while logged out
$ ${TURBO} logout
>>> Logged out

2 changes: 2 additions & 0 deletions cli/integration_tests/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
TURBO=${TESTDIR}/../turbo
31 changes: 31 additions & 0 deletions cli/integration_tests/turbo_help.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Setup
$ . ${TESTDIR}/setup.sh

Test help flag
$ ${TURBO} -h
Usage: turbo [--version] [--help] <command> [<args>]

Available commands are:
bin Get the path to the Turbo binary
daemon Runs turbod
link Link your local directory to a Vercel organization and enable remote caching.
login Login to your Vercel account
logout Logout of your Vercel account
prune Prepare a subset of your monorepo.
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching


$ ${TURBO} --help
Usage: turbo [--version] [--help] <command> [<args>]

Available commands are:
bin Get the path to the Turbo binary
daemon Runs turbod
link Link your local directory to a Vercel organization and enable remote caching.
login Login to your Vercel account
logout Logout of your Vercel account
prune Prepare a subset of your monorepo.
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching

10 changes: 10 additions & 0 deletions cli/integration_tests/turbo_version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Setup
$ . ${TESTDIR}/setup.sh

Test version
$ ${TURBO} --version
(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ (re)

Semver Regex source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
TODO: resolve ambiguity
$ ${TURBO} -v
3 changes: 2 additions & 1 deletion cli/internal/cmd/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"errors"
"fmt"
"os"

"github.com/fatih/color"
"github.com/vercel/turborepo/cli/internal/config"
Expand Down Expand Up @@ -66,7 +67,7 @@ func LogoutCmd(ch *LogoutCommand) *cobra.Command {
Use: "logout",
Short: "Logout of your Vercel account",
RunE: func(cmd *cobra.Command, args []string) error {
if err := ch.Config.UserConfig.Delete(); err != nil {
if err := ch.Config.UserConfig.Delete(); err != nil && !os.IsNotExist(err) {
return ch.logError("could not logout. Something went wrong: %w", err)
}

Expand Down

0 comments on commit bfb6193

Please sign in to comment.