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

kie-issues#1114: Containerize Playwright end-to-end tests to resolve screenshot comparison issues caused by OS differences #2866

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

ljmotta
Copy link
Contributor

@ljmotta ljmotta commented Jan 21, 2025

Closes apache/incubator-kie-issues#1114
Closes #2839

Description

This PR introduces containerized end-to-end (E2E) Playwright tests to ensure consistent and reliable test execution across environments.

Tests were executed in the following environments:

  • macOS
    • arm64
    • Sonoma 14.6.1
    • Podman Desktop v1.15
    • Podman Engine 5.3.1
    • Docker CLI 27.2.1
  • Windows WSL
    • amd64
    • Ubuntu 22.04.3 LTS
    • Docker CE CLI 25.0.2
    • Docker CE Engine 25.0.2

Known Issues

  • Running the online-editor containerized test-e2e script on macOS requires starting the services in a separate terminal.
  • Performance: Tests may run slower on macOS due to architecture differences.
  • Flakiness: Retries are enabled because tests can occasionally fail without valid reasons when running in the restricted containerized environment.
  • Debugging tests is not currently supported but could be added in the future.
  • The Docker CLI is required to run the containerized tests.

Trying it out

  • Install the dependencies.
  • Build the @kie-tools/playwright-base image with the following command:
KIE_TOOLS_BUILD__buildContainerImages=true pnpm -F @kie-tools/playwright-base image:docker:build
  • In a package that contains Playwright e2e tests, run the following:
KIE_TOOLS_BUILD__runContainerizedEndToEndTests=true pnpm test-e2e

This command will start the required services and run the tests inside the container.

Updating screenshots

To update screenshots, use the pnpm test-e2e:container:shell script to open a shell inside the container:

pnpm test-e2e:container:shell
# In the container shell, manually call the `test-e2e:run` passing the `-u` or `--update-snapshots` flag
pnpm test-e2e:run -u
# or
pnpm test-e2e:run --update-snapshots

To improve performance, you can filter which tests will run by adding the -g flag:

pnpm test-e2e:run -u -g "test name"

@ljmotta ljmotta added area:dependencies Pull requests that update a dependency file area:tests labels Jan 21, 2025
@ljmotta ljmotta self-assigned this Jan 21, 2025
@ljmotta ljmotta requested a review from tiagobento as a code owner January 21, 2025 22:08
@ljmotta ljmotta added the pr: wip PR is still under development label Jan 21, 2025
@jomarko
Copy link
Contributor

jomarko commented Jan 22, 2025

Thank you @ljmotta . Please, let us know this is ready for a verification. I will try on non-MAC environment.

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 23, 2025

@jomarko This PR can be tested for macOS and Linux. I still need to make some adjustments for native Windows (non WSL).

Copy link
Member

@thiagoelg thiagoelg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR @ljmotta! This will make our e2e tests more stable and concise!

I've made some comments below about the package.json scripts; let me know what you think.

packages/playwright-base/package.json Outdated Show resolved Hide resolved
packages/online-editor/package.json Outdated Show resolved Hide resolved
@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 23, 2025

Status update regarding Windows. My current setup with Docker CLI + Docker WSL didn't work, as WSL doesn't handle Windows symlinks [1][2], which is heavily used by pnpm, so mounting the Windows volume in the container doesn't work. I'll try a different approach with Docker CLI + Podman Desktop to check. Podman works a little different, but it also uses WSL behind the scenes so I'm not too confident, but I'll give it a shot.

[1] microsoft/WSL#5118
[2] microsoft/WSL#12250

@tiagobento
Copy link
Contributor

Maybe try hard links @ljmotta? I think we had a similar issue with maven-m2-repo-via-http-inage.

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 24, 2025

@tiagobento The symlinks are located in the node_modules directory, so switching to hard links might not be straightforward. After experimenting, I made some progress with volumes using Docker Desktop and HyperV. However, I encountered two additional issues:

  1. It appears that playwright Windows browsers cannot be used inside the container. This means the browsers need to be reinstalled. Furthermore, the playwright binary is unavailable, requiring a full reinstallation of playwright, including erasing node_modules [1].
  2. To address the first issue, all untracked files (e.g., node_modules) need to be removed. However, since pnpm creates recursive structures with symlinks, the git clean -fdx command cannot be used [2][3].

Even if the second issue were resolved, having to fix the first issue every time a container is started would be impractical. Considering these challenges, I am leaning toward not supporting Windows development without WSL for this pull request.

[1] microsoft/playwright#23098 (comment)
[2] git-for-windows/git#3358
[3] pnpm/pnpm#4401

@tiagobento
Copy link
Contributor

@ljmotta I'm ok with not supporting Windows without WSL here, just please add a new statement to the README making that explicit. And thank you so much for the effort!

Comment on lines 100 to 102
containerizedEndToEndTests: {
run: str2bool(getOrDefault(this.vars.KIE_TOOLS_BUILD__runContainerizedEndToEndTests)),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think the KIE_TOOLS_BUILD__runEndToEndTests env var should still be the one use to toggle the execution of the E2E tests, and this new flag should only toggle the MODE with which the tests run.

KIE_TOOLS_BUILD__runEndToEndTests=false
# E2E tests don't run and `KIE_TOOLS_BUILD__runContainerizedEndToEndTests` is ignored.
KIE_TOOLS_BUILD__runEndToEndTests=true
KIE_TOOLS_BUILD__runContainerizedEndToEndTests=true
# E2E tests run inside containers
KIE_TOOLS_BUILD__runEndToEndTests=true
KIE_TOOLS_BUILD__runContainerizedEndToEndTests=false (default)
# E2E tests run on host machine (without containers involved)

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dependencies Pull requests that update a dependency file area:tests pr: wip PR is still under development
Projects
None yet
4 participants