From fc3f1e5fb457853c4eea7b6c88bab658e47b4fc8 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Thu, 12 Sep 2024 20:11:00 +0100 Subject: [PATCH] Allow access to userland promises when executing for `@inngest/test` (#710) ## Summary For `@inngest/test` (#704), we need access to the internal promise that we send to userland code so that we can access its output for state assertions. ## Checklist - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A - [ ] ~Added unit/integration tests~ N/A - [ ] Added changesets if applicable ## Related - #704 --- .changeset/young-spies-repeat.md | 5 +++++ packages/inngest/src/components/InngestStepTools.ts | 5 +++++ .../inngest/src/components/execution/InngestExecution.ts | 5 +++++ packages/inngest/src/components/execution/v1.ts | 1 + 4 files changed, 16 insertions(+) create mode 100644 .changeset/young-spies-repeat.md diff --git a/.changeset/young-spies-repeat.md b/.changeset/young-spies-repeat.md new file mode 100644 index 000000000..4e9ab90a2 --- /dev/null +++ b/.changeset/young-spies-repeat.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Allow access to userland promises when executing for `@inngest/test` diff --git a/packages/inngest/src/components/InngestStepTools.ts b/packages/inngest/src/components/InngestStepTools.ts index d74bd765c..a956ce9f0 100644 --- a/packages/inngest/src/components/InngestStepTools.ts +++ b/packages/inngest/src/components/InngestStepTools.ts @@ -39,6 +39,11 @@ export interface FoundStep extends HashedOp { fulfilled: boolean; handled: boolean; + /** + * The promise that has been returned to userland code for this step. + */ + promise: Promise; + /** * Returns a boolean representing whether or not the step was handled on this * invocation. diff --git a/packages/inngest/src/components/execution/InngestExecution.ts b/packages/inngest/src/components/execution/InngestExecution.ts index 0a45c542f..7292e624d 100644 --- a/packages/inngest/src/components/execution/InngestExecution.ts +++ b/packages/inngest/src/components/execution/InngestExecution.ts @@ -43,6 +43,11 @@ export interface MemoizedOp extends IncomingOp { */ rawArgs?: unknown[]; fulfilled?: boolean; + + /** + * The promise that has been returned to userland code. + */ + promise?: Promise; seen?: boolean; } diff --git a/packages/inngest/src/components/execution/v1.ts b/packages/inngest/src/components/execution/v1.ts index 639baced3..e79a53591 100644 --- a/packages/inngest/src/components/execution/v1.ts +++ b/packages/inngest/src/components/execution/v1.ts @@ -864,6 +864,7 @@ class V1InngestExecution extends InngestExecution implements IInngestExecution { hashedId, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument fn: opts?.fn ? () => opts.fn?.(...args) : undefined, + promise, fulfilled: Boolean(stepState), displayName: opId.displayName ?? opId.id, handled: false,