Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions packages/document-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"default": "./src/types/index.ts"
}
},
"scripts": {
"test": "bun test"
},
"files": [
"src"
]
Expand Down
24 changes: 12 additions & 12 deletions packages/document-api/src/authorities/authorities.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeAuthoritiesList,
Expand All @@ -17,18 +17,18 @@ import {

function makeAdapter(): AuthoritiesAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
configure: vi.fn().mockReturnValue({ success: true }),
rebuild: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
configure: mock().mockReturnValue({ success: true }),
rebuild: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
entries: {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
update: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
update: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/document-api/src/blocks/blocks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, it, mock } from 'bun:test';
import { executeBlocksDelete, type BlocksAdapter } from './blocks.js';
import type { BlocksDeleteInput, BlocksDeleteResult } from '../types/blocks.types.js';
import { DocumentApiValidationError } from '../errors.js';
Expand All @@ -9,7 +9,7 @@ function makeAdapter(result?: BlocksDeleteResult): BlocksAdapter {
deleted: { kind: 'block', nodeType: 'paragraph', nodeId: 'p1' },
};
return {
delete: vi.fn(() => result ?? defaultResult),
delete: mock(() => result ?? defaultResult),
};
}

Expand Down
12 changes: 6 additions & 6 deletions packages/document-api/src/bookmarks/bookmarks.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeBookmarksList,
Expand All @@ -11,11 +11,11 @@ import {

function makeAdapter(): BookmarksAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
rename: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
rename: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
};
}

Expand Down
14 changes: 7 additions & 7 deletions packages/document-api/src/captions/captions.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeCaptionsList,
Expand All @@ -12,12 +12,12 @@ import {

function makeAdapter(): CaptionsAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
update: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
configure: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
update: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
configure: mock().mockReturnValue({ success: true }),
};
}

