Files
orca/config/scripts/mobile-entry-static-closure.test.mjs
T
OrcaWinandOrcaWin 466960a62a test: retain mobile closure semantics without traversal counters (#29803)
* fix: remove redundant chat callback alias to restore lint

* test: retain mobile closure semantics without traversal counters

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-16 12:02:20 -07:00

61 lines
2.1 KiB
JavaScript

import { expect, it } from 'vitest'
import { entryStaticClosure } from './build-mobile-web-app-bundle.mjs'
it('returns every reachable chunk in a fresh set without changing the metadata', () => {
const paths = Array.from({ length: 128 }, (_value, index) => `dist/chunk-${index}.js`)
const metafile = {
outputs: Object.fromEntries(
paths.map((path, index) => [
path,
{
imports:
index === 0
? paths.slice(1).map((child) => ({ kind: 'import-statement', path: child }))
: []
}
])
)
}
const before = structuredClone(metafile)
const reached = entryStaticClosure(metafile, paths[0])
expect(reached).toEqual(new Set(paths))
expect(metafile).toEqual(before)
const fresh = entryStaticClosure(metafile, paths[0])
expect(fresh).not.toBe(reached)
reached.add('mutated-result')
expect(fresh).toEqual(new Set(paths))
})
it('follows static imports through duplicates, cycles and missing chunks without loading dynamic imports', () => {
const metafile = {
outputs: {
entry: {
imports: [
{ kind: 'import-statement', path: 'one' },
{ kind: 'dynamic-import', path: 'deferred' },
{ kind: 'import-statement', path: 'two' },
{ kind: 'import-statement', path: 'one' }
]
},
one: { imports: [{ kind: 'import-statement', path: 'three' }] },
two: {
imports: [
{ kind: 'import-statement', path: 'entry' },
{ kind: 'import-statement', path: 'three' },
{ kind: 'import-statement', path: 'missing' }
]
},
three: { imports: [] },
deferred: { imports: [{ kind: 'import-statement', path: 'deferred-child' }] }
}
}
expect(entryStaticClosure(metafile, 'entry')).toEqual(
new Set(['entry', 'one', 'two', 'three', 'missing'])
)
metafile.outputs.one.imports.push({ kind: 'import-statement', path: 'fresh-😀' })
expect(entryStaticClosure(metafile, 'entry')).toEqual(
new Set(['entry', 'one', 'two', 'three', 'fresh-😀', 'missing'])
)
expect(entryStaticClosure({ outputs: {} }, 'unknown')).toEqual(new Set(['unknown']))
})