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

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: Types, unit tests, build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.11
- run: bun install --frozen-lockfile
- run: bun run check
- run: bun run test
- run: bun run build

browser:
name: ${{ matrix.engine }} ${{ matrix.backend }}
# macOS: the suites' pixel and geometry checks are written against its
# fonts, and Playwright's WebKit there is Apple's port (Metal,
# CoreText, WebGPU), the closest to iOS Safari. On Linux, other
# monospace metrics break wrapping and bidi checks, and its WebKit
# build has no WebGPU.
runs-on: macos-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
engine: [chromium, webkit]
backend: [webgl2, webgpu]
env:
# Lets Chromium fall back to SwiftShader if the runner has no GPU.
CHROME_ARGS: --enable-unsafe-swiftshader
steps:
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.11
- uses: actions/setup-node@v5
with:
node-version: 24
- run: bun install --frozen-lockfile
- run: bunx playwright install ${{ matrix.engine }}
- run: bun run demo:build
- name: Browser suites
run: |
if [ "${{ matrix.engine }}" = webkit ]; then
suites="webkit"
else
suites="cursor input selection mouse keyboard layout bidi context sticky ligatures"
[ "${{ matrix.backend }}" = webgl2 ] && suites="$suites input:--input=textarea"
fi
failed=""
for s in $suites; do
name=${s%%:*}
extra=$([ "$name" != "$s" ] && echo "${s#*:}" || true)
echo "::group::$s"
node test/browser/$name.mjs --backend=${{ matrix.backend }} $extra || failed="$failed $s"
echo "::endgroup::"
done
if [ -n "$failed" ]; then
echo "::error::Failed:$failed"
exit 1
fi
8 changes: 7 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bun install
bun run check # TypeScript (tsc --noEmit)
bun run test # unit tests (test/*.test.ts)
bun run test:browser # browser suites on both backends, with real touch/mouse/key/IME events
bun run test:webkit # the WebKit (iOS) suite alone, both backends
bun run demo # demo at http://127.0.0.1:5173 (index.html = canvas-view, cm.html = CodeMirror)
bun run demo:lan # same on 0.0.0.0:5199, for phones on the LAN
bun run build # dist/
Expand All @@ -45,7 +46,12 @@ node bench/compare.mjs --cpu=1,4,6 # vs CodeMirror 6, Ace and Monac

Browser tests and benchmarks launch Chromium through Puppeteer. Pass
`--browser=<path>` or set `CHROME_PATH` to choose the binary (the default
is Playwright's cached "Chrome for Testing" on macOS). Benchmarks emulate
is the "Chrome for Testing" of the pinned `playwright` devDependency:
`bunx playwright install chromium webkit` once), and `CHROME_ARGS` to add
flags. `test/browser/webkit.mjs` runs in Playwright's WebKit instead, the
closest headless stand-in for iOS. CI (`.github/workflows/ci.yml`) runs
every browser suite on macOS, on both backends: their pixel and geometry
checks assume its fonts, and its WebKit is Apple's port. Benchmarks emulate
a 412×860 phone at DPR 2.625 with touch and throttle the CPU through CDP.
`--device` variants drive a USB-connected phone's WebView over DevTools
(see the comment at the top of each script).
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ bun install
bun run demo # http://127.0.0.1:5173
bun run check # TypeScript
bun run test # unit tests
bun run test:browser # browser tests, both backends
bun run test:browser # browser tests, both backends, Chromium and WebKit
bun run bench # fling benchmark vs CodeMirror 6
```

The demo has a ⚙ panel for every option and loads CodeMirror's search,
autocomplete, lint and folding. `cm.html`, `ace.html` and `monaco.html`
show the same file in the other editors. Browser tests and benchmarks
launch Chromium through Puppeteer: pass `--browser=<path>` or set
`CHROME_PATH`.
launch Chromium through Puppeteer (`--browser=<path>` or `CHROME_PATH`
to choose it); the WebKit suite stands in for iOS Safari. Install the
browsers once with `bunx playwright install chromium webkit`.

## Contributing

Expand Down
12 changes: 8 additions & 4 deletions bench/harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {chromium} from "playwright"

const types = {".html": "text/html", ".js": "text/javascript", ".css": "text/css"}

Expand Down Expand Up @@ -34,14 +34,18 @@ export async function serveDemo(port = 0) {
return {url: `http://localhost:${server.address().port}`, close: () => server.close()}
}

export const defaultBrowser = join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
/// Playwright's Chrome for Testing, pinned by the playwright devDependency
/// (`bunx playwright install chromium`).
export const defaultBrowser = chromium.executablePath()

