promise-try-shim.test.mjs
38 lines 1.4 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 19 hours ago
1 /**
2 * Ensures lib/shims/promise-try.mjs can install Promise.try when absent (Node 20 / unpdf).
3 */
4 import { describe, it } from 'node:test';
5 import assert from 'node:assert/strict';
6
7 describe('lib/shims/promise-try', () => {
8 it('defines Promise.try when the global is missing (mirrors Node 20 CI)', async () => {
9 const d = Object.getOwnPropertyDescriptor(Promise, 'try');
10 if (!d?.configurable) {
11 // Very old runtimes: leave behavior to pdf golden tests
12 return;
13 }
14 const orig = d.value;
15 try {
16 // eslint-disable-next-line no-delete-var -- test setup
17 delete Promise.try;
18 assert.equal(typeof Promise.try, 'undefined');
19 const base = new URL('../lib/shims/promise-try.mjs', import.meta.url);
20 base.searchParams.set('t', String(Date.now()));
21 await import(base.href);
22 assert.equal(typeof Promise.try, 'function');
23 assert.equal(await Promise.try(() => 7), 7);
24 assert.equal(
25 await Promise.try((a, b) => a + b, 2, 3),
26 5,
27 'Promise.try(fn, ...args) must forward args (PDF.js workers rely on this)',
28 );
29 const err = new Error('sync-fail');
30 await assert.rejects(
31 () => Promise.try(() => { throw err; }),
32 (e) => e === err
33 );
34 } finally {
35 Object.defineProperty(Promise, 'try', { value: orig, configurable: true, writable: true });
36 }
37 });
38 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 19 hours ago