v1.1.0: pooled runtime, 959 tests, production hardening (0 squash)

This commit is contained in:
John Dvorak
2025-08-15 10:00:00 -07:00
commit 92deb689cd
321 changed files with 79170 additions and 0 deletions
@@ -0,0 +1,52 @@
import { performance } from 'node:perf_hooks'
import { chromium } from 'playwright'
import { imhotep } from 'imhotep'
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
const tmpdir2 = mkdtempSync(join(tmpdir(), 'imhotep-cache-hit-'))
const html = `
<!DOCTYPE html>
<html><body>
<div id="container">
${Array.from({length: 50}, (_, i) => `<div class="item" data-testid="item-${i}" style="position:absolute;left:${(i % 10) * 60}px;top:${Math.floor(i / 10) * 60}px;width:50px;height:50px;background:#ccc;">${i}</div>
`).join('')}
</div>
</body></html>
`
writeFileSync(join(tmpdir2, 'page.html'), html)
const browser = await chromium.launch()
const page = await browser.newPage()
await page.goto(`file:${join(tmpdir2, 'page.html')}`)
const selectors = Array.from({length: 50}, (_, i) => `[data-testid="item-${i}"]`)
// Warmup: run once to populate cache
const ui1 = await imhotep(page)
for (const sel of selectors) {
ui1.expect(sel).to.be.leftOf('[data-testid="item-0"]')
}
await ui1.checkAll()
console.log('=== Cache Hit Performance ===\n')
for (const count of [1, 5, 10, 25, 50]) {
const ui = await imhotep(page)
for (let i = 0; i < count; i++) {
ui.expect(selectors[i]).to.be.leftOf('[data-testid="item-0"]')
}
const times = []
for (let run = 0; run < 10; run++) {
const start = performance.now()
await ui.checkAll()
times.push(performance.now() - start)
}
const mean = times.reduce((a,b) => a+b, 0) / times.length
console.log(`${count} selectors (cache hit): ${mean.toFixed(2)}ms (avg of 10 runs)`)
}
await browser.close()
rmSync(tmpdir2, { recursive: true, force: true })