/// `CHROME_ARGS` adds flags, e.g. CI's software GPU (SwiftShader) on a
/// machine without one.
export function launch(args = {}) {
return puppeteer.launch({
executablePath: args.browser ?? process.env.CHROME_PATH ?? defaultBrowser,
headless: args.headful ? false : true,
args: ["--enable-unsafe-webgpu", "--ignore-gpu-blocklist", "--no-first-run"]
args: ["--enable-unsafe-webgpu", "--ignore-gpu-blocklist", "--no-first-run",
...(process.env.CHROME_ARGS ?? "").split(/\s+/).filter(Boolean)]
})
}

Expand Down
9 changes: 8 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"build": "bun build ./src/index.ts --outdir ./dist --target browser --format esm --packages external && tsc -p tsconfig.build.json",
"check": "tsc -p tsconfig.json --noEmit",
"test": "bun test test/*.test.ts",
"test:browser": "vite build && node test/browser/cursor.mjs && node test/browser/cursor.mjs --backend=webgpu && node test/browser/input.mjs && node test/browser/input.mjs --input=textarea && node test/browser/input.mjs --backend=webgpu && node test/browser/selection.mjs && node test/browser/selection.mjs --backend=webgpu && node test/browser/mouse.mjs && node test/browser/mouse.mjs --backend=webgpu && node test/browser/keyboard.mjs && node test/browser/keyboard.mjs --backend=webgpu && node test/browser/layout.mjs && node test/browser/layout.mjs --backend=webgpu && node test/browser/bidi.mjs && node test/browser/bidi.mjs --backend=webgpu && node test/browser/context.mjs && node test/browser/context.mjs --backend=webgpu && node test/browser/sticky.mjs && node test/browser/sticky.mjs --backend=webgpu && node test/browser/ligatures.mjs && node test/browser/ligatures.mjs --backend=webgpu",
"test:browser": "vite build && node test/browser/cursor.mjs && node test/browser/cursor.mjs --backend=webgpu && node test/browser/input.mjs && node test/browser/input.mjs --input=textarea && node test/browser/input.mjs --backend=webgpu && node test/browser/selection.mjs && node test/browser/selection.mjs --backend=webgpu && node test/browser/mouse.mjs && node test/browser/mouse.mjs --backend=webgpu && node test/browser/keyboard.mjs && node test/browser/keyboard.mjs --backend=webgpu && node test/browser/layout.mjs && node test/browser/layout.mjs --backend=webgpu && node test/browser/bidi.mjs && node test/browser/bidi.mjs --backend=webgpu && node test/browser/context.mjs && node test/browser/context.mjs --backend=webgpu && node test/browser/sticky.mjs && node test/browser/sticky.mjs --backend=webgpu && node test/browser/ligatures.mjs && node test/browser/ligatures.mjs --backend=webgpu && bun run test:webkit",
"test:webkit": "node test/browser/webkit.mjs && node test/browser/webkit.mjs --backend=webgpu",
"demo": "vite --host 127.0.0.1",
"demo:lan": "vite --host 0.0.0.0 --port 5199",
"demo:build": "vite build",
Expand All @@ -74,6 +75,7 @@
"@webgpu/types": "^0.1.74",
"ace-builds": "^1.45.0",
"monaco-editor": "^0.57.0",
"playwright": "1.60.0",
"puppeteer-core": "^25.14.0",
"typescript": "^7.0.2",
"vite": "^8.3.4"
Expand Down
7 changes: 2 additions & 5 deletions test/browser/bidi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {launch} from "../../bench/harness.mjs"
import {bidiFixtures, compareWithBrowser} from "./bidifixtures.mjs"

const args = Object.fromEntries(process.argv.slice(2).map(a => {
let [k, v] = a.replace(/^--/, "").split("=")
return [k, v ?? "true"]
}))
const backend = args.backend ?? "webgl2"
const browserPath = args.browser ?? join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
const root = resolve(import.meta.dirname, "../../demo-dist")

