test: narrow emit return type in componentResources test
All checks were successful
Engine CI / build-and-test (docker) (push) Successful in 3m23s

This commit is contained in:
Meta Vens 2026-12-05 01:48:57 +01:00
commit 6f79f4fed9

View file

@ -28,6 +28,19 @@ function sha256Hex8(content: string): string {
return createHash("sha256").update(content).digest("hex").slice(0, 8)
}
async function drainEmitted(
emitted: Promise<FilePath[]> | AsyncGenerator<FilePath> | null,
): Promise<void> {
if (!emitted) return
if (Symbol.asyncIterator in emitted) {
for await (const _ of emitted) {
// exhaust async generator
}
} else {
await emitted
}
}
function makeTestCtx(outputDir: string, emitters: QuartzEmitterPluginInstance[]): BuildCtx {
const cfg: QuartzConfig = {
configuration: {
@ -231,9 +244,7 @@ describe("asset cache-busting hashes", () => {
const plugin = loaded.ComponentResources()
const ctx = makeTestCtx(outDir, [makeDummyComponentEmitter(opts), plugin])
const resources: StaticResources = { css: [], js: [], additionalHead: [] }
for await (const _ of plugin.emit(ctx, [], resources)) {
// exhaust async generator
}
await drainEmitted(plugin.emit(ctx, [], resources))
const [cssFile, preFile, postFile] = await Promise.all([
fs.readFile(path.join(outDir, "index.css"), "utf8"),
@ -320,16 +331,12 @@ describe("asset cache-busting hashes", () => {
const ctx = makeTestCtx(outDir, [plugin])
const initialResources: StaticResources = { css: [], js: [], additionalHead: [] }
for await (const _ of plugin.emit(ctx, [], initialResources)) {
// exhaust async generator
}
await drainEmitted(plugin.emit(ctx, [], initialResources))
const freshResources: StaticResources = { css: [], js: [], additionalHead: [] }
const partial = plugin.partialEmit!(ctx, [], freshResources, [])
assert.ok(partial && Symbol.asyncIterator in partial)
for await (const _ of partial) {
// exhaust async generator
}
await drainEmitted(partial)
assert.deepEqual(freshResources.assetHashes, initialResources.assetHashes)
})