2026-07-04 10:34:24 +00:00
|
|
|
import { expect, setDefaultTimeout, test } from 'bun:test'
|
|
|
|
|
import { mkdtemp } from 'node:fs/promises'
|
|
|
|
|
import { tmpdir } from 'node:os'
|
|
|
|
|
import { join } from 'node:path'
|
|
|
|
|
|
2026-07-28 07:12:41 +00:00
|
|
|
import { unzipSync } from 'fflate'
|
|
|
|
|
|
2026-07-04 10:34:24 +00:00
|
|
|
import { BUILTIN_IO_FORMATS, IORegistry } from '@open-pencil/core/io'
|
|
|
|
|
|
|
|
|
|
import { runOpenPencilCLI } from '#tests/helpers/cli'
|
|
|
|
|
import { createRect, firstPageId, makeSceneGraph } from '#tests/helpers/scene'
|
|
|
|
|
|
|
|
|
|
setDefaultTimeout(30_000)
|
|
|
|
|
|
|
|
|
|
const io = new IORegistry(BUILTIN_IO_FORMATS)
|
|
|
|
|
|
|
|
|
|
async function createFigFixture() {
|
|
|
|
|
const dir = await mkdtemp(join(tmpdir(), 'open-pencil-export-cli-'))
|
|
|
|
|
const figPath = join(dir, 'card.fig')
|
|
|
|
|
const graph = makeSceneGraph('Export Page')
|
2026-07-28 07:12:41 +00:00
|
|
|
const firstFrame = graph.createNode('FRAME', firstPageId(graph), {
|
|
|
|
|
name: 'First slide',
|
|
|
|
|
width: 1280,
|
|
|
|
|
height: 720
|
|
|
|
|
})
|
|
|
|
|
const rect = createRect(graph, firstFrame.id, {
|
2026-07-04 10:34:24 +00:00
|
|
|
name: 'Export Card',
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 160,
|
|
|
|
|
height: 80
|
|
|
|
|
})
|
|
|
|
|
rect.layoutMode = 'HORIZONTAL'
|
|
|
|
|
rect.itemSpacing = 8
|
|
|
|
|
rect.paddingLeft = 16
|
|
|
|
|
rect.paddingRight = 16
|
|
|
|
|
rect.paddingTop = 16
|
|
|
|
|
rect.paddingBottom = 16
|
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites
Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.
@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.
* test: fix the type errors the test suites were hiding
Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.
Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.
No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.
* docs: record what typechecking the tests established
Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.
The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.
* fix: align @types/bun and keep node types resolvable when extended
The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.
* fix: fail the test typecheck when the compiler itself fails
The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.
Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.
* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00
|
|
|
rect.fills = [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, opacity: 1, visible: true }]
|
2026-07-04 10:34:24 +00:00
|
|
|
|
2026-07-22 11:56:58 +00:00
|
|
|
const secondPage = graph.addPage('Second Page')
|
2026-07-28 07:12:41 +00:00
|
|
|
const secondFrame = graph.createNode('FRAME', secondPage.id, {
|
|
|
|
|
name: 'Second slide',
|
|
|
|
|
width: 1280,
|
|
|
|
|
height: 720
|
|
|
|
|
})
|
|
|
|
|
createRect(graph, secondFrame.id, {
|
2026-07-22 11:56:58 +00:00
|
|
|
name: 'Second Card',
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 120,
|
|
|
|
|
height: 60
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-04 10:34:24 +00:00
|
|
|
const result = await io.writeDocument('fig', graph)
|
|
|
|
|
await Bun.write(figPath, result.data as Uint8Array)
|
|
|
|
|
return { dir, figPath }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-22 11:56:58 +00:00
|
|
|
test('FIG export preserves the whole document by default', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'whole.fig')
|
|
|
|
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'fig',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
expect(stdout).toContain('Target: whole document')
|
|
|
|
|
|
|
|
|
|
const { graph } = await io.readDocument({
|
|
|
|
|
name: output,
|
|
|
|
|
data: new Uint8Array(await Bun.file(output).arrayBuffer())
|
|
|
|
|
})
|
|
|
|
|
expect(graph.getPages()).toHaveLength(3)
|
|
|
|
|
expect(graph.getPages().map((page) => page.name)).toContain('Second Page')
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-28 07:12:41 +00:00
|
|
|
test('PPTX export includes slides from every page by default', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'whole.pptx')
|
|
|
|
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'pptx',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
expect(stdout).toContain('Target: whole document')
|
|
|
|
|
|
|
|
|
|
const files = unzipSync(new Uint8Array(await Bun.file(output).arrayBuffer()))
|
|
|
|
|
expect(files['ppt/slides/slide1.xml']).toBeDefined()
|
|
|
|
|
expect(files['ppt/slides/slide2.xml']).toBeDefined()
|
|
|
|
|
expect(files['ppt/slides/slide3.xml']).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-22 11:56:58 +00:00
|
|
|
test('FIG export requires an explicit page for a partial archive', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'page.fig')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'fig',
|
|
|
|
|
'--page',
|
|
|
|
|
'Second Page',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const { graph } = await io.readDocument({
|
|
|
|
|
name: output,
|
|
|
|
|
data: new Uint8Array(await Bun.file(output).arrayBuffer())
|
|
|
|
|
})
|
|
|
|
|
expect(graph.getPages().map((page) => page.name)).toEqual(['Second Page'])
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-04 10:34:24 +00:00
|
|
|
test('export CLI writes HTML with inline styles by default', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card.html')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'html',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const html = await Bun.file(output).text()
|
|
|
|
|
expect(html).toContain('data-open-pencil-node-id')
|
|
|
|
|
expect(html).toContain('style=')
|
|
|
|
|
expect(html).toContain('display: flex')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('export CLI can write HTML styles as Tailwind classes', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card-tailwind.html')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'html',
|
2026-07-04 11:54:58 +00:00
|
|
|
'--css',
|
2026-07-04 10:34:24 +00:00
|
|
|
'tailwind',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const html = await Bun.file(output).text()
|
|
|
|
|
expect(html).toContain('data-open-pencil-node-id')
|
|
|
|
|
expect(html).toContain('class="')
|
|
|
|
|
expect(html).toContain('flex')
|
|
|
|
|
expect(html).not.toContain('style=')
|
|
|
|
|
})
|
2026-07-04 11:54:58 +00:00
|
|
|
|
refactor!: generate Tailwind JSX through dom-css (#763)
* refactor!: generate Tailwind JSX through dom-css
Core kept its own SceneGraph → Tailwind mapper next to the one dom-css
uses for Tailwind HTML, and the two drifted: HTML export turned grid
frames into flex columns and dropped rotation, inner shadows, blur, and
flex grow, while Tailwind JSX had them.
Tailwind JSX is now printed by dom-css from the same CSS projection as
HTML export, with esrap building the JSX and string literals carrying
text or attributes that JSX would otherwise reinterpret. The projection
gains grid layout and placement, rotation, every shadow, layer and
background blur, flex grow, right-to-left direction, and sections, and
writes opaque colors as hex so Tailwind can match its palette.
BREAKING CHANGE: `sceneNodeToJSX` and `selectionToJSX` in
`@open-pencil/core` no longer accept a format, and `JSXFormat` and
`JSXExportOptions` are removed. Use `sceneNodesToTailwindJSX` from
`@open-pencil/dom-css` or `@open-pencil/dom-css/browser`.
* fix(dom-css): keep backslashes and line breaks in Tailwind JSX attributes
JSX attribute strings keep backslashes literally, but the printer
escapes backslashes and line breaks in string literals, so a layer
named `a\b` came back as `a\\b`. Such values are now written as
expression containers, like values containing quotes or `&`.
2026-09-26 06:50:28 +00:00
|
|
|
test('export CLI writes Tailwind JSX for a page', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card.jsx')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'jsx',
|
|
|
|
|
'--style',
|
|
|
|
|
'tailwind',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
const jsx = await Bun.file(output).text()
|
|
|
|
|
expect(jsx).toStartWith('<div data-name="First slide" className="')
|
|
|
|
|
expect(jsx).toContain('<div data-name="Export Card" className="flex p-4 gap-2')
|
|
|
|
|
expect(jsx).not.toContain('Second Card')
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-04 11:54:58 +00:00
|
|
|
test('export CLI can write standalone HTML', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card-standalone.html')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'html',
|
|
|
|
|
'--html',
|
|
|
|
|
'standalone',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const html = await Bun.file(output).text()
|
|
|
|
|
expect(html).toContain('<!doctype html>')
|
|
|
|
|
expect(html).toContain('data-open-pencil-html="standalone"')
|
2026-07-04 16:37:58 +00:00
|
|
|
expect(html).toContain('position:relative')
|
2026-07-04 11:54:58 +00:00
|
|
|
expect(html).toContain('position: absolute')
|
|
|
|
|
expect(html).not.toContain('@tailwindcss/browser@4')
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-04 16:37:58 +00:00
|
|
|
test('export CLI precompiles Tailwind CSS for standalone Tailwind HTML', async () => {
|
2026-07-04 11:54:58 +00:00
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card-standalone-tailwind.html')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'html',
|
|
|
|
|
'--html',
|
|
|
|
|
'standalone',
|
|
|
|
|
'--css',
|
|
|
|
|
'tailwind',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const html = await Bun.file(output).text()
|
|
|
|
|
expect(html).toContain('<!doctype html>')
|
2026-07-04 16:37:58 +00:00
|
|
|
expect(html).toContain('<style>')
|
2026-07-04 11:54:58 +00:00
|
|
|
expect(html).toContain('class="')
|
2026-07-04 16:37:58 +00:00
|
|
|
expect(html).toContain('.flex')
|
|
|
|
|
expect(html).not.toContain('@tailwindcss/browser@4')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('export CLI can write external standalone HTML assets', async () => {
|
|
|
|
|
const { dir, figPath } = await createFigFixture()
|
|
|
|
|
const output = join(dir, 'card-external.html')
|
|
|
|
|
|
|
|
|
|
const { stderr, exitCode } = await runOpenPencilCLI([
|
|
|
|
|
'export',
|
|
|
|
|
figPath,
|
|
|
|
|
'--format',
|
|
|
|
|
'html',
|
|
|
|
|
'--html',
|
|
|
|
|
'standalone',
|
|
|
|
|
'--css',
|
|
|
|
|
'tailwind',
|
|
|
|
|
'--assets',
|
|
|
|
|
'external',
|
|
|
|
|
'--output',
|
|
|
|
|
output
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(stderr).toBe('')
|
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
|
|
|
|
|
|
const html = await Bun.file(output).text()
|
|
|
|
|
const cssPath = join(dir, 'card-external.assets', 'openpencil.css')
|
|
|
|
|
const css = await Bun.file(cssPath).text()
|
|
|
|
|
expect(html).toContain('<link rel="stylesheet" href="card-external.assets/openpencil.css">')
|
|
|
|
|
expect(html).not.toContain('<style>')
|
|
|
|
|
expect(css).toContain('.flex')
|
|
|
|
|
expect(css).toContain('.op-stage')
|
2026-07-04 11:54:58 +00:00
|
|
|
})
|