Skip to content

Commit 4f7c294

Browse files
authored
Merge pull request #54 from dustywusty/e2e-actions
adding testing workflow
2 parents af84ae2 + a740722 commit 4f7c294

File tree

4 files changed

+116
-51
lines changed

4 files changed

+116
-51
lines changed

.github/workflows/e2e.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: E2E
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
e2e:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: stable
19+
- uses: browser-actions/setup-chrome@v1
20+
id: chrome
21+
- name: Install ffmpeg
22+
run: sudo apt-get update && sudo apt-get install -y ffmpeg
23+
- name: Run e2e tests
24+
env:
25+
CHROME_BIN: ${{ steps.chrome.outputs.chrome-path }}
26+
CHROMEDP_NO_SANDBOX: "1"
27+
E2E_RECORD: "1"
28+
E2E_RECORD_FORMAT: gif
29+
E2E_RECORD_FPS: "6"
30+
run: make test-e2e
31+
- name: Upload e2e gifs
32+
if: always()
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: e2e-gifs
36+
path: e2e-artifacts
37+
if-no-files-found: warn
38+
retention-days: 7
39+
- name: Publish gifs to e2e-artifacts branch
40+
if: always() && github.event.pull_request.head.repo.fork == false
41+
env:
42+
RUN_ID: ${{ github.run_id }}
43+
run: |
44+
set -euo pipefail
45+
if ! ls e2e-artifacts/*.gif >/dev/null 2>&1; then
46+
echo "No gifs to publish"
47+
exit 0
48+
fi
49+
git config user.name "github-actions[bot]"
50+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
51+
if git show-ref --quiet refs/remotes/origin/e2e-artifacts; then
52+
git checkout -B e2e-artifacts origin/e2e-artifacts
53+
else
54+
git checkout --orphan e2e-artifacts
55+
git rm -rf . >/dev/null 2>&1 || true
56+
fi
57+
mkdir -p "e2e/${RUN_ID}"
58+
cp e2e-artifacts/*.gif "e2e/${RUN_ID}/"
59+
git add "e2e/${RUN_ID}"
60+
git commit -m "e2e gifs for run ${RUN_ID}"
61+
git push origin e2e-artifacts
62+
- name: Comment with e2e gifs
63+
if: always() && github.event.pull_request.head.repo.fork == false
64+
uses: actions/github-script@v7
65+
with:
66+
script: |
67+
const marker = "<!-- e2e-gifs -->";
68+
const { owner, repo } = context.repo;
69+
const issue_number = context.payload.pull_request.number;
70+
const run_id = context.runId.toString();
71+
const fs = require("fs");
72+
const dir = "e2e-artifacts";
73+
let files = [];
74+
if (fs.existsSync(dir)) {
75+
files = fs
76+
.readdirSync(dir)
77+
.filter((file) => file.toLowerCase().endsWith(".gif"));
78+
}
79+
const base = `https://raw.githubusercontent.com/${owner}/${repo}/e2e-artifacts/e2e/${run_id}`;
80+
const lines = files.length
81+
? files.map((file) => `![${file}](${base}/${encodeURIComponent(file)})`)
82+
: ["(no gifs found)"];
83+
const body = [
84+
marker,
85+
"E2E gifs:",
86+
...lines,
87+
].join("\n");
88+
const { data: comments } = await github.rest.issues.listComments({
89+
owner,
90+
repo,
91+
issue_number,
92+
per_page: 100,
93+
});
94+
const existing = comments.find((comment) => comment.body && comment.body.includes(marker));
95+
if (existing) {
96+
await github.rest.issues.updateComment({
97+
owner,
98+
repo,
99+
comment_id: existing.id,
100+
body,
101+
});
102+
} else {
103+
await github.rest.issues.createComment({
104+
owner,
105+
repo,
106+
issue_number,
107+
body,
108+
});
109+
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ BIN := bin/$(APP)
33
PKG := .
44
PORT ?= 8080
55
CHROMEDP_HEADLESS ?= 1
6-
CHROMEDP_VIEWPORT_WIDTH ?= 1280
7-
CHROMEDP_VIEWPORT_HEIGHT ?= 2000
6+
CHROMEDP_VIEWPORT_WIDTH ?= 393
7+
CHROMEDP_VIEWPORT_HEIGHT ?= 852
88
E2E_RECORD ?= 1
99
E2E_RECORD_FORMAT ?= gif
1010
E2E_RECORD_FPS ?= 6

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Notes:
7474
- Famous quick mates:
7575
- Fool's Mate: `go test -tags e2e ./internal/e2e -run TestPlayFullGame`
7676
- Scholar's Mate: `go test -tags e2e ./internal/e2e -run TestPlayScholarsMate`
77-
- A longer demo test is available: `go test -tags e2e ./internal/e2e -run TestPlayLongGame`.
7877
- Optional recording:
7978
- Set `E2E_RECORD=1` to capture screenshots before each move (white client).
8079
- Output defaults to `e2e-artifacts/` (override with `E2E_RECORD_DIR`).
@@ -91,7 +90,7 @@ E2E_RECORD=1 E2E_RECORD_FORMAT=gif E2E_RECORD_FPS=6 make test-e2e
9190

9291
Defaults can be overridden:
9392
- `CHROMEDP_HEADLESS=0` to watch the run.
94-
- `CHROMEDP_VIEWPORT_WIDTH` and `CHROMEDP_VIEWPORT_HEIGHT` for mobile/aspect testing.
93+
- `CHROMEDP_VIEWPORT_WIDTH` and `CHROMEDP_VIEWPORT_HEIGHT` for mobile/aspect testing (defaults to iPhone 15 Pro: 393x852).
9594
- `E2E_MOVE_DELAY_MS` and `E2E_START_DELAY_MS` for timing.
9695
- `E2E_CAPTURE_DELAY_MS` to wait for SSE/UI updates before each capture.
9796
- `E2E_RECORD_HOLD_MS` to extend the final frame.

internal/e2e/play_full_game_test.go

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,6 @@ func TestPlayScholarsMate(t *testing.T) {
5656
}, true)
5757
}
5858

59-
func TestPlayLongGame(t *testing.T) {
60-
if testing.Short() {
61-
t.Skip("skipping e2e test in short mode")
62-
}
63-
64-
runGame(t, "long", []move{
65-
{color: "white", from: "e2", to: "e4"},
66-
{color: "black", from: "e7", to: "e5"},
67-
{color: "white", from: "g1", to: "f3"},
68-
{color: "black", from: "b8", to: "c6"},
69-
{color: "white", from: "f1", to: "b5"},
70-
{color: "black", from: "a7", to: "a6"},
71-
{color: "white", from: "b5", to: "a4"},
72-
{color: "black", from: "g8", to: "f6"},
73-
{color: "white", from: "e1", to: "g1"},
74-
{color: "black", from: "f8", to: "e7"},
75-
{color: "white", from: "f1", to: "e1"},
76-
{color: "black", from: "b7", to: "b5"},
77-
{color: "white", from: "a4", to: "b3"},
78-
{color: "black", from: "d7", to: "d6"},
79-
{color: "white", from: "c2", to: "c3"},
80-
{color: "black", from: "e8", to: "g8"},
81-
{color: "white", from: "h2", to: "h3"},
82-
{color: "black", from: "c6", to: "a5"},
83-
{color: "white", from: "b3", to: "c2"},
84-
{color: "black", from: "c7", to: "c5"},
85-
{color: "white", from: "d2", to: "d4"},
86-
{color: "black", from: "c5", to: "d4"},
87-
{color: "white", from: "c3", to: "d4"},
88-
{color: "black", from: "d8", to: "c7"},
89-
{color: "white", from: "d4", to: "e5"},
90-
{color: "black", from: "d6", to: "e5"},
91-
{color: "white", from: "f3", to: "e5"},
92-
{color: "black", from: "f6", to: "e4"},
93-
{color: "white", from: "e5", to: "d3"},
94-
{color: "black", from: "e4", to: "f6"},
95-
{color: "white", from: "d1", to: "d2"},
96-
{color: "black", from: "c7", to: "d6"},
97-
{color: "white", from: "c2", to: "b3"},
98-
{color: "black", from: "c8", to: "e6"},
99-
}, false)
100-
}
101-
10259
type move struct {
10360
color string
10461
from string
@@ -119,8 +76,8 @@ func runGame(t *testing.T, label string, moves []move, expectMate bool) {
11976
blackCtx, blackCancel := newBrowserCtx(t)
12077
defer blackCancel()
12178

122-
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 1280)
123-
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 2000)
79+
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 393)
80+
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 852)
12481

12582
attachDebug(t, whiteCtx, "white-"+label)
12683
attachDebug(t, blackCtx, "black-"+label)
@@ -251,8 +208,8 @@ func newBrowserCtx(t *testing.T) (context.Context, context.CancelFunc) {
251208
t.Fatalf("temp dir: %v", err)
252209
}
253210

254-
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 1280)
255-
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 2000)
211+
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 393)
212+
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 852)
256213
opts := append(chromedp.DefaultExecAllocatorOptions[:],
257214
chromedp.NoFirstRun,
258215
chromedp.NoDefaultBrowserCheck,

0 commit comments

Comments
 (0)