const server = createServer(async (req, res) => {
Expand All @@ -36,7 +33,7 @@ const server = createServer(async (req, res) => {
}
}).listen(0)
const port = server.address().port
const browser = await puppeteer.launch({executablePath: browserPath, headless: true, args: ["--enable-unsafe-webgpu"]})
const browser = await launch(args)
const sleep = ms => new Promise(r => setTimeout(r, ms))

let failures = 0, passes = 0
Expand Down
5 changes: 3 additions & 2 deletions test/browser/bidifixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export async function compareWithBrowser(lines, mode) {
let theirs = units.map((u, i) => {
range.setStart(node, u.from)
range.setEnd(node, u.to)
let rects = range.getClientRects()
return {i, x: rects.length ? rects[0].left : -1}
// WebKit adds an empty rect where a unit meets a run of the other direction.
let rect = [...range.getClientRects()].find(r => r.width > 0)
return {i, x: rect ? rect.left : -1}
})
// Whitespace order is ambiguous at run edges in the DOM's rects.
let keep = u => !/^\s+$/.test(text.slice(units[u.i].from, units[u.i].to))
Expand Down
6 changes: 2 additions & 4 deletions test/browser/context.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {launch} from "../../bench/harness.mjs"

const args = Object.fromEntries(process.argv.slice(2).map(a => {
let [k, v] = a.replace(/^--/, "").split("=")
return [k, v ?? "true"]
}))
const backend = args.backend ?? "webgl2"
const browserPath = args.browser ?? join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
const root = resolve(import.meta.dirname, "../../demo-dist")

const server = createServer(async (req, res) => {
Expand All @@ -41,7 +39,7 @@ const server = createServer(async (req, res) => {
const device = args.device && (args.device == "true" ? "http://localhost:9333" : args.device)
const base = device ? "http://localhost:5173" : `http://localhost:${server.address().port}`
const browser = device ? await puppeteer.connect({browserURL: device, defaultViewport: null})
: await puppeteer.launch({executablePath: browserPath, headless: true, args: ["--enable-unsafe-webgpu"]})
: await launch(args)
const sleep = ms => new Promise(r => setTimeout(r, ms))

let failures = 0, passes = 0
Expand Down
7 changes: 2 additions & 5 deletions test/browser/cursor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {launch} from "../../bench/harness.mjs"

const args = Object.fromEntries(process.argv.slice(2).map(a => {
let [k, v] = a.replace(/^--/, "").split("=")
return [k, v ?? "true"]
}))
const backend = args.backend ?? "webgl2"
const browserPath = args.browser ?? join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
const root = resolve(import.meta.dirname, "../../demo-dist")

const server = createServer(async (req, res) => {
Expand All @@ -32,7 +29,7 @@ const server = createServer(async (req, res) => {
}
}).listen(0)
const port = server.address().port
const browser = await puppeteer.launch({executablePath: browserPath, headless: true, args: ["--enable-unsafe-webgpu"]})
const browser = await launch(args)
const sleep = ms => new Promise(r => setTimeout(r, ms))

let failures = 0, passes = 0
Expand Down
4 changes: 3 additions & 1 deletion test/browser/input.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ await page.keyboard.up(mod)
check("Mod-z undoes typing", await line3() == "undo", JSON.stringify(await line3()))
await page.keyboard.down(mod)
await page.keyboard.down("Shift")
await page.keyboard.press("z")
// "Z", as browsers report it: with Control held, Puppeteer's "z" stays
// lowercase, which CodeMirror reads as Ctrl-z (undo) on Linux.
await page.keyboard.press("Z")
await page.keyboard.up("Shift")
await page.keyboard.up(mod)
check("Mod-Shift-z redoes", await line3() == "undo me", JSON.stringify(await line3()))
Expand Down
7 changes: 2 additions & 5 deletions test/browser/layout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {launch} from "../../bench/harness.mjs"

const args = Object.fromEntries(process.argv.slice(2).map(a => {
let [k, v] = a.replace(/^--/, "").split("=")
return [k, v ?? "true"]
}))
const backend = args.backend ?? "webgl2"
const browserPath = args.browser ?? join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
const root = resolve(import.meta.dirname, "../../demo-dist")

const server = createServer(async (req, res) => {
Expand All @@ -34,7 +31,7 @@ const server = createServer(async (req, res) => {
}
}).listen(0)
const port = server.address().port
const browser = await puppeteer.launch({executablePath: browserPath, headless: true, args: ["--enable-unsafe-webgpu"]})
const browser = await launch(args)
const sleep = ms => new Promise(r => setTimeout(r, ms))

let failures = 0, passes = 0
Expand Down
7 changes: 2 additions & 5 deletions test/browser/ligatures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import {createServer} from "node:http"
import {readFile} from "node:fs/promises"
import {extname, join, resolve} from "node:path"
import {homedir} from "node:os"
import puppeteer from "puppeteer-core"
import {launch} from "../../bench/harness.mjs"

const args = Object.fromEntries(process.argv.slice(2).map(a => {
let [k, v] = a.replace(/^--/, "").split("=")
return [k, v ?? "true"]
}))
const backend = args.backend ?? "webgl2"
const browserPath = args.browser ?? process.env.CHROME_PATH ?? join(homedir(),
"Library/Caches/ms-playwright/chromium-1223/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing")
const root = resolve(import.meta.dirname, "../../demo-dist")

const server = createServer(async (req, res) => {
Expand All @@ -34,7 +31,7 @@ const server = createServer(async (req, res) => {
}
}).listen(0)
const port = server.address().port
const browser = await puppeteer.launch({executablePath: browserPath, headless: true, args: ["--enable-unsafe-webgpu"]})
const browser = await launch(args)
const sleep = ms => new Promise(r => setTimeout(r, ms))

let failures = 0, passes = 0
Expand Down
Loading
Loading