Skip to content

Commit 9238e8f

Browse files
authoredMar 19, 2025··
test: adds flutter web unit tests (#390)
* adds: flutter-web-unit-tests * adds chrome patch * adds fix for arm * adds fix path * adds fix path
1 parent 6d69e9d commit 9238e8f

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed
 

‎earthly/flutter/Earthfile

+67-23
Original file line numberDiff line numberDiff line change
@@ -170,33 +170,77 @@ PUBLISH_DRY_RUN:
170170
UNIT_TESTS:
171171
FUNCTION
172172

173-
IF [ -f melos.yaml ]
174-
RUN echo "Running unit tests with melos."
175-
176-
# We always want to save the test_reports and coverage
177-
# therefore we must defer the error reported here until later.
178-
RUN melos run test-report > melos-output.txt 2>&1 || touch fail
179-
180-
# If not failed then print the output immediately,
181-
# if it has failed then it's printed at the end of the function when exiting.
182-
IF [ ! -f fail ]
183-
RUN cat melos-output.txt
184-
END
173+
ARG PLATFORM=native
174+
ARG REPORT=false
185175

186-
WAIT
187-
SAVE ARTIFACT test_reports AS LOCAL test_reports
188-
SAVE ARTIFACT coverage AS LOCAL coverage
176+
IF [ -f melos.yaml ]
177+
IF [ $PLATFORM = native ]
178+
RUN echo "Running native unit tests with melos."
179+
180+
IF [ $REPORT = true ]
181+
# We always want to save the test_reports and coverage
182+
# therefore we must defer the error reported here until later.
183+
RUN melos run test-report-native > melos-output.txt 2>&1 || touch fail
184+
185+
# If not failed then print the output immediately,
186+
# if it has failed then it's printed at the end of the function when exiting.
187+
IF [ ! -f fail ]
188+
RUN cat melos-output.txt
189+
END
190+
191+
WAIT
192+
SAVE ARTIFACT test_reports AS LOCAL test_reports
193+
SAVE ARTIFACT coverage AS LOCAL coverage
194+
END
195+
196+
# Defer the failure to here.
197+
IF [ -f fail ]
198+
RUN echo "Error occurred when running: melos run test-report"; \
199+
cat melos-output.txt; \
200+
exit 1
201+
END
202+
ELSE
203+
RUN melos run test-native
204+
END
189205
END
190-
191-
# Defer the failure to here.
192-
IF [ -f fail ]
193-
RUN echo "Error occurred when running: melos run test-report"; \
194-
cat melos-output.txt; \
195-
exit 1
206+
IF [ $PLATFORM = web ]
207+
RUN echo "Running web unit tests with melos."
208+
209+
IF [ $REPORT = true ]
210+
# We always want to save the test_reports and coverage
211+
# therefore we must defer the error reported here until later.
212+
RUN melos run test-report-web > melos-output.txt 2>&1 || touch fail
213+
214+
# If not failed then print the output immediately,
215+
# if it has failed then it's printed at the end of the function when exiting.
216+
IF [ ! -f fail ]
217+
RUN cat melos-output.txt
218+
END
219+
220+
WAIT
221+
SAVE ARTIFACT test_reports AS LOCAL test_reports
222+
SAVE ARTIFACT coverage AS LOCAL coverage
223+
END
224+
225+
# Defer the failure to here.
226+
IF [ -f fail ]
227+
RUN echo "Error occurred when running: melos run test-report"; \
228+
cat melos-output.txt; \
229+
exit 1
230+
END
231+
ELSE
232+
RUN melos run test-web
233+
END
196234
END
197235
ELSE
198-
RUN echo "Running flutter test"
199-
RUN flutter test
236+
IF [ $PLATFORM = native ]
237+
RUN echo "Running flutter native test"
238+
RUN flutter test
239+
END
240+
IF [ $PLATFORM = web ]
241+
RUN echo "Running flutter web test"
242+
RUN flutter test --platform chrome
243+
END
200244
END
201245

202246
# Build web app and save artifacts locally if needed.

‎earthly/flutter/installer/Earthfile

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ INSTALL_CHROME_LINUX64:
3535
&& apt-get install -f -y \
3636
&& rm -rf /opt/chrome.zip /opt/chrome
3737
RUN google-chrome --version
38+
DO +PATCH_CHROME --BIN_TO_PATCH="google-chrome"
3839

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

5052
DO +INSTALL_CHROMIUM --PACKAGE_TYPE="chromium-driver" --DOWNLOAD_URL="${BASE_URL}/chrome/chromium-driver.zip"
5153
RUN chromedriver --version
@@ -137,3 +139,13 @@ INSTALL_CHROMIUM:
137139
&& rm /opt/${PACKAGE_TYPE}.zip \
138140
&& rm -r /opt/${PACKAGE_TYPE} \
139141
&& echo "${PACKAGE_TYPE} installation completed."
142+
143+
PATCH_CHROME:
144+
FUNCTION
145+
ARG --required BIN_TO_PATCH
146+
# patch Chrome - workaround for https://github.com/flutter/flutter/issues/154727
147+
ENV CHROME_EXECUTABLE="/usr/local/bin/chrome-patch.sh"
148+
RUN printf "${BLUE} Creating a ${BIN_TO_PATCH} patch at ${CHROME_EXECUTABLE}..." \
149+
&& echo '#!/bin/bash' > $CHROME_EXECUTABLE \
150+
&& echo '/usr/bin/'$BIN_TO_PATCH' --no-sandbox --disable-gpu --disable-dev-shm-usage --headless --disable-extensions --disable-popup-blocking --incognito "$@"' >> $CHROME_EXECUTABLE \
151+
&& chmod +x $CHROME_EXECUTABLE

0 commit comments

Comments
 (0)
Please sign in to comment.