-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run storybook tests with playwright (#249)
* resolve conflicts * test cleanup * add post deployment action for testing * update lockfile to fix failing action * update action name * correct config dir path * add workflow dispatch for testing * add push action for wip branch * fix failing test for radio group pattern edit * update documentation and add script for storybook testing with playwright * update lockfile * update path in action * set endpoint in action * update workflow endpoint and run mode * install playwright in gh action * create a self-contained image that runs through the tests on docker build * use docker in post-deploy action * clean up logging for docker build * simplify end to end tests * debugging tests * rename test * install unfiltered deps in docker--no-verify * change end-to-end back to imported convention * test deliberate failure in pipeline * remove deliberately failing test * update adr for test strategy * add drag and drop test * dry up test code * add mouse interaction test for drag-and-drop * fix flaky test * remove flaky test * remove commented code * ignore pnpm cache dir * use netcat instead of sleep to start server. pare down the copied files in the base image. * use netcat instead of sleep to start server. pare down the copied files in the base image. * add script to provide config for docker functions * update documentation and add provisions for running stories locally * grammar correction
- Loading branch information
1 parent
8c8994d
commit 5ab94b0
Showing
15 changed files
with
14,803 additions
and
11,442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: End-to-end tests | ||
on: | ||
workflow_call: | ||
jobs: | ||
end-to-end: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Docker to run tests | ||
run: | | ||
docker build --platform linux/amd64 --tag 'playwright' . -f ./e2e/Dockerfile --target test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_Store | ||
.env | ||
.pnpm-store/ | ||
*.code-workspace | ||
_site | ||
.turbo/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/sh | ||
pnpm lint | ||
pnpm format | ||
pnpm test | ||
pnpm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
# End-to-end testing | ||
E2E testing runs in a docker container. | ||
# End-to-end and interaction testing | ||
E2E testing runs in a docker container. There is a shell script (`./scripts/end-to-end.sh`) that provides configuration to automate several Docker-related commands. | ||
|
||
```bash | ||
# run from project root | ||
docker build --tag 'playwright' . -f ./e2e/Dockerfile | ||
``` | ||
Parameters: | ||
-p : Configure the port on which Storybook will be served. Defaults to 9009 if no value is specified. | ||
-c : Configure the name of the Docker container. Defaults to e2e if no value is specified. | ||
-f : Specify the function(s) you'd like to run. You can add multiple -f parameters followed by function name, like `-f build_container -f run_container` | ||
-t : This parameter lets you specify the Docker build target. This should be either `serve` or `test`. | ||
|
||
Functions: | ||
`build_container` : Builds a Docker container, where the build target is specified using a -t flag (the default target is `test`). | ||
`run_container` : Runs the built Docker container. | ||
`end_to_end` : Performs playwright test command inside the Docker container for end-to-end testing. Requires the container to be running. | ||
`interaction` : Performs the interaction tests inside the Docker container against the storybook instance. Requires the container to be running. | ||
|
||
If Docker is not installed on your machine, running the script will prompt you to install Docker. If no function(s) are defined using -f flag, it runs `end_to_end` and `interaction` function by default. | ||
|
||
## Build targets | ||
The `test` target is self-contained and meant to run mostly in the build pipeline. The `serve` target is most useful during local development. When the `serve` container is run, it will mount a volume from your local machine and start a dev server, so you get persistent storage without having to rebuild the image. | ||
|
||
## Getting Started | ||
|
||
First, make sure the script is executable: | ||
|
||
To see the output of the tests and run everything when the docker container is built, run the command below: | ||
```bash | ||
# run from project root | ||
docker build --tag 'playwright' . -f ./e2e/Dockerfile --progress=plain --target test | ||
# from the project root | ||
chmod +x ./e2e/scripts/end-to-end.sh | ||
``` | ||
You can add the `--no-cache` flag to build from scratch. | ||
|
||
To run the container (best for development): | ||
Examples: | ||
|
||
```bash | ||
# run from project root | ||
docker run -p 4321:4321 -it --name e2e --rm playwright | ||
# builds the test container (also will run the tests) | ||
./e2e/scripts/end-to-end.sh -f build_container -t test | ||
``` | ||
|
||
```bash | ||
# run from project root | ||
docker exec -it e2e pnpm playwright test | ||
# builds the serve container and start it | ||
./e2e/scripts/end-to-end.sh -f build_container -t serve -f run_container | ||
``` | ||
|
||
### Debugging | ||
To debug and follow the flow of a test in a browser, you can run: | ||
|
||
```bash | ||
# run from this directory | ||
export E2E_ENDPOINT=http://localhost:4321; pnpm playwright test --ui-port=8080 --ui-host=0.0.0.0 | ||
``` | ||
# Runs the default tasks `end_to_end` and `interaction` | ||
./e2e/scripts/end-to-end.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
# default values | ||
STORYBOOK_PORT=9009 | ||
CONTAINER_NAME="e2e" | ||
BUILD_TARGET="test" | ||
BASE_PATH=$(dirname $0) | ||
FUNCS="" | ||
|
||
# Parse flag parameters | ||
while getopts "p:c:f:t:" flag | ||
do | ||
case "${flag}" in | ||
p) STORYBOOK_PORT=${OPTARG};; | ||
c) CONTAINER_NAME=${OPTARG};; | ||
f) FUNCS="$FUNCS ${OPTARG}";; | ||
t) BUILD_TARGET="${OPTARG}";; | ||
esac | ||
done | ||
|
||
build_container() { | ||
if [[ $BUILD_TARGET != "serve" ]] && [[ $BUILD_TARGET != "test" ]]; then | ||
echo "Invalid BUILD_TARGET! It should be either 'serve' or 'test.' You need to pass these values in with the -t flag (e.g. -t serve)." | ||
exit 1 | ||
fi | ||
|
||
docker build --tag 'playwright' . -f $BASE_PATH/../Dockerfile --progress=plain --target $BUILD_TARGET | ||
} | ||
|
||
run_container() { | ||
docker run -p 4321:4321 -p $STORYBOOK_PORT:$STORYBOOK_PORT --name $CONTAINER_NAME -v $(dirname $0)/../../:/srv/apps/atj-platform -it --rm playwright | ||
} | ||
|
||
end_to_end() { | ||
docker exec -w /srv/apps/atj-platform/e2e -it $CONTAINER_NAME pnpm playwright test | ||
} | ||
|
||
interaction() { | ||
docker exec -it $CONTAINER_NAME pnpm --filter=end-to-end-tests test:storybook --url http://localhost:$STORYBOOK_PORT --config-dir ../packages/design/.storybook/ --browsers firefox chromium | ||
} | ||
|
||
if ! command -v docker &> /dev/null; then | ||
echo "Docker is not installed. Please install Docker to run this script." | ||
exit 1 | ||
fi | ||
|
||
|
||
if [ -z "$FUNCS" ]; then | ||
end_to_end | ||
interaction | ||
else | ||
for FUNC in $FUNCS; do | ||
case $FUNC in | ||
"build_container") build_container ;; | ||
"run_container") run_container ;; | ||
"interaction") interaction ;; | ||
"end_to_end") end_to_end ;; | ||
*) echo "Invalid flag: ${FUNC}. Ignored." ;; | ||
esac | ||
done | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const BASE_URL = process.env.E2E_ENDPOINT; | ||
export const STORYBOOK_PATH = 'design/iframe.html?id='; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.