Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.0 kB · 57 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758// Minimal browser-side CTS driver for headless automation. Mirrors// src/common/runtime/cmdline.ts (the Node driver tools/run_node uses) but// runs a single query given as ?q=<query> in the URL, using the page's own// navigator.gpu instead of a GPUProviderModule, and exposes the result on// `window` instead of printing to a console, since there's no stdout to read// from a headless browser tab.//// Not part of the CTS checkout: copied into cts/src/common/runtime/ by// run-browser.sh before the dev server starts, because the dev server only// compiles and serves .ts files that live under cts/src/.import { DefaultTestFileLoader } from '../internal/file_loader.js';import { Logger } from '../internal/logging/logger.js';import { parseQuery } from '../internal/query/parseQuery.js';import { parseExpectationsForTestQuery } from '../internal/query/query.js';
declare global { interface Window { __ctsDone?: boolean; __ctsResultJSON?: string; __ctsError?: string; }}
(async () => { try { const params = new URLSearchParams(window.location.search); const query = params.get('q'); if (!query) { window.__ctsError = 'missing ?q= query parameter'; return; }
const loader = new DefaultTestFileLoader(); const filterQuery = parseQuery(query); const testcases = await loader.loadCases(filterQuery); const expectations = parseExpectationsForTestQuery([], filterQuery);
const log = new Logger(); let total = 0; for (const testcase of testcases) { const name = testcase.query.toString(); const [rec] = log.record(name); await testcase.run(rec, expectations); total++; }
if (total === 0) { window.__ctsError = `found no tests for query: ${query}`; } else { window.__ctsResultJSON = log.asJSON(2); } } catch (e) { window.__ctsError = (e && (e as Error).stack) || String(e); } finally { window.__ctsDone = true; }})();