-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy path_open-document-track-changes-worker.ts
More file actions
81 lines (71 loc) · 1.91 KB
/
_open-document-track-changes-worker.ts
File metadata and controls
81 lines (71 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Subprocess worker for the openDocument track-changes forwarding test.
*/
import { mock } from 'bun:test';
let editorOpenCalled = false;
let capturedTrackChanges: unknown;
const MockEditor = {
open: mock(async (_source: unknown, options: Record<string, unknown> = {}) => {
editorOpenCalled = true;
capturedTrackChanges = (options.modules as { trackChanges?: unknown } | undefined)?.trackChanges;
return {
destroy: () => {},
exportDocument: async () => new Uint8Array(),
};
}),
};
mock.module('superdoc/super-editor', () => ({
Editor: MockEditor,
BLANK_DOCX_BASE64: '',
DocxEncryptionError: class DocxEncryptionError extends Error {
code: string;
constructor(code: string, message: string) {
super(message);
this.code = code;
}
},
getDocumentApiAdapters: () => ({}),
markdownToPmDoc: () => null,
initPartsRuntime: () => ({ dispose: () => {} }),
syncCommentEntitiesFromCollaboration: () => new Set<string>(),
}));
mock.module('@superdoc/document-api', () => ({
createDocumentApi: () => ({}),
}));
mock.module('happy-dom', () => ({
Window: class {
document = {
createElement: () => ({}),
body: { appendChild: () => {}, innerHTML: '' },
};
happyDOM = { abort: () => {} };
close() {}
},
}));
async function main() {
const { openDocument } = await import('../../lib/document');
const io = {
stdout: () => {},
stderr: () => {},
readStdinBytes: async () => new Uint8Array(),
};
let opened: { dispose(): void } | undefined;
try {
opened = await openDocument(undefined, io, {
editorOpenOptions: {
modules: {
trackChanges: {
replacements: 'independent',
},
},
},
});
} finally {
opened?.dispose();
}
console.log(JSON.stringify({ editorOpenCalled, capturedTrackChanges }));
}
main().catch((e) => {
console.error(e);
process.exit(1);
});