Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PPDSC-2313): script to run applitools locally #321

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Scripts should be named using the following naming convention:

* `eyes:storybook` -> runs the applitools storybook tests locally. Requires APPLITOOLS_API_KEY to be exported prior to running.

* `test:visual:comps:local` -> sets required env variables and runs the applitools component tests locally.

* `e2e:visual:docs:local` -> sets required env variables and runs the applitools doc site tests locally.

## Storybook

* `dev:storybook` -> locally starts storybook at port 6006.
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"test:unit:comps": "yarn test:unit:run:local --projects=src",
"test:unit:site": "yarn test:unit:run:local --projects=site",
"test:visual:comps:ci": "start-server-and-test dev:storybook 6006 eyes:storybook",
"test:visual:comps:local": "sh ./scripts/applitools_local.sh comps",
"prepublish": "yarn build:sync-version-number",
"build:clean": "rm -rf dist && rm -rf dist-storybook && rm -rf public",
"build:ts:cjs": "NODE_ENV=production tsc --outDir dist/cjs",
Expand All @@ -55,6 +56,7 @@
"e2e:comps:ci": "start-server-and-test e2e:serve 8080 'TZ=UTC cypress run --config-file cypress/config/cypress.components.json'",
"e2e:docs:ci": "start-server-and-test serve:docs 8081 'TZ=UTC cypress run --config-file cypress/config/cypress.docs.json'",
"e2e:visual:docs:ci": "start-server-and-test serve:docs 8081 'TZ=UTC APPLITOOLS_SHOW_LOGS=true cypress run --config-file cypress/config/cypress.docs.visual.json'",
"e2e:visual:docs:local": "sh ./scripts/applitools_local.sh docs",
"e2e:generate:a11ytests": "node scripts/generate-a11y-tests.js",
"e2e:findbrokenlinks": "linkinator http://localhost:8081 --recurse --skip '^(?!http://localhost:8081)'",
"e2e:findbrokenlinks:ci": "start-server-and-test serve:docs 8081 e2e:findbrokenlinks",
Expand Down
56 changes: 56 additions & 0 deletions scripts/applitools_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# this script sets the environment variables required to run Applitools tests locally

USERNAME=$(git config user.name)
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
COMMIT_SHA=$(git rev-parse HEAD)
STATUS=$(git status)

# the commit needs to be pushed (so that the Applitools / GitHub integration can retrieve its info)
if [[ "$STATUS" != *"Your branch is up to date with 'origin/${BRANCH_NAME}'."* ]]; then
echo "Please make sure you are up-to-date with remote before running Applitools tests."
exit 1
fi

# guide the user to only running a subset of tests to keep usage down
if [[ $1 = "comps" ]]; then
Vanals marked this conversation as resolved.
Show resolved Hide resolved
CONFIG_FILE="applitools.components.config.js"
DOCS_LINK="https://www.npmjs.com/package/@applitools/eyes-storybook"
else
CONFIG_FILE="applitools.config.js"
DOCS_LINK="https://www.npmjs.com/package/@applitools/eyes-cypress"
fi

echo "If you have not added an include prop in ${CONFIG_FILE}, all ${1} tests will run."$'\n'
echo "See ${DOCS_LINK}"$'\n'
read -r -p "Proceed? (y/n) " response
if [[ $response =~ ^(yes|y) ]] || [[ -z $response ]]; then
:
else
echo Aborting
exit 1
fi

# ask the user to input their API key
read -p "Enter your API key (you can find this in the Applitools UI): " apiKey

# the batch id must be set to the commit sha for the integration to work
export APPLITOOLS_BATCH_ID=$(git rev-parse HEAD);
# batch name can be anything (make it easy to identify)
export APPLITOOLS_BATCH_NAME="LOCAL RUN by ${USERNAME} for commit ${COMMIT_SHA} on ${BRANCH_NAME}";
# set to the user's API key
export APPLITOOLS_API_KEY=$apiKey
# make sure the batch closes after running
export APPLITOOLS_DONT_CLOSE_BATCHES=false

# once the tests start, warn the user that force quitting may lead to an unclosed batch
trap 'echo "Force quitting means that a batch may have been created but not closed. If so, tests in the next run for this commit will be added to the same batch. To prevent this you can close the batch using CURL or delete it in the Applitools UI."' INT

if [[ "$1" == "comps" ]]; then
echo "Running component tests..."
yarn test:visual:comps:ci
else
echo "Running doc site tests..."
yarn e2e:visual:docs:ci
fi