Skip to content

Commit

Permalink
Remove tsc dependency and fix path route (#47)
Browse files Browse the repository at this point in the history
* fix: nextjs path route

* fix: add test for context.cancel inside context.run
  • Loading branch information
CahidArda authored Dec 19, 2024
1 parent 80250fc commit 7396a5d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Binary file modified bun.lockb
Binary file not shown.
14 changes: 9 additions & 5 deletions examples/nextjs/app/path/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const runtime = 'nodejs';

import { serve } from '@upstash/workflow/nextjs'

const someWork = (input: string) => {
Expand All @@ -9,7 +7,13 @@ const someWork = (input: string) => {
export const { POST } = serve<string>(async (context) => {
const input = context.requestPayload
const result1 = await context.run('step1', async () => {
console.log(someWork(input));
const output = someWork(input)
console.log('step 1 input', input, 'output', output)
return output
})

await context.run('step2', async () => {
const output = someWork(result1)
console.log('step 2 input', result1, 'output', output)
})
}, {
})
})
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"husky": "^9.1.6",
"next": "^14.2.14",
"prettier": "3.3.3",
"tsc": "^2.0.4",
"tsup": "^8.3.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.8.0"
Expand Down
33 changes: 33 additions & 0 deletions src/workflow-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,39 @@ describe("Workflow Requests", () => {
expect(result.value).toBe("workflow-finished");
});

test("should call onCancel if context.cancel is called inside context.run", async () => {
const workflowRunId = nanoid();
const token = "myToken";

const context = new WorkflowContext({
qstashClient: new Client({ baseUrl: MOCK_SERVER_URL, token }),
workflowRunId: workflowRunId,
initialPayload: undefined,
headers: new Headers({}) as Headers,
steps: [],
url: WORKFLOW_ENDPOINT,
});

const finished = new FinishState();
const result = await triggerRouteFunction({
onStep: async () => {
await context.run("should call cancel", async () => {
await context.cancel();
});
},
onCleanup: async () => {
throw new Error("shouldn't call");
},
onCancel: async () => {
finished.finish();
},
});
finished.check();
expect(result.isOk()).toBeTrue();
// @ts-expect-error value will be set since result isOk
expect(result.value).toBe("workflow-finished");
});

test("should call publishJSON in triggerWorkflowDelete", async () => {
const workflowRunId = nanoid();
const token = "myToken";
Expand Down

0 comments on commit 7396a5d

Please sign in to comment.