Skip to content

Commit 1c9deb7

Browse files
authored
chore: test fixes (#2503)
* chore: fix tests * chore: type fix * chore: fix wrapper regressino
1 parent e914af7 commit 1c9deb7

8 files changed

Lines changed: 29 additions & 11 deletions

File tree

apps/cli/src/__tests__/command-examples.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const WRAPPER_EXTRA_SPECS: Partial<Record<string, OptionSpec[]>> = {
3636
{ name: 'pattern', type: 'string' },
3737
{ name: 'mode', type: 'string' },
3838
{ name: 'case-sensitive', type: 'boolean' },
39+
{ name: 'select-json', type: 'string' },
3940
{ name: 'query-json', type: 'string' },
4041
{ name: 'query-file', type: 'string' },
4142
{ name: 'within-json', type: 'string' },

apps/cli/src/lib/operation-wrapper-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export async function parseWrapperOperationInput(
8585
{ name: 'pattern', type: 'string' },
8686
{ name: 'mode', type: 'string' },
8787
{ name: 'case-sensitive', type: 'boolean' },
88+
{ name: 'select-json', type: 'string' },
8889
{ name: 'query-json', type: 'string' },
8990
{ name: 'query-file', type: 'string' },
9091
{ name: 'within-json', type: 'string' },

packages/document-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
},
1919
"scripts": {
20-
"test": "vitest run"
20+
"test": "bun test"
2121
},
2222
"files": [
2323
"src"

packages/layout-engine/layout-bridge/tsconfig.types.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"composite": true,
5-
"outDir": "dist-types"
5+
"emitDeclarationOnly": true,
6+
"outDir": "dist",
7+
"tsBuildInfoFile": "./dist/tsconfig.types.tsbuildinfo"
68
},
79
"references": [
810
{ "path": "../contracts/tsconfig.json" },

packages/super-editor/src/core/commands/insertContent.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('insertContent (integration) list export', () => {
196196
helpers = await import('../../tests/helpers/helpers.js');
197197
cachedDocxData = await helpers.loadTestDataForEditorTests('blank-doc.docx');
198198
exportHelpers = await import('../../tests/export/export-helpers/index.js');
199-
});
199+
}, 30000);
200200

201201
const setupEditor = () => {
202202
const { docx, media, mediaFiles, fonts } = cachedDocxData;
@@ -368,7 +368,7 @@ describe.skipIf(!process.env.CI)('insertContent (integration) horizontal rule',
368368
vi.doUnmock('../helpers/contentProcessor.js');
369369
helpers = await import('../../tests/helpers/helpers.js');
370370
cachedDocxData = await helpers.loadTestDataForEditorTests('blank-doc.docx');
371-
});
371+
}, 30000);
372372

373373
const setupEditor = () => {
374374
const { docx, media, mediaFiles, fonts } = cachedDocxData;

packages/super-editor/src/document-api-adapters/info-adapter.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ function extractTextFormatting(node: import('prosemirror-model').Node): { fontFa
6262
// to get consistent "first run" formatting rather than mixed properties.
6363
node.descendants((child) => {
6464
if (fontFamily !== undefined || fontSize !== undefined) return false;
65-
if (!child.isText || child.marks.length === 0) return;
66-
for (const mark of child.marks) {
65+
const marks = child.marks ?? [];
66+
if (!child.isText || marks.length === 0) return;
67+
for (const mark of marks) {
6768
const attrs = mark.attrs as Record<string, unknown>;
6869
if (typeof attrs.fontFamily === 'string' && attrs.fontFamily) {
6970
fontFamily = attrs.fontFamily;
@@ -85,6 +86,14 @@ function extractTextFormatting(node: import('prosemirror-model').Node): { fontFa
8586
*/
8687
function collectDocumentStyles(editor: Editor): { styles: DocumentStyles; defaults: DocumentDefaults } {
8788
const headingPattern = HEADING_STYLE_PATTERN;
89+
const doc = editor.state?.doc;
90+
91+
if (!doc?.descendants) {
92+
return {
93+
styles: { paragraphStyles: [] },
94+
defaults: { styleId: 'Normal' },
95+
};
96+
}
8897

8998
// Per-style data
9099
const styleData = new Map<string, { count: number; fontFamily?: string; fontSize?: number }>();
@@ -93,7 +102,7 @@ function collectDocumentStyles(editor: Editor): { styles: DocumentStyles; defaul
93102
const fontCounts = new Map<string, number>();
94103
const sizeCounts = new Map<number, number>();
95104

96-
editor.state.doc.descendants((node) => {
105+
doc.descendants((node) => {
97106
if (node.type.name !== 'paragraph') return;
98107

99108
const props = node.attrs.paragraphProperties as { styleId?: string } | undefined;

packages/super-editor/src/document-api-adapters/plan-engine/blocks-wrappers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ function extractBlockFormatting(node: ProseMirrorNode): {
8686

8787
node.descendants((child) => {
8888
if (fontFamily !== undefined) return false;
89-
if (!child.isText || child.marks.length === 0) return;
90-
for (const mark of child.marks) {
89+
const marks = child.marks ?? [];
90+
if (!child.isText || marks.length === 0) return;
91+
for (const mark of marks) {
9192
const attrs = mark.attrs as Record<string, unknown>;
9293
if (typeof attrs.fontFamily === 'string' && attrs.fontFamily) fontFamily = attrs.fontFamily;
9394
if (attrs.fontSize != null) {

packages/super-editor/src/document-api-adapters/plan-engine/query-match-adapter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,13 @@ export function queryMatchAdapter(editor: Editor, input: QueryMatchInput): Query
513513
// Include a short document text preview so the model can see the actual
514514
// text formatting (quote style, whitespace, etc.) and retry with the
515515
// correct pattern instead of guessing blindly.
516-
const docSize = editor.state.doc.content.size;
516+
const doc = storyEditor.state?.doc;
517+
const docSize = typeof doc?.content?.size === 'number' ? doc.content.size : 0;
517518
const previewLength = Math.min(docSize, 300);
518-
const textPreview = previewLength > 0 ? editor.state.doc.textBetween(0, previewLength, '\n', '\n') : '';
519+
const textPreview =
520+
previewLength > 0 && typeof doc?.textBetween === 'function'
521+
? doc.textBetween(0, previewLength, '\n', '\n')
522+
: '';
519523
throw planError(
520524
'MATCH_NOT_FOUND',
521525
`selector matched zero ranges. Document starts with: "${textPreview.slice(0, 200)}..."`,

0 commit comments

Comments
 (0)