Files
orca/config/scripts/mobile-web-app-bundle-test-fixture.mjs
T
OrcaWinandm4air 47cebbf5d2 ci: use ARM unit runners, overlap web builds, and reuse verifier fixtures (#23376)
* test: reuse isolated mobile bundle fixtures for verifier checks

* ci: run PR unit shards on ARM and overlap independent web builds

* docs: record controlled CI overlap and runner measurements

* test: observe WebRTC packets with the host clock

* ci: isolate Windows installer CIM probe from native test load

* docs: record native probe scheduling validation

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
2026-09-27 01:06:54 -07:00

50 lines
1.8 KiB
JavaScript

import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { deserialize, serialize } from 'node:v8'
import { bundleMobileWebApp, buildMobileWebAppBundle } from './build-mobile-web-app-bundle.mjs'
export async function withScratch(run) {
const scratch = await mkdtemp(join(tmpdir(), 'orca-mobile-web-app-test-'))
try {
return await run(scratch)
} finally {
await rm(scratch, { recursive: true, force: true })
}
}
// Snapshots preserve Buffer methods and give each assertion its own mutable copy.
let appBundleSnapshot
let writtenBundleSnapshot
export async function readAppBundle() {
appBundleSnapshot ??= bundleMobileWebApp().then(serialize)
// Deserialized Buffers alias their snapshot, so copy it before exposing them.
return deserialize(Buffer.from(await appBundleSnapshot))
}
export async function readWrittenBundle() {
writtenBundleSnapshot ??= withScratch(async (scratch) => {
const { outDir, ...result } = await buildMobileWebAppBundle({ outDir: join(scratch, 'bundle') })
const html = await readFile(join(outDir, 'index.html'), 'utf8')
const files = await Promise.all(
['manifest.json', ...result.manifest.assets.map((asset) => asset.path)].map(async (file) => ({
file,
bytes: await readFile(join(outDir, file))
}))
)
return serialize({ ...result, html, files })
})
return deserialize(Buffer.from(await writtenBundleSnapshot))
}
export async function copyWrittenBundle(outDir) {
const snapshot = await readWrittenBundle()
for (const { file, bytes } of snapshot.files) {
const destination = join(outDir, file)
await mkdir(dirname(destination), { recursive: true })
await writeFile(destination, bytes)
}
return { ...snapshot, outDir }
}