Experimental: Add playwright and test to find broken sketches (console errors)#1279
Experimental: Add playwright and test to find broken sketches (console errors)#1279nbogie wants to merge 9 commits intoprocessing:2.0from
Conversation
npm init playwright@latest answers to questions: ts or js? ts dir: "tests/" CI? yes Install browsers? yes
…e.g. from sketches)
|
Just for fun, here are some detected page errors that might be interesting, from a first full run against all reference pages on localhost website (2.0 branch) after a fairly recent custom:dev. I took out all the ones where jumpToLinks was complaining of duplicate keys, but there are still in here going to be a lot of issues with microphone, camera, autoplay non-interaction. Nice that it already catches some seemingly legit errors. Here's a sampling:
Also, I didn't really run this long test against production, just against local. Afterwards, I changed the urls in the result data to point at prodn (beta) to make it much easier for the curious to click on the links! |
unrelated, but perhaps informative
This draft PR is an experimental proof-of-concept.
What's it for?
To find broken example sketches in reference pages we can look for errors in the console as we go through each page.
This PR adds playright as a dependency (browser automation) and a playwright test to automatically load the reference pages, scroll through them to trigger loading of their content (including their sketches), and monitor the console for errors. It reports which URLs had errors in the console, and what the errors were.
It is a VERY rough WIP
running the test
To run all tests, headed:
npx playwright test --project=chromiumThe following two headless versions are not working correctly with webgl yet (Error creating webgl context):
run all tests, headless
npx playwright test --project=chromiumor with UI test runner
npx playwright test --project=chromium --uimore discussion
early results:
Various todos listed at the top of the prototype test.
This should not be one test but one per reference page, so that we can see progress as we go, and so we can use the reporting tools to filter data, etc.
The list of url paths to check should probably come from astro build's list of static routes. or perhaps be generated from /docs/reference/data.json.
There'll be a bunch of false positives - those sketches requiring camera, mic access. That's fine, this may be a quick way to list them.
Doesn't yet correctly report 404s.
If you start it in vscode from the playwright extension test runner, you'll get the camera access popup in vscode. the test runner won't block on this yet when the first(?) relevant test is encountered. Same for mic and other resources, I guess?
The scrolling is janky - was a quick stackoverflow hack. to be improved.
It's intentionally a little slow.
Playwright has a frames api so we ought to be able to detect the iframes and only wait until they're all loaded + some short grace period.
That grace period will have to be longer for those sketches that need to do shader compilation, or download a big resource like ML weights. We can't tell which those are from URL path. Perhaps we could tag example with meta-data.
Running against production: recommend we don't, yet. even at 1 page per 2 seconds, each page is very large and has a lot of requests. Further, I think the browser's prefetching will amplify that a LOT. Besides spamming the server being bad manners, Cloudflare might block your ip.
The github actions workflow is the default one playwright generated - I haven't looked at it except to disable it. It's a quick way to accidentally burn CI minutes, if not well configured.
This test eventually will also naturally catch and report basic 404s where a requested reference page is not found/served at expected URL. We can't tell if it's been removed/renamed or our config has a bad url.
(Playwright could also eventually be used to recursively crawl and check for bad links in all pages (though if it's all static content, wget could work, too)).
Some discussion on discord here:
https://discord.com/channels/836700474425475088/1483526487561867499