Expand Down
32 changes: 16 additions & 16 deletions packages/document-api/src/citations/citations.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeCitationsList,
Expand All @@ -21,24 +21,24 @@ import {

function makeAdapter(): CitationsAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
update: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
update: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
sources: {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
update: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
update: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
},
bibliography: {
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
rebuild: vi.fn().mockReturnValue({ success: true }),
configure: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
rebuild: mock().mockReturnValue({ success: true }),
configure: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, mock } from 'bun:test';
import { executeClearContent } from './clear-content.js';
import type { ClearContentAdapter } from './clear-content.js';
import type { Receipt } from '../types/receipt.js';
Expand All @@ -8,7 +9,7 @@ const NOOP_RECEIPT: Receipt = { success: false, failure: { code: 'NO_OP', messag
describe('executeClearContent', () => {
it('delegates to adapter.clearContent with input and options', () => {
const adapter: ClearContentAdapter = {
clearContent: vi.fn(() => SUCCESS_RECEIPT),
clearContent: mock(() => SUCCESS_RECEIPT),
};

const result = executeClearContent(adapter, {}, { expectedRevision: 'r1' });
Expand All @@ -19,7 +20,7 @@ describe('executeClearContent', () => {

it('returns adapter result when NO_OP', () => {
const adapter: ClearContentAdapter = {
clearContent: vi.fn(() => NOOP_RECEIPT),
clearContent: mock(() => NOOP_RECEIPT),
};

const result = executeClearContent(adapter, {});
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 { executeBlocksDelete, type BlocksAdapter } from '../blocks/blocks.js';
import type { BlocksDeleteResult } from '../types/blocks.types.js';
import { DocumentApiValidationError } from '../errors.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/document-api/src/contract/contract.test.ts
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 { COMMAND_CATALOG, OPERATION_DESCRIPTION_MAP, OPERATION_EXPECTED_RESULT_MAP } from './command-catalog.js';
import { OPERATION_DEFINITIONS, type ReferenceGroupKey } from './operation-definitions.js';
import { DOCUMENT_API_MEMBER_PATHS, OPERATION_MEMBER_PATH_MAP, memberPathForOperation } from './operation-map.js';
Expand Down
1 change: 1 addition & 0 deletions packages/document-api/src/contract/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'bun:test';
import { assertOperationId, isOperationId, isValidOperationIdFormat, OPERATION_IDS } from './types.js';
import type { DocumentApiMemberPath } from './operation-map.js';

Expand Down
7 changes: 4 additions & 3 deletions packages/document-api/src/create/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, mock } from 'bun:test';
import {
executeCreateParagraph,
executeCreateSectionBreak,
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('executeCreateSectionBreak', () => {
paragraph: () => ({ success: true }),
heading: () => ({ success: true }),
table: () => ({ success: true }),
sectionBreak: vi.fn(() => ({
sectionBreak: mock(() => ({
success: true,
section: { kind: 'section', sectionId: 'section-1' },
})),
Expand All @@ -166,7 +167,7 @@ describe('executeCreateSectionBreak', () => {
paragraph: () => ({ success: true }),
heading: () => ({ success: true }),
table: () => ({ success: true }),
sectionBreak: vi.fn(() => ({ success: true })),
sectionBreak: mock(() => ({ success: true })),
} as any;

expect(() =>
Expand All @@ -181,7 +182,7 @@ describe('executeCreateSectionBreak', () => {
paragraph: () => ({ success: true }),
heading: () => ({ success: true }),
table: () => ({ success: true }),
sectionBreak: vi.fn(() => ({ success: true })),
sectionBreak: mock(() => ({ success: true })),
} as any;

expect(() =>
Expand Down
12 changes: 6 additions & 6 deletions packages/document-api/src/cross-refs/cross-refs.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeCrossRefsList,
Expand All @@ -11,11 +11,11 @@ import {

function makeAdapter(): CrossRefsAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
rebuild: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
rebuild: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
};
}

Expand Down
12 changes: 6 additions & 6 deletions packages/document-api/src/fields/fields.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeFieldsList,
Expand All @@ -11,11 +11,11 @@ import {

function makeAdapter(): FieldsAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
rebuild: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
rebuild: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/document-api/src/find/find.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, mock } from 'bun:test';
import { executeFind, normalizeFindQuery } from './find.js';
import type { Query, Selector } from '../types/index.js';
import type { SDFindInput, SDFindResult } from '../types/sd-envelope.js';
Expand Down Expand Up @@ -167,7 +168,7 @@ describe('executeFind', () => {
offset: 0,
items: [],
};
const adapter: FindAdapter = { find: vi.fn(() => sdResult) };
const adapter: FindAdapter = { find: mock(() => sdResult) };
const input: SDFindInput = {
select: { type: 'node', nodeType: 'paragraph' },
limit: 5,
Expand All @@ -186,7 +187,7 @@ describe('executeFind', () => {
offset: 0,
items: [],
};
const adapter: FindAdapter = { find: vi.fn(() => sdResult) };
const adapter: FindAdapter = { find: mock(() => sdResult) };
const input: SDFindInput = {
select: { type: 'text', pattern: 'hello' },
limit: 10,
Expand Down
14 changes: 7 additions & 7 deletions packages/document-api/src/footnotes/footnotes.test.ts
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 { DocumentApiValidationError } from '../errors.js';
import {
executeFootnotesList,
Expand All @@ -12,12 +12,12 @@ import {

function makeAdapter(): FootnotesAdapter {
return {
list: vi.fn().mockReturnValue({ items: [], total: 0 }),
get: vi.fn().mockReturnValue({}),
insert: vi.fn().mockReturnValue({ success: true }),
update: vi.fn().mockReturnValue({ success: true }),
remove: vi.fn().mockReturnValue({ success: true }),
configure: vi.fn().mockReturnValue({ success: true }),
list: mock().mockReturnValue({ items: [], total: 0 }),
get: mock().mockReturnValue({}),
insert: mock().mockReturnValue({ success: true }),
update: mock().mockReturnValue({ success: true }),
remove: mock().mockReturnValue({ success: true }),
configure: mock().mockReturnValue({ success: true }),
};
}

Expand Down
10 changes: 7 additions & 3 deletions packages/document-api/src/format/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { describe, expect, it, vi, assertType } from 'vitest';
import { describe, expect, it, mock } from 'bun:test';
import type { FormatInlineAliasInput, StyleApplyInput } from './format.js';

/** Type-only assertion — validates at compile time, no-op at runtime. */
function assertType<T>(_value: T): void {}

import { executeStyleApply, executeInlineAlias } from './format.js';
import { DocumentApiValidationError } from '../errors.js';
import type { TextMutationReceipt } from '../types/index.js';
Expand All @@ -25,9 +29,9 @@ function makeReceipt(): TextMutationReceipt {
};
}

function makeAdapter(): SelectionMutationAdapter & Record<string, ReturnType<typeof vi.fn>> {
function makeAdapter(): SelectionMutationAdapter & Record<string, ReturnType<typeof mock>> {
return {
execute: vi.fn(() => makeReceipt()),
execute: mock(() => makeReceipt()),
};
}

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 { INLINE_PROPERTY_BY_KEY, validateInlineRunPatch } from './inline-run-patch.js';
import { DocumentApiValidationError } from '../errors.js';

Expand Down
5 changes: 3 additions & 2 deletions packages/document-api/src/get-html/get-html.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, expect, it, mock } from 'bun:test';
import { executeGetHtml } from './get-html.js';
import type { GetHtmlAdapter } from './get-html.js';

describe('executeGetHtml', () => {
it('delegates to adapter.getHtml with the input', () => {
const adapter: GetHtmlAdapter = {
getHtml: vi.fn(() => '<p>Hello world</p>'),
getHtml: mock(() => '<p>Hello world</p>'),
};

const result = executeGetHtml(adapter, {});
Expand All @@ -15,7 +16,7 @@ describe('executeGetHtml', () => {

it('passes unflattenLists option through to the adapter', () => {
const adapter: GetHtmlAdapter = {
getHtml: vi.fn(() => '<ol><li>item</li></ol>'),
getHtml: mock(() => '<ol><li>item</li></ol>'),
};

const result = executeGetHtml(adapter, { unflattenLists: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, expect, it, mock } from 'bun:test';
import { executeGetMarkdown } from './get-markdown.js';
import type { GetMarkdownAdapter } from './get-markdown.js';

describe('executeGetMarkdown', () => {
it('delegates to adapter.getMarkdown with the input', () => {
const adapter: GetMarkdownAdapter = {
getMarkdown: vi.fn(() => '# Hello\n\nworld\n'),
getMarkdown: mock(() => '# Hello\n\nworld\n'),
};

const result = executeGetMarkdown(adapter, {});
Expand Down
Loading
Loading