Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
test(harper.js): ensure summaries can cross worker boundary
Elijah Potter4446e3cf1873
diff --git a/packages/harper.js/src/Linter.test.ts b/packages/harper.js/src/Linter.test.tsindex f2aee5dad..e9ad24887 100644--- a/packages/harper.js/src/Linter.test.ts+++ b/packages/harper.js/src/Linter.test.ts@@ -188,6 +188,30 @@ for (const [linterName, Linter] of Object.entries(linters)) {expect(lints).toHaveLength(0);});+ test(`${linterName} can summarize simple stat records`, async () => {+ const linter = new Linter({ binary });+ linter.setup();++ const source = 'This is an test.';++ const lints = await linter.lint(source);++ const lint = lints[0];++ expect(lint).not.toBeNull();++ const sug = lint.suggestions()[0];++ expect(sug).not.toBeNull();++ const applied = await linter.applySuggestion(lint, sug);++ expect(applied).toBe('This is a test.');++ const summary = await linter.summarizeStats();+ expect(summary).toBeTypeOf('object');+ });+test(`${linterName} can save and restore stat records`, async () => {const linter = new Linter({ binary });linter.setup();diff --git a/packages/harper.js/src/binary.ts b/packages/harper.js/src/binary.tsindex 8bc685dc1..74164dcb9 100644--- a/packages/harper.js/src/binary.ts+++ b/packages/harper.js/src/binary.ts@@ -30,6 +30,7 @@ export type SerializableTypes =| 'string'| 'number'| 'boolean'+ | 'object'| 'Suggestion'| 'Lint'| 'Span'@@ -133,13 +134,17 @@ export class BinaryModule {}if (type === undefined) {- throw new Error('Unhandled case');+ throw new Error('Unhandled case: type undefined');}return { json, type };}- throw new Error('Unhandled case');+ if (argType == 'object'){+ return { json: JSON.stringify(arg), type: 'object'}+ }++ throw new Error(`Unhandled case: ${arg}`);}async serialize(req: DeserializedRequest): Promise<SerializedRequest> {@@ -170,6 +175,10 @@ export class BinaryModule {assert(Array.isArray(parsed));return await Promise.all(parsed.map((arg) => this.deserializeArg(arg)));}+ case 'object': {+ const parsed = JSON.parse(requestArg.json);+ return parsed;+ }default:throw new Error(`Unhandled case: ${requestArg.type}`);}