openpencil/tools/dev/unit-tests/tests/shards.test.ts
Danila Poyarkov 9b418de13e
refactor: print OpenPencil JSX export as syntax trees (#799)
* refactor(codegen): share syntax-tree code generation between exporters

dom-css printed Tailwind JSX with its own esrap JSX builders and kept TypeScript template helpers under its Storybook export. The OpenPencil JSX exporter needs the same JSX builders, and design-jsx and dom-css may not depend on each other.

@open-pencil/codegen holds both: es for ESTree templates and modules (moved from dom-css) and jsx for JSX elements, attributes, text, and printing, including the literal rules that keep exported strings from being reinterpreted. dom-css no longer depends on acorn and esrap directly.

* refactor(design-jsx): print JSX export as syntax trees

sceneNodeToJSX concatenated strings with hand-written escaping and indentation. It now collects typed props (moved to export/props.ts) and prints them with @open-pencil/codegen's JSX builders. Output is unchanged except for text: special characters print as a string expression instead of entities, and multi-line text keeps its line breaks, which the old line-splitting lost on render.

* docs(codegen): fix package metadata and dependency rules

codegen's repository.directory still named design-jsx, the README mentioned es without showing it, and the design-jsx and dom-css guides still said they depend only on scene-graph.

* test(core): move the JSX export round-trips to the design-jsx test home

Covers tabs in layer names and text, which JSX keeps as written.
2026-10-01 21:22:43 +04:00

95 lines
3.4 KiB
TypeScript

import { expect, test } from 'bun:test'
import { resolveWorkspaceRoot } from '@open-pencil/package-artifacts-tools'
import {
isHeavyUnitTest,
listHeavyUnitTests,
listUnitTests,
pathsForUnitTestGroup,
unitTestGroupNames
} from '../src/shards'
const REPO_ROOT = await resolveWorkspaceRoot(import.meta.dir)
async function discover(pattern: string): Promise<string[]> {
return Array.fromAsync(new Bun.Glob(pattern).scan({ cwd: REPO_ROOT }))
}
test('every app, engine and package-local test belongs to exactly one shard', async () => {
const discovered = [
...(await discover('tests/app/**/*.test.ts')),
...(await discover('tests/integration/**/*.test.ts')),
...(await discover('tests/engine/**/*.test.ts')),
...(await discover('packages/*/tests/**/*.test.ts'))
].filter((file) => !file.startsWith('packages/harness/'))
const paths = pathsForUnitTestGroup('all')
const invalidAssignments = discovered.flatMap((file) => {
const owners = paths.filter((path) => file.startsWith(`${path}/`))
return owners.length === 1 ? [] : [{ file, owners }]
})
expect(discovered.length).toBeGreaterThan(0)
expect(invalidAssignments).toEqual([])
expect((await listUnitTests('all', { includeHeavy: true })).sort()).toEqual(discovered.sort())
})
test('canonical destinations are registered before they hold files', async () => {
const paths = pathsForUnitTestGroup('all')
expect(paths).toContain('tests/app')
expect(paths).toContain('tests/integration')
for (const owner of [
'core',
'scene-graph',
'vue',
'fig',
'kiwi',
'dom-css',
'design-jsx',
'codegen',
'pen',
'cli',
'mcp'
]) {
expect(paths).toContain(`packages/${owner}/tests`)
}
await expect(listUnitTests('all')).resolves.toBeArray()
})
test('quick and explicit heavy tests partition the full engine suite', async () => {
const quick = await listUnitTests('all')
const heavy = await listHeavyUnitTests()
const all = await listUnitTests('all', { includeHeavy: true })
expect(quick.filter((file) => heavy.includes(file))).toEqual([])
expect([...quick, ...heavy].sort()).toEqual(all)
})
test('unit test groups cover all declared shards', () => {
expect(unitTestGroupNames()).toContain('all')
expect(pathsForUnitTestGroup('dom')).toContain('tests/engine/dom-css')
expect(pathsForUnitTestGroup('fig')).toContain('packages/fig/tests')
expect(pathsForUnitTestGroup('all')).toContain('tests/engine/io')
})
test('heavy unit test matcher excludes fixture-heavy tests', () => {
expect(isHeavyUnitTest('tests/engine/io/fig/heavy/fixtures.test.ts')).toBe(true)
expect(isHeavyUnitTest('packages/core/tests/io/formats/fig/roundtrip/glyph-blob.test.ts')).toBe(
true
)
expect(isHeavyUnitTest('tests/engine/dom-css/runtime.test.ts')).toBe(false)
})
test('quick unit test listing excludes heavy tests', async () => {
const quickFiles = await listUnitTests('all')
expect(quickFiles).toContain('tests/engine/dom-css/runtime.test.ts')
expect(quickFiles).not.toContain('tests/engine/io/fig/heavy/fixtures.test.ts')
expect(quickFiles).not.toContain('tests/engine/io/fig/roundtrip/glyph-blob.test.ts')
})
test('heavy unit test listing contains only heavy tests', async () => {
const heavyFiles = await listHeavyUnitTests()
expect(heavyFiles).toContain('tests/engine/io/fig/heavy/fixtures.test.ts')
expect(heavyFiles.every(isHeavyUnitTest)).toBe(true)
})