Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/layout-engine/layout-bridge/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
timeout = 5000
4 changes: 3 additions & 1 deletion packages/layout-engine/layout-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
],
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
"test": "vitest run",
"test": "bun test $(grep -l \"from 'bun:test'\" test/*.test.ts)",
"test:vitest": "vitest run $(grep -l \"from 'vitest'\" test/*.test.ts)",
"test:all": "pnpm test && pnpm test:vitest",
"lint": "eslint src --ext .ts",
"dev": "tsup src/index.ts --format esm --watch"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for TypingPerfBenchmark
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { TypingPerfBenchmark } from '../src/benchmarks';

describe('TypingPerfBenchmark', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for CacheWarmer
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { CacheWarmer } from '../src/cache-warmer';
import { FontMetricsCache } from '../src/font-metrics-cache';
import { ParagraphLineCache } from '../src/paragraph-line-cache';
Expand Down
2 changes: 1 addition & 1 deletion packages/layout-engine/layout-bridge/test/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { MeasureCache } from '../src/cache';
import type { FlowBlock, ImageRun, TableBlock, TableCell } from '@superdoc/contracts';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Tests for cache invalidation logic for headers/footers and body content.
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { describe, it, expect, beforeEach, spyOn } from 'bun:test';
import type { FlowBlock, ParagraphBlock, SectionMetadata } from '@superdoc/contracts';
import type { HeaderFooterConstraints } from '../../layout-engine';
import {
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('Cache Invalidation', () => {
});

it('should invalidate cache when content changes', () => {
const invalidateSpy = vi.spyOn(cache, 'invalidate');
const invalidateSpy = spyOn(cache, 'invalidate');

const blocks1 = {
default: [
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('Cache Invalidation', () => {
});

it('should invalidate cache when constraints change', () => {
const invalidateSpy = vi.spyOn(cache, 'invalidate');
const invalidateSpy = spyOn(cache, 'invalidate');

const blocks = {
default: [
Expand Down Expand Up @@ -485,7 +485,7 @@ describe('Cache Invalidation', () => {
});

it('should invalidate cache when section metadata changes', () => {
const invalidateSpy = vi.spyOn(cache, 'invalidate');
const invalidateSpy = spyOn(cache, 'invalidate');

const blocks = {
default: [
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('Cache Invalidation', () => {
});

it('should not invalidate when nothing has changed', () => {
const invalidateSpy = vi.spyOn(cache, 'invalidate');
const invalidateSpy = spyOn(cache, 'invalidate');

const blocks = {
default: [
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('Cache Invalidation', () => {
});

it('should invalidate cache when overflowBaseHeight changes', () => {
const invalidateSpy = vi.spyOn(cache, 'invalidate');
const invalidateSpy = spyOn(cache, 'invalidate');

const blocks = {
default: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { clickToPosition, hitTestPage } from '../src/index.ts';
import type { Layout } from '@superdoc/contracts';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Tests the comment hashing logic used for cache invalidation
*/

import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import type { Run } from '@superdoc/contracts';

// Import the internal function for testing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { computeLinePmRange } from '../src/index.ts';
import type { FlowBlock, Line } from '@superdoc/contracts';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout-engine/layout-bridge/test/diff.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import type { VectorShapeDrawing } from '@superdoc/contracts';
import { computeDirtyRegions } from '../src/diff';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for DirtyTracker
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { DirtyTracker, type DirtyRange } from '../src/dirty-tracker';

describe('DirtyTracker', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* the system.
*/

import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import type { Page, HeaderFooterPage, HeaderFooterLayout } from '@superdoc/contracts';
import { getBucketForPageNumber, getBucketRepresentative } from '../src/layoutHeaderFooter';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* different environment variable configurations.
*/

import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { FeatureFlags, isFeatureEnabled, getAllFeatureFlags, type FeatureFlagKey } from '../src/featureFlags';

describe('Feature Flags', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, mock } from 'bun:test';
import type { FlowBlock, Measure } from '@superdoc/contracts';
import { incrementalLayout } from '../src/incrementalLayout';

Expand Down Expand Up @@ -34,7 +34,7 @@ describe('Footnotes in columns', () => {
const footnoteOne = makeParagraph('footnote-1-0-paragraph', 'Footnote one', 0);
const footnoteTwo = makeParagraph('footnote-2-0-paragraph', 'Footnote two', 0);

const measureBlock = vi.fn(async (block: FlowBlock) => {
const measureBlock = mock(async (block: FlowBlock) => {
if (block.kind === 'columnBreak') {
return { kind: 'columnBreak' } as Measure;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, mock } from 'bun:test';
import type { FlowBlock, Measure } from '@superdoc/contracts';
import { incrementalLayout } from '../src/incrementalLayout';

Expand Down Expand Up @@ -43,7 +43,7 @@ const buildLayout = async ({
const dividerHeight = 1;
const topPadding = 4;

const measureBlock = vi.fn(async (block: FlowBlock) => {
const measureBlock = mock(async (block: FlowBlock) => {
if (block.id.startsWith('footnote-')) {
return makeMeasure(footnoteLineHeight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 3. Integration with incrementalLayout
*/

import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, mock } from 'bun:test';
import type { FlowBlock, Measure, ParagraphBlock, TextRun, SectionMetadata } from '@superdoc/contracts';
import { incrementalLayout } from '../src/incrementalLayout';
import type { HeaderFooterBatch } from '../src/layoutHeaderFooter';
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
];

// Mock measureBlock function
const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

// Run incremental layout with headers
const result = await incrementalLayout(
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
default: [makePageNumberParagraph('header-large-doc')],
};

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

const result = await incrementalLayout(
[],
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
default: [makePageNumberParagraph('footer-default')],
};

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

const result = await incrementalLayout(
[],
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
default: [originalHeaderBlock],
};

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

await incrementalLayout(
[],
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
},
];

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

const result = await incrementalLayout(
[],
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
default: [makePageNumberParagraph('header-single')],
};

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

const result = await incrementalLayout(
[],
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('End-to-End Header/Footer Token Resolution', () => {
makeTextParagraph(`body-${i}`, `Content ${i + 1}`),
);

const measureBlock = vi.fn(async () => makeMeasure(20));
const measureBlock = mock(async () => makeMeasure(20));

const result = await incrementalLayout(
[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it } from 'bun:test';
import type { Layout } from '@superdoc/contracts';
import {
defaultHeaderFooterIdentifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { hitTestPage, hitTestFragment } from '../src/index.ts';
import { columnsLayout, blocks, measures } from './mock-data';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for ImeHandler
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { ImeHandler } from '../src/ime-handler';

describe('ImeHandler', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* Tests for debug logging and metrics collection.
*/

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { describe, it, expect, beforeEach, afterEach, spyOn } from 'bun:test';
import { PageTokenLogger, HeaderFooterCacheLogger, MetricsCollector } from '../src/instrumentation';

describe('Instrumentation', () => {
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
let consoleLogSpy: ReturnType<typeof spyOn>;
let consoleWarnSpy: ReturnType<typeof spyOn>;

beforeEach(() => {
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
consoleLogSpy = spyOn(console, 'log').mockImplementation(() => {});
consoleWarnSpy = spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* Tests for LayoutCoordinator
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { describe, it, expect, beforeEach, mock, spyOn } from 'bun:test';
import { LayoutCoordinator, type LayoutResult } from '../src/layout-coordinator';
import { Priority } from '../src/layout-scheduler';
import { LayoutVersionManager } from '../src/layout-version-manager';

describe('LayoutCoordinator', () => {
let coordinator: LayoutCoordinator;
let versionManager: LayoutVersionManager;
let executeP0: ReturnType<typeof vi.fn>;
let executeP1: ReturnType<typeof vi.fn>;
let executeWorker: ReturnType<typeof vi.fn>;
let executeP0: ReturnType<typeof mock>;
let executeP1: ReturnType<typeof mock>;
let executeWorker: ReturnType<typeof mock>;

const mockLayout = { pages: [], pageSize: { w: 612, h: 792 } };

Expand All @@ -28,9 +28,9 @@ describe('LayoutCoordinator', () => {
aborted: false,
};

executeP0 = vi.fn().mockReturnValue(mockResult);
executeP1 = vi.fn().mockResolvedValue(mockResult);
executeWorker = vi.fn().mockResolvedValue(mockResult);
executeP0 = mock(() => mockResult);
executeP1 = mock(() => Promise.resolve(mockResult));
executeWorker = mock(() => Promise.resolve(mockResult));

coordinator = new LayoutCoordinator({
layoutVersionManager: versionManager,
Expand Down Expand Up @@ -144,15 +144,15 @@ describe('LayoutCoordinator', () => {

describe('version management integration', () => {
it('should notify version manager on P0 completion', () => {
const spy = vi.spyOn(versionManager, 'onLayoutComplete');
const spy = spyOn(versionManager, 'onLayoutComplete');

coordinator.scheduleLayout(1, Priority.P0, { scope: 'paragraph' });

expect(spy).toHaveBeenCalledWith(1);
});

it('should notify version manager on async completion', async () => {
const spy = vi.spyOn(versionManager, 'onLayoutComplete');
const spy = spyOn(versionManager, 'onLayoutComplete');

coordinator.scheduleLayout(1, Priority.P1, { scope: 'viewport' });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for LayoutScheduler
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { LayoutScheduler, Priority, type LayoutRequest } from '../src/layout-scheduler';

describe('LayoutScheduler', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for LayoutWorkerManager
*/

import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'bun:test';
import { LayoutWorkerManager } from '../src/layout-worker';
import { Priority } from '../src/layout-scheduler';

Expand Down
Loading
Loading