Files
orca/config/scripts/orcad-mobile-web-bundle.test.mjs
T
Neil 73930bedee Prepare server template assembly alongside qualification (#31422)
* Prepare template assembly during qualification and cache Intel downloads

* Limit early template qualification polling to fifteen seconds

* Verify Windows retains its download cache policy

* Drop Intel store restoration after measuring its overhead
2026-10-21 00:06:40 -07:00

78 lines
3.1 KiB
JavaScript

import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { parse } from 'yaml'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { ORCAD_MOBILE_WEB_MANIFEST } from '../../src/shared/orcad-artifacts.ts'
import { writeMobileWebBundleFixtureTree } from './mobile-web-bundle-fixture-tree.mjs'
import {
readOrcadMobileWebAssetFilenames,
stageOrcadMobileWebBundle
} from './orcad-mobile-web-bundle.mjs'
let scratch
let bundleDir
let outputDir
beforeEach(() => {
scratch = mkdtempSync(join(tmpdir(), 'orcad-mobile-web-'))
bundleDir = join(scratch, 'mobile-web')
outputDir = join(scratch, 'orcad')
vi.spyOn(console, 'log').mockImplementation(() => {})
})
afterEach(() => {
vi.restoreAllMocks()
vi.unstubAllEnvs()
rmSync(scratch, { recursive: true, force: true })
})
it('stages the manifest and every asset it lists, byte for byte', async () => {
const { manifest } = await writeMobileWebBundleFixtureTree({ outDir: bundleDir })
stageOrcadMobileWebBundle(outputDir, bundleDir)
const staged = readOrcadMobileWebAssetFilenames(outputDir)
expect(staged).toHaveLength(manifest.assets.length)
for (const asset of manifest.assets) {
expect(readFileSync(join(outputDir, 'out', 'mobile-web', asset.path))).toEqual(
readFileSync(join(bundleDir, asset.path))
)
}
expect(readFileSync(join(outputDir, ORCAD_MOBILE_WEB_MANIFEST))).toEqual(
readFileSync(join(bundleDir, 'manifest.json'))
)
})
it('stages a dark page into a dark orcad, and refuses it in any other', async () => {
vi.stubEnv('ORCA_SIDEBAR_INPUTS', 'main')
await writeMobileWebBundleFixtureTree({ outDir: bundleDir })
stageOrcadMobileWebBundle(outputDir, bundleDir)
expect(existsSync(join(outputDir, ORCAD_MOBILE_WEB_MANIFEST))).toBe(true)
vi.unstubAllEnvs()
rmSync(outputDir, { recursive: true, force: true })
expect(() => stageOrcadMobileWebBundle(outputDir, bundleDir)).toThrow('ORCA_SIDEBAR_INPUTS=main')
expect(existsSync(join(outputDir, ORCAD_MOBILE_WEB_MANIFEST))).toBe(false)
})
it('fails the build when the page was never built', () => {
expect(() => stageOrcadMobileWebBundle(outputDir, bundleDir)).toThrow('pnpm build:mobile-web')
expect(existsSync(join(outputDir, ORCAD_MOBILE_WEB_MANIFEST))).toBe(false)
})
it('ships the page the qualification lanes tested in the release template', () => {
const workflow = parse(
readFileSync(new URL('../../.github/workflows/node-server-tests.yml', import.meta.url), 'utf8')
)
const template = workflow.jobs.desktop_template
const wait = template.steps.findIndex(
(step) => step.name === 'Wait for every template qualification lane'
)
expect(template.steps[wait].with.script).toContain('mobile_web_bundle: 1')
expect(wait).toBeLessThan(
template.steps.findIndex((step) => step.with?.name === 'orcad-mobile-web-bundle')
)
expect(template.steps.some((step) => step.with?.name === 'orcad-mobile-web-bundle')).toBe(true)
expect(template.steps.some((step) => step.uses?.includes('build-mobile-web-bundle'))).toBe(false)
})