From 11c7eb5c545ba3c158bcbdee539055f6ef2cdca6 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:42:56 -0700 Subject: [PATCH] Fix warnings (#53) * fix warnings * fix warnings --- src/worker/registry.ts | 10 +++++++++- test/e2e/orchestration.spec.ts | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/worker/registry.ts b/src/worker/registry.ts index 01c6926..99c4be5 100644 --- a/src/worker/registry.ts +++ b/src/worker/registry.ts @@ -72,6 +72,14 @@ export class Registry { } _getFunctionName(fn: Function): string { - return fn.name || fn.toString().match(/function\s*([^(]*)\(/)![1]; + if (fn.name) { + return fn.name; + } + + const fnStr = fn.toString(); + const start = fnStr.indexOf('function') + 'function'.length; + const end = fnStr.indexOf('(', start); + + return fnStr.slice(start, end).trim() || ''; } } diff --git a/test/e2e/orchestration.spec.ts b/test/e2e/orchestration.spec.ts index 5f8aa24..03daf47 100644 --- a/test/e2e/orchestration.spec.ts +++ b/test/e2e/orchestration.spec.ts @@ -227,7 +227,7 @@ describe("Durable Functions", () => { expectedCompletionSecond += delay * 1000; } expect(expectedCompletionSecond).toBeDefined(); - const actualCompletionSecond = state?.lastUpdatedAt?.getTime(); + const actualCompletionSecond = state?.lastUpdatedAt?.getTime() ?? 0; expect(actualCompletionSecond).toBeDefined(); expect(state); @@ -237,7 +237,7 @@ describe("Durable Functions", () => { expect(state?.runtimeStatus).toEqual(OrchestrationStatus.ORCHESTRATION_STATUS_COMPLETED); expect(state?.createdAt).toBeDefined(); expect(state?.lastUpdatedAt).toBeDefined(); - expect(expectedCompletionSecond).toBeLessThanOrEqual(actualCompletionSecond!); + expect(expectedCompletionSecond).toBeLessThanOrEqual(actualCompletionSecond); }, 31000); it("should wait for external events with a timeout - true", async () => {