From efaeb1c45126e7215abb7e0f1141629866548f26 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Mon, 16 Sep 2024 14:07:39 -0400 Subject: [PATCH] feat: loosen watcher type guards to support non-passables Co-authored-by: Michael FIG --- packages/vow/src/watch-utils.js | 4 ++-- packages/vow/test/watch-utils.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/vow/src/watch-utils.js b/packages/vow/src/watch-utils.js index 0bb740530bc9..1039b950005c 100644 --- a/packages/vow/src/watch-utils.js +++ b/packages/vow/src/watch-utils.js @@ -57,8 +57,8 @@ export const prepareWatchUtils = ( asPromise: M.call(M.raw()).rest(M.raw()).returns(M.promise()), }), watcher: M.interface('Watcher', { - onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()), - onRejected: M.call(M.any()).rest(M.any()).returns(M.any()), + onFulfilled: M.call(M.raw()).rest(M.raw()).returns(M.raw()), + onRejected: M.call(M.raw()).rest(M.raw()).returns(M.raw()), }), retryRejectionPromiseWatcher: PromiseWatcherI, }, diff --git a/packages/vow/test/watch-utils.test.js b/packages/vow/test/watch-utils.test.js index 13e5be07d5df..ac6a597d7df3 100644 --- a/packages/vow/test/watch-utils.test.js +++ b/packages/vow/test/watch-utils.test.js @@ -252,3 +252,19 @@ test('asPromise handles watcher arguments', async t => { t.is(result, 'watcher test'); t.true(watcherCalled); }); + +test('allVows handles unstorable results', async t => { + const zone = makeHeapZone(); + const { watch, when, allVows } = prepareBasicVowTools(zone); + + const nonPassable = () => 'i am a function'; + + const specimenA = Promise.resolve('i am a promise'); + const specimenB = watch(nonPassable); + + const result = await when(allVows([specimenA, specimenB])); + t.is(result.length, 2); + t.is(result[0], 'i am a promise'); + t.is(result[1], nonPassable); + t.is(result[1](), 'i am a function'); +});