Skip to content
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
109 changes: 109 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: E2E

on:
pull_request:

jobs:
e2e:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: browser-actions/setup-chrome@v1
id: chrome
- name: Install ffmpeg
run: sudo apt-get update && sudo apt-get install -y ffmpeg
- name: Run e2e tests
env:
CHROME_BIN: ${{ steps.chrome.outputs.chrome-path }}
CHROMEDP_NO_SANDBOX: "1"
E2E_RECORD: "1"
E2E_RECORD_FORMAT: gif
E2E_RECORD_FPS: "6"
run: make test-e2e
- name: Upload e2e gifs
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-gifs
path: e2e-artifacts
if-no-files-found: warn
retention-days: 7
- name: Publish gifs to e2e-artifacts branch
if: always() && github.event.pull_request.head.repo.fork == false
env:
RUN_ID: ${{ github.run_id }}
run: |
set -euo pipefail
if ! ls e2e-artifacts/*.gif >/dev/null 2>&1; then
echo "No gifs to publish"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git show-ref --quiet refs/remotes/origin/e2e-artifacts; then
git checkout -B e2e-artifacts origin/e2e-artifacts
else
git checkout --orphan e2e-artifacts
git rm -rf . >/dev/null 2>&1 || true
fi
mkdir -p "e2e/${RUN_ID}"
cp e2e-artifacts/*.gif "e2e/${RUN_ID}/"
git add "e2e/${RUN_ID}"
git commit -m "e2e gifs for run ${RUN_ID}"
git push origin e2e-artifacts
- name: Comment with e2e gifs
if: always() && github.event.pull_request.head.repo.fork == false
uses: actions/github-script@v7
with:
script: |
const marker = "<!-- e2e-gifs -->";
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const run_id = context.runId.toString();
const fs = require("fs");
const dir = "e2e-artifacts";
let files = [];
if (fs.existsSync(dir)) {
files = fs
.readdirSync(dir)
.filter((file) => file.toLowerCase().endsWith(".gif"));
}
const base = `https://raw.githubusercontent.com/${owner}/${repo}/e2e-artifacts/e2e/${run_id}`;
const lines = files.length
? files.map((file) => `![${file}](${base}/${encodeURIComponent(file)})`)
: ["(no gifs found)"];
const body = [
marker,
"E2E gifs:",
...lines,
].join("\n");
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find((comment) => comment.body && comment.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ BIN := bin/$(APP)
PKG := .
PORT ?= 8080
CHROMEDP_HEADLESS ?= 1
CHROMEDP_VIEWPORT_WIDTH ?= 1280
CHROMEDP_VIEWPORT_HEIGHT ?= 2000
CHROMEDP_VIEWPORT_WIDTH ?= 393
CHROMEDP_VIEWPORT_HEIGHT ?= 852
E2E_RECORD ?= 1
E2E_RECORD_FORMAT ?= gif
E2E_RECORD_FPS ?= 6
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Notes:
- Famous quick mates:
- Fool's Mate: `go test -tags e2e ./internal/e2e -run TestPlayFullGame`
- Scholar's Mate: `go test -tags e2e ./internal/e2e -run TestPlayScholarsMate`
- A longer demo test is available: `go test -tags e2e ./internal/e2e -run TestPlayLongGame`.
- Optional recording:
- Set `E2E_RECORD=1` to capture screenshots before each move (white client).
- Output defaults to `e2e-artifacts/` (override with `E2E_RECORD_DIR`).
Expand All @@ -91,7 +90,7 @@ E2E_RECORD=1 E2E_RECORD_FORMAT=gif E2E_RECORD_FPS=6 make test-e2e

Defaults can be overridden:
- `CHROMEDP_HEADLESS=0` to watch the run.
- `CHROMEDP_VIEWPORT_WIDTH` and `CHROMEDP_VIEWPORT_HEIGHT` for mobile/aspect testing.
- `CHROMEDP_VIEWPORT_WIDTH` and `CHROMEDP_VIEWPORT_HEIGHT` for mobile/aspect testing (defaults to iPhone 15 Pro: 393x852).
- `E2E_MOVE_DELAY_MS` and `E2E_START_DELAY_MS` for timing.
- `E2E_CAPTURE_DELAY_MS` to wait for SSE/UI updates before each capture.
- `E2E_RECORD_HOLD_MS` to extend the final frame.
Expand Down
51 changes: 4 additions & 47 deletions internal/e2e/play_full_game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,49 +56,6 @@ func TestPlayScholarsMate(t *testing.T) {
}, true)
}

func TestPlayLongGame(t *testing.T) {
if testing.Short() {
t.Skip("skipping e2e test in short mode")
}

runGame(t, "long", []move{
{color: "white", from: "e2", to: "e4"},
{color: "black", from: "e7", to: "e5"},
{color: "white", from: "g1", to: "f3"},
{color: "black", from: "b8", to: "c6"},
{color: "white", from: "f1", to: "b5"},
{color: "black", from: "a7", to: "a6"},
{color: "white", from: "b5", to: "a4"},
{color: "black", from: "g8", to: "f6"},
{color: "white", from: "e1", to: "g1"},
{color: "black", from: "f8", to: "e7"},
{color: "white", from: "f1", to: "e1"},
{color: "black", from: "b7", to: "b5"},
{color: "white", from: "a4", to: "b3"},
{color: "black", from: "d7", to: "d6"},
{color: "white", from: "c2", to: "c3"},
{color: "black", from: "e8", to: "g8"},
{color: "white", from: "h2", to: "h3"},
{color: "black", from: "c6", to: "a5"},
{color: "white", from: "b3", to: "c2"},
{color: "black", from: "c7", to: "c5"},
{color: "white", from: "d2", to: "d4"},
{color: "black", from: "c5", to: "d4"},
{color: "white", from: "c3", to: "d4"},
{color: "black", from: "d8", to: "c7"},
{color: "white", from: "d4", to: "e5"},
{color: "black", from: "d6", to: "e5"},
{color: "white", from: "f3", to: "e5"},
{color: "black", from: "f6", to: "e4"},
{color: "white", from: "e5", to: "d3"},
{color: "black", from: "e4", to: "f6"},
{color: "white", from: "d1", to: "d2"},
{color: "black", from: "c7", to: "d6"},
{color: "white", from: "c2", to: "b3"},
{color: "black", from: "c8", to: "e6"},
}, false)
}

type move struct {
color string
from string
Expand All @@ -119,8 +76,8 @@ func runGame(t *testing.T, label string, moves []move, expectMate bool) {
blackCtx, blackCancel := newBrowserCtx(t)
defer blackCancel()

width := envInt("CHROMEDP_VIEWPORT_WIDTH", 1280)
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 2000)
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 393)
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 852)

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

width := envInt("CHROMEDP_VIEWPORT_WIDTH", 1280)
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 2000)
width := envInt("CHROMEDP_VIEWPORT_WIDTH", 393)
height := envInt("CHROMEDP_VIEWPORT_HEIGHT", 852)
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.NoFirstRun,
chromedp.NoDefaultBrowserCheck,
Expand Down