js-in-html-testing
Skill3.3k starsChanged 3 months agoMITView on GitHub
Test JS logic embedded in HTML using two-layer strategy - Python unit tests + Playwright browser integration tests
- Installs packages
Trending
Quiet since September.thin dataabout the whole repository
Who's talking about liaohch3/claude-tap
- sudosubin/agents.nix“agent-skills.github.liaohch3.claude-tap: init at 0.1.145”GitHub · Sep 29, 2026
- chenhg5/cc-connect“[Bug] I am using both cc-connect and claude-tap, but response is missing in claude-tap”GitHub · Jun 6, 2026
- jianshuo/ccglass“feat: surface API errors, non-2xx responses, and retry loops in the dashboard”GitHub · May 24, 2026
- jianshuo/ccglass“feat: harden & expand request-format rendering (OpenAI Responses/Codex edge cases, Gemini)”GitHub · May 24, 2026
The biggest 4 of 4 mentions linking to the repository that our crawl found. Each line is their own headline.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- codex-e2e-testSkill
- demo-videoSkill
- e2e-testSkill
- legibility-checkSkill
- playwright-screen-recordingSkill
- pr-preflightSkill
- push-releaseSkill
- real-e2e-testSkill
- screenshot-validationSkill
- translate-i18nSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 109
Test data must match the viewer's expected JSONL format (including turn, duration_ms, request_id, request.path, etc.)
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JS-in-HTML Two-Layer Testing Strategy
For JavaScript logic embedded in HTML files (e.g., diff navigation in viewer.html), use a two-layer testing approach.
Layer 1: Python Unit Tests (fast algorithm verification)
Replicate core JS algorithms in Python and verify correctness via pytest.
Best for: pure computation logic, state decisions, matching algorithms — anything that doesn't depend on the DOM.
Example: tests/test_diff_matching.py
# Replicate JS findPrevSameModel / findNextSameModel
def find_diff_parent_by_prefix(entries, idx): ...
def find_next_by_prefix(entries, idx): ...
# Replicate JS updateNavButtons state computation
def compute_nav_button_states(entries, cur_idx):
prev_idx = find_diff_parent_by_prefix(entries, cur_idx)
...
return (prev_enabled, next_enabled)Advantages: fast (0.02s), no browser dependency, integrates with existing pytest setup.
Layer 2: Playwright Browser Integration Tests (DOM interaction verification)
Generate HTML with test data embedded, open it in real Chromium via Playwright, and verify DOM state and user interactions.
Best for: button disabled states, overlay show/hide, keyboard events, click navigation, etc.
Example: tests/test_nav_browser.py
Building test HTML
def _build_test_html():
from claude_tap.viewer import VIEWER_SCRIPT_ANCHOR, _read_viewer_template
template = _read_viewer_template()
records = [json.dumps(e) for e in TEST_ENTRIES]
data_js = "const EMBEDDED_TRACE_DATA = [\n" + ",\n".join(records) + "\n];\n"
# Inject data into template
return template.replace(
VIEWER_SCRIPT_ANCHOR,
f"<script>\n{data_js}</script>\n{VIEWER_SCRIPT_ANCHOR}",
1,
)Playwright fixture
@pytest.fixture(scope="module")
def browser_page(html_file):
from playwright.sync_api import sync_playwright
pw = sync_playwright().start()
browser = pw.chromium.launch(headless=True)
page = browser.new_page()
page.goto(f"file://{html_file}")
page.wait_for_selector(".sidebar-item", timeout=5000)
yield page
browser.close()
pw.stop()Verifying DOM state
def _get_nav_state(page):
return page.evaluate("""() => {
const overlay = document.querySelector('.diff-overlay');
if (!overlay) return { overlayExists: false };
return {
overlayExists: true,
prevDisabled: overlay.querySelector('.diff-nav-prev')?.disabled,
nextDisabled: overlay.querySelector('.diff-nav-next')?.disabled,
title: overlay.querySelector('.diff-title')?.textContent,
};
}""")Simulating user interaction
# Click buttons
page.click(".diff-nav-next")
# Keyboard navigation
page.keyboard.press("ArrowRight")
# Call internal JS functions
page.evaluate("selectEntry(2)")
page.evaluate("showDiff()")Notes
- Trace data may contain
</script>text (e.g., when Claude discusses code), which breaks<script>block parsing. Escape it:line.replace("</script>", '</scr" + "ipt>') - Test data must match the viewer's expected JSONL format (including
turn,duration_ms,request_id,request.path, etc.) - Playwright requires
uv pip install playwright
Running
# Fast unit tests
uv run pytest tests/test_diff_matching.py -v
# Browser integration tests
uv run pytest tests/test_nav_browser.py -v
# All (excluding slow e2e)
uv run pytest tests/ --ignore=tests/test_e2e.py -vDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

