Skip to content

A fast, helpful, and open-source document parser

fix tests

Logan Markewichec9f4f51fda3
diff --git a/packages/node/tests/pool.test.mjs b/packages/node/tests/pool.test.mjs
index ca767cc..7fa2f23 100644
--- a/packages/node/tests/pool.test.mjs
+++ b/packages/node/tests/pool.test.mjs
@@ -152,6 +152,21 @@ test("close() shuts down the pool", { skip: !existsSync(SAMPLE_PDF) }, async ()
pooled.close(); // idempotent
});
+test("CJS build resolves and forks the pool worker", { skip: !existsSync(SAMPLE_PDF) }, async () => {
+ // The worker file is located relative to import.meta.url, which tsup shims
+ // in the .cjs bundle — this guards the fork path for require() consumers.
+ const { createRequire } = await import("node:module");
+ const require = createRequire(import.meta.url);
+ const cjs = require("../dist/lib.cjs");
+ const pooled = new cjs.LiteParse({ ...CFG, poolSize: 1, parseTimeoutMs: 30_000 });
+ try {
+ const result = await pooled.parse(SAMPLE_PDF);
+ assert.ok(result.text.length > 0);
+ } finally {
+ pooled.close();
+ }
+});
+
test("pooled parses run concurrently", { skip: !existsSync(SAMPLE_PDF) }, async () => {
const pooled = new LiteParse({ ...CFG, poolSize: 4 });
try {
diff --git a/packages/node/tsup.config.ts b/packages/node/tsup.config.ts
index 827341b..2858ca3 100644
--- a/packages/node/tsup.config.ts
+++ b/packages/node/tsup.config.ts
@@ -30,4 +30,15 @@ export default defineConfig([
format: ["esm"],
dts: false,
},
+ {
+ ...shared,
+ // Pool worker: forked as a standalone child process by pool.ts, never
+ // imported, so it needs its own entry (nothing else would emit the file)
+ // and ESM suffices — fork() runs an ESM entry regardless of whether the
+ // parent loaded lib.js or lib.cjs. pool.ts resolves the file relative to
+ // import.meta.url, which `shims` keeps working from the .cjs build.
+ entry: { "pool-worker": "src/pool-worker.ts" },
+ format: ["esm"],
+ dts: false,
+ },
]);