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

test: adds flutter web unit tests #390

Merged
merged 6 commits into from
Mar 19, 2025
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
90 changes: 67 additions & 23 deletions earthly/flutter/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -170,33 +170,77 @@ PUBLISH_DRY_RUN:
UNIT_TESTS:
FUNCTION

IF [ -f melos.yaml ]
RUN echo "Running unit tests with melos."

# We always want to save the test_reports and coverage
# therefore we must defer the error reported here until later.
RUN melos run test-report > melos-output.txt 2>&1 || touch fail

# If not failed then print the output immediately,
# if it has failed then it's printed at the end of the function when exiting.
IF [ ! -f fail ]
RUN cat melos-output.txt
END
ARG PLATFORM=native
ARG REPORT=false

WAIT
SAVE ARTIFACT test_reports AS LOCAL test_reports
SAVE ARTIFACT coverage AS LOCAL coverage
IF [ -f melos.yaml ]
IF [ $PLATFORM = native ]
RUN echo "Running native unit tests with melos."

IF [ $REPORT = true ]
# We always want to save the test_reports and coverage
# therefore we must defer the error reported here until later.
RUN melos run test-report-native > melos-output.txt 2>&1 || touch fail

# If not failed then print the output immediately,
# if it has failed then it's printed at the end of the function when exiting.
IF [ ! -f fail ]
RUN cat melos-output.txt
END

WAIT
SAVE ARTIFACT test_reports AS LOCAL test_reports
SAVE ARTIFACT coverage AS LOCAL coverage
END

# Defer the failure to here.
IF [ -f fail ]
RUN echo "Error occurred when running: melos run test-report"; \
cat melos-output.txt; \
exit 1
END
ELSE
RUN melos run test-native
END
END

# Defer the failure to here.
IF [ -f fail ]
RUN echo "Error occurred when running: melos run test-report"; \
cat melos-output.txt; \
exit 1
IF [ $PLATFORM = web ]
RUN echo "Running web unit tests with melos."

IF [ $REPORT = true ]
# We always want to save the test_reports and coverage
# therefore we must defer the error reported here until later.
RUN melos run test-report-web > melos-output.txt 2>&1 || touch fail

# If not failed then print the output immediately,
# if it has failed then it's printed at the end of the function when exiting.
IF [ ! -f fail ]
RUN cat melos-output.txt
END

WAIT
SAVE ARTIFACT test_reports AS LOCAL test_reports
SAVE ARTIFACT coverage AS LOCAL coverage
END

# Defer the failure to here.
IF [ -f fail ]
RUN echo "Error occurred when running: melos run test-report"; \
cat melos-output.txt; \
exit 1
END
ELSE
RUN melos run test-web
END
END
ELSE
RUN echo "Running flutter test"
RUN flutter test
IF [ $PLATFORM = native ]
RUN echo "Running flutter native test"
RUN flutter test
END
IF [ $PLATFORM = web ]
RUN echo "Running flutter web test"
RUN flutter test --platform chrome
END
END

# Build web app and save artifacts locally if needed.
Expand Down
12 changes: 12 additions & 0 deletions earthly/flutter/installer/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ INSTALL_CHROME_LINUX64:
&& apt-get install -f -y \
&& rm -rf /opt/chrome.zip /opt/chrome
RUN google-chrome --version
DO +PATCH_CHROME --BIN_TO_PATCH="google-chrome"

RUN printf "${BLUE} Installing Chromedriver..." \
&& mkdir -p /opt/chromedriver \
Expand All @@ -46,6 +47,7 @@ INSTALL_CHROME_LINUX64:
ELSE
DO +INSTALL_CHROMIUM --PACKAGE_TYPE="chromium" --DOWNLOAD_URL="${BASE_URL}/chrome/chromium.zip"
RUN chromium --version
DO +PATCH_CHROME --BIN_TO_PATCH="chromium"

DO +INSTALL_CHROMIUM --PACKAGE_TYPE="chromium-driver" --DOWNLOAD_URL="${BASE_URL}/chrome/chromium-driver.zip"
RUN chromedriver --version
Expand Down Expand Up @@ -137,3 +139,13 @@ INSTALL_CHROMIUM:
&& rm /opt/${PACKAGE_TYPE}.zip \
&& rm -r /opt/${PACKAGE_TYPE} \
&& echo "${PACKAGE_TYPE} installation completed."

PATCH_CHROME:
FUNCTION
ARG --required BIN_TO_PATCH
# patch Chrome - workaround for https://github.com/flutter/flutter/issues/154727
ENV CHROME_EXECUTABLE="/usr/local/bin/chrome-patch.sh"
RUN printf "${BLUE} Creating a ${BIN_TO_PATCH} patch at ${CHROME_EXECUTABLE}..." \
&& echo '#!/bin/bash' > $CHROME_EXECUTABLE \
&& echo '/usr/bin/'$BIN_TO_PATCH' --no-sandbox --disable-gpu --disable-dev-shm-usage --headless --disable-extensions --disable-popup-blocking --incognito "$@"' >> $CHROME_EXECUTABLE \
&& chmod +x $CHROME_EXECUTABLE
Loading