Skip to content

Commit 6f137a6

Browse files
authored
feat: Earthfile flutter integration tests (#304)
* feat(earthly): first draft * feat: adds cspell words * feat: adds scripts and earthly target to install browsers * feat: adds test targets * feat: cleanup and cspell * feat: adds logging * feat: removing edge testing * fix: restore cspell * feat: remove integration test workflow
1 parent 9e580c0 commit 6f137a6

File tree

7 files changed

+138
-67
lines changed

7 files changed

+138
-67
lines changed

.config/dictionaries/project.dic

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dotglob
3737
drep
3838
dreps
3939
earthfile
40+
Edgedriver
4041
encryptor
4142
fetchval
4243
fmtchk
@@ -47,6 +48,7 @@ Formz
4748
fuzzer
4849
gapless
4950
gcloud
51+
geckodriver
5052
genhtml
5153
gethostname
5254
gmtime
@@ -72,6 +74,7 @@ mgrybyk
7274
mithril
7375
mitigations
7476
moderations
77+
msedgedriver
7578
multidex
7679
myproject
7780
nanos

.github/workflows/flutter-web-integration-test.yml

-46
This file was deleted.

catalyst_voices/Earthfile

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
VERSION --try --global-cache 0.7
1+
VERSION --try --global-cache --arg-scope-and-set 0.7
22

33
deps:
4-
FROM debian:stable-slim
4+
FROM debian:bookworm-slim
55
RUN apt-get update
6-
RUN apt-get install -y curl git unzip bash
7-
WORKDIR /frontend
6+
RUN apt-get install -y git curl unzip bzip2 bash jq gpg
7+
COPY --dir test_driver/scripts .
8+
RUN chmod +x scripts/install-chrome-linux64.sh && ./scripts/install-chrome-linux64.sh
9+
RUN chmod +x scripts/install-edge-linux64.sh && ./scripts/install-edge-linux64.sh
10+
RUN chmod +x scripts/install-firefox-linux64.sh && ./scripts/install-firefox-linux64.sh
811

9-
# Download and set-up flutter
10-
flutter:
11-
FROM +deps
12+
WORKDIR /frontend
1213

13-
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter
14+
GIT CLONE https://github.com/flutter/flutter.git /usr/local/flutter
1415
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
1516

1617
RUN flutter channel stable
@@ -19,11 +20,13 @@ flutter:
1920
RUN flutter doctor -v
2021
RUN flutter config --enable-web
2122

23+
src:
24+
FROM +deps
25+
COPY --dir pubspec.yaml lib packages web test test_driver integration_test .
26+
2227
# Build web version of Catalyst Voices
2328
build:
24-
FROM +flutter
25-
26-
COPY --dir pubspec.yaml lib packages web test test_driver integration_test .
29+
FROM +src
2730

2831
RUN flutter clean
2932
RUN flutter pub get
@@ -32,18 +35,11 @@ build:
3235
WORKDIR /frontend/build
3336
SAVE ARTIFACT web /web AS LOCAL web
3437

35-
docker:
36-
FROM +deps
37-
FROM nginx:stable-alpine3.17
38-
38+
package:
39+
FROM nginx:alpine3.18
40+
ARG tag='latest'
3941
COPY +build/web /app
4042
COPY ./nginx.conf /etc/nginx/nginx.conf
41-
4243
EXPOSE 80
4344

44-
package:
45-
FROM +docker
46-
47-
ARG tag='latest'
48-
4945
SAVE IMAGE catalyst-voices-app:$tag

catalyst_voices/test_driver/Earthfile

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
VERSION --try --global-cache --arg-scope-and-set 0.7
2+
3+
integration-test-web:
4+
FROM ../+build
5+
ARG browser
6+
LET driver_port = 4444
7+
8+
IF [ $browser = "chrome" ]
9+
LET driver = "chromedriver"
10+
END
11+
12+
IF [ $browser = "firefox" ]
13+
LET driver = "geckodriver"
14+
END
15+
# Commenting out Edge tests as they are failing due to:
16+
# https://github.com/flutter/flutter/issues/76213
17+
# https://github.com/flutter/flutter/issues/142021
18+
#IF [ $browser = "edge" ]
19+
# LET driver = "msedgedriver"
20+
#END
21+
RUN ($driver --port=$driver_port > $driver.log &) && \
22+
flutter drive --driver=test_driver/integration_test.dart \
23+
--target=integration_test/main.dart \
24+
--flavor development -d web-server --profile \
25+
--browser-name=$browser --driver-port=$driver_port || echo fail > fail
26+
# Using WAIT instead of TRY because TRY/CATCH/FINALLY does not (currently) support expanding args for SAVE ARTIFACT paths
27+
WAIT
28+
SAVE ARTIFACT $driver.log AS LOCAL $driver.log
29+
END
30+
IF [ -f fail ]
31+
RUN echo ""$browser" integration test failed" && \
32+
echo "Printing "$driver" logs..." && \
33+
cat $driver.log && \
34+
exit 1
35+
END
36+
37+
test-web-all:
38+
BUILD +integration-test-web \
39+
--browser=chrome \
40+
--browser=firefox
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# This script installs Chrome for testing and Chromedriver
3+
PLATFORM=linux64
4+
DISTR="Debian 12 (Bookworm)"
5+
6+
# Installing dependencies for Chrome. Workaround for:
7+
# https://github.com/GoogleChromeLabs/chrome-for-testing/issues/55
8+
echo "Installing Google Chrome dependencies"
9+
chrome_deps=$(curl -s https://raw.githubusercontent.com/chromium/chromium/main/chrome/installer/linux/debian/dist_package_versions.json)
10+
deps=$(echo "$chrome_deps" | jq -r ".\"$DISTR\" | keys[]")
11+
apt-get update
12+
for dep in $deps; do
13+
apt-get install -y $dep
14+
done
15+
16+
# Get latest chrome for testing version
17+
json_chrome=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json)
18+
19+
# Install chrome
20+
echo "Installing Google Chrome..."
21+
latest_chrome=$(echo "$json_chrome" | jq -r ".channels.Stable.downloads.chrome[].url | select(contains(\"$PLATFORM\"))")
22+
curl -s --create-dirs -o chrome.zip --output-dir /opt/chrome "$latest_chrome"
23+
unzip -d /opt/chrome -j /opt/chrome/chrome.zip && rm /opt/chrome/chrome.zip
24+
ln -s /opt/chrome/chrome /usr/local/bin/google-chrome
25+
chmod +x /opt/chrome/chrome
26+
google-chrome --version
27+
28+
# Install chromedriver
29+
echo "Installing Chromedriver..."
30+
latest_chromedriver=$(echo "$json_chrome" | jq -r ".channels.Stable.downloads.chromedriver[].url | select(contains(\"$PLATFORM\"))")
31+
curl -s --create-dirs -o chromedriver.zip --output-dir /opt/chromedriver "$latest_chromedriver"
32+
unzip -d /opt/chromedriver -j /opt/chromedriver/chromedriver.zip && rm /opt/chromedriver/chromedriver.zip
33+
ln -s /opt/chromedriver/chromedriver /usr/local/bin/chromedriver
34+
chmod +x /opt/chromedriver/chromedriver
35+
chromedriver --version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# This script installs Edge and Edgedriver.
3+
PLATFORM=linux64
4+
5+
echo "Installing Edge..."
6+
install -d -m 0755 /etc/apt/keyrings
7+
curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/keyrings/microsoft-edge.gpg > /dev/null
8+
echo 'deb [signed-by=/etc/apt/keyrings/microsoft-edge.gpg] https://packages.microsoft.com/repos/edge stable main' | tee /etc/apt/sources.list.d/microsoft-edge.list
9+
apt-get update && apt-get install -y microsoft-edge-stable
10+
microsoft-edge-stable --version
11+
12+
echo "Installing Edgedriver..."
13+
edge_version=$(microsoft-edge-stable --version | grep -Eo '[0-9]+.+' | tr -d ' ')
14+
curl -s --create-dirs -o msedgedriver.zip --output-dir /opt/msedgedriver "https://msedgedriver.azureedge.net/$edge_version/edgedriver_$PLATFORM.zip"
15+
unzip -d /opt/msedgedriver -j /opt/msedgedriver/msedgedriver.zip && rm /opt/msedgedriver/msedgedriver.zip
16+
ln -s /opt/msedgedriver/msedgedriver /usr/local/bin/msedgedriver
17+
chmod +x /opt/msedgedriver/msedgedriver
18+
msedgedriver --version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# This script installs Firefox and Geckodriver. Geckodriver supported versions:
3+
# https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html
4+
PLATFORM=linux64
5+
6+
echo "Installing Firefox..."
7+
install -d -m 0755 /etc/apt/keyrings
8+
curl -fSsL https://packages.mozilla.org/apt/repo-signing-key.gpg | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null
9+
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null
10+
echo '
11+
Package: *
12+
Pin: origin packages.mozilla.org
13+
Pin-Priority: 1000
14+
' | tee /etc/apt/preferences.d/mozilla
15+
apt-get update && apt-get install -y firefox
16+
firefox --version
17+
18+
echo "Installing Geckodriver..."
19+
json_geckodriver=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
20+
latest_geckodriver=$(echo "$json_geckodriver" | jq -r ".assets[].browser_download_url | select(contains(\"$PLATFORM\") and endswith(\"gz\"))")
21+
curl -sL --create-dirs -o geckodriver.tar.gz --output-dir /opt/geckodriver "$latest_geckodriver"
22+
tar -xzf /opt/geckodriver/geckodriver.tar.gz -C /opt/geckodriver/ && rm /opt/geckodriver/geckodriver.tar.gz
23+
ln -s /opt/geckodriver/geckodriver /usr/local/bin/geckodriver
24+
chmod +x /opt/geckodriver/geckodriver
25+
geckodriver --version

0 commit comments

Comments
 (0)