diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/webgpu/tests/cts/checkout/src/common/internal/file_loader.ts | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/common/internal/file_loader.ts | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/common/internal/file_loader.ts b/dom/webgpu/tests/cts/checkout/src/common/internal/file_loader.ts new file mode 100644 index 0000000000..922d6a09dd --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/common/internal/file_loader.ts @@ -0,0 +1,95 @@ +import { IterableTestGroup } from '../internal/test_group.js'; +import { assert } from '../util/util.js'; + +import { parseQuery } from './query/parseQuery.js'; +import { TestQuery } from './query/query.js'; +import { TestSuiteListing } from './test_suite_listing.js'; +import { loadTreeForQuery, TestTree, TestTreeLeaf } from './tree.js'; + +// A listing file, e.g. either of: +// - `src/webgpu/listing.ts` (which is dynamically computed, has a Promise<TestSuiteListing>) +// - `out/webgpu/listing.js` (which is pre-baked, has a TestSuiteListing) +interface ListingFile { + listing: Promise<TestSuiteListing> | TestSuiteListing; +} + +// A .spec.ts file, as imported. +export interface SpecFile { + readonly description: string; + readonly g: IterableTestGroup; +} + +export interface ImportInfo { + url: string; +} + +interface TestFileLoaderEventMap { + import: MessageEvent<ImportInfo>; + finish: MessageEvent<void>; +} + +export interface TestFileLoader extends EventTarget { + addEventListener<K extends keyof TestFileLoaderEventMap>( + type: K, + listener: (this: TestFileLoader, ev: TestFileLoaderEventMap[K]) => void, + options?: boolean | AddEventListenerOptions + ): void; + addEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions + ): void; + removeEventListener<K extends keyof TestFileLoaderEventMap>( + type: K, + listener: (this: TestFileLoader, ev: TestFileLoaderEventMap[K]) => void, + options?: boolean | EventListenerOptions + ): void; + removeEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions + ): void; +} + +// Base class for DefaultTestFileLoader and FakeTestFileLoader. +export abstract class TestFileLoader extends EventTarget { + abstract listing(suite: string): Promise<TestSuiteListing>; + protected abstract import(path: string): Promise<SpecFile>; + + importSpecFile(suite: string, path: string[]): Promise<SpecFile> { + const url = `${suite}/${path.join('/')}.spec.js`; + this.dispatchEvent( + new MessageEvent<ImportInfo>('import', { data: { url } }) + ); + return this.import(url); + } + + async loadTree(query: TestQuery, subqueriesToExpand: string[] = []): Promise<TestTree> { + const tree = await loadTreeForQuery( + this, + query, + subqueriesToExpand.map(s => { + const q = parseQuery(s); + assert(q.level >= 2, () => `subqueriesToExpand entries should not be multi-file:\n ${q}`); + return q; + }) + ); + this.dispatchEvent(new MessageEvent<void>('finish')); + return tree; + } + + async loadCases(query: TestQuery): Promise<IterableIterator<TestTreeLeaf>> { + const tree = await this.loadTree(query); + return tree.iterateLeaves(); + } +} + +export class DefaultTestFileLoader extends TestFileLoader { + async listing(suite: string): Promise<TestSuiteListing> { + return ((await import(`../../${suite}/listing.js`)) as ListingFile).listing; + } + + import(path: string): Promise<SpecFile> { + return import(`../../${path}`); + } +} |