-
Notifications
You must be signed in to change notification settings - Fork 1
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
Run storybook tests with playwright #249
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1ff6f82
resolve conflicts
ethangardner 9ebd4f7
test cleanup
ethangardner bc30d9a
add post deployment action for testing
ethangardner 261c2f9
update lockfile to fix failing action
ethangardner fc0438e
update action name
ethangardner 9740619
correct config dir path
ethangardner f94d96d
add workflow dispatch for testing
ethangardner 19b6a5a
add push action for wip branch
ethangardner 6baa92d
fix failing test for radio group pattern edit
ethangardner f769587
update documentation and add script for storybook testing with playwr…
ethangardner cc94a2d
update lockfile
ethangardner 3c1c60c
update path in action
ethangardner fabdd8b
set endpoint in action
ethangardner 74eec1b
update workflow endpoint and run mode
ethangardner 567f55a
install playwright in gh action
ethangardner 534223c
create a self-contained image that runs through the tests on docker b…
ethangardner 70ae3e9
use docker in post-deploy action
ethangardner 26325c7
clean up logging for docker build
ethangardner 2ee44c3
simplify end to end tests
ethangardner f11d4a8
debugging tests
ethangardner 209ee88
rename test
ethangardner 0b6bc26
install unfiltered deps in docker--no-verify
ethangardner f17f4aa
change end-to-end back to imported convention
ethangardner 3c40e40
test deliberate failure in pipeline
ethangardner da6c75d
remove deliberately failing test
ethangardner 117f9e0
update adr for test strategy
ethangardner d3091ea
add drag and drop test
ethangardner 5aa5891
dry up test code
ethangardner 9838d6a
add mouse interaction test for drag-and-drop
ethangardner 7e9708f
fix flaky test
ethangardner a211bc4
remove flaky test
ethangardner 56e193e
Merge branch 'main' into 106-playwright-storybook
ethangardner e493d19
remove commented code
ethangardner bbe040f
ignore pnpm cache dir
ethangardner 0c7e9e9
use netcat instead of sleep to start server. pare down the copied fil…
ethangardner 04917d1
use netcat instead of sleep to start server. pare down the copied fil…
ethangardner 49219dd
add script to provide config for docker functions
ethangardner 210379a
update documentation and add provisions for running stories locally
ethangardner 9c53f42
grammar correction
ethangardner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good to give this a try... It solves the complaint about not being able to run locally, and gets the job done pretty concisely.
After using awhile, I might prefer to (for local development)
pnpm install playwright
and run tests natively on my Mac. With the container, running the tests in the multi-stage build portion is interesting and a nice way to keep it repeatable... but running the server during the build means we'd lose the ability to mount a volume on the container at runtime, and do dev server hot-reloading kinds of behavior.