Skip to content

Commit 4216357

Browse files
authored
chore(testing-sdk): fix all typescript errors in tests (#355)
*Issue #, if available:* *Description of changes:* Currently the tests have a lot of TypeScript errors since TS has not been running on the tests. This PR fixes all the errors and enables running `tsc` when running `npm test` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 4e981d7 commit 4216357

25 files changed

+661
-268
lines changed

packages/aws-durable-execution-sdk-js-testing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"prepublishOnly": "npm run build && npm run test",
2424
"lint": "eslint --fix",
2525
"prebuild": "npm run lint",
26-
"test": "jest --config jest.config.mjs --collectCoverage --collectCoverageFrom=src/**/*.{ts,js}",
26+
"test": "tsc --noEmit && jest --config jest.config.mjs --collectCoverage --collectCoverageFrom=src/**/*.{ts,js}",
2727
"run-durable": "tsx src/cli/run-durable.ts"
2828
},
2929
"exports": {

packages/aws-durable-execution-sdk-js-testing/src/checkpoint-server/handlers/__tests__/execution-handlers.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ describe("execution handlers", () => {
7272
});
7373
});
7474

75-
it("should return undefined when execution manager cannot find execution", () => {
75+
it("should propagate errors when execution manager cannot find execution", () => {
7676
const startInvocationSpy = jest
7777
.spyOn(executionManager, "startInvocation")
78-
.mockReturnValue(undefined);
78+
.mockImplementation(() => {
79+
throw new Error("Execution not found");
80+
});
7981

80-
const result = processStartInvocation(
81-
"non-existent-execution",
82-
executionManager,
83-
);
82+
expect(() =>
83+
processStartInvocation("non-existent-execution", executionManager),
84+
).toThrow("Execution not found");
8485

8586
expect(startInvocationSpy).toHaveBeenCalledWith(
8687
createExecutionId("non-existent-execution"),
8788
);
88-
expect(result).toBeUndefined();
8989
});
9090
});
9191

packages/aws-durable-execution-sdk-js-testing/src/checkpoint-server/storage/__tests__/callback-manager.test.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
OperationType,
66
} from "@aws-sdk/client-lambda";
77
import { CallbackManager, CompleteCallbackStatus } from "../callback-manager";
8-
import { CheckpointManager } from "../checkpoint-manager";
8+
import { CheckpointManager, CheckpointOperation } from "../checkpoint-manager";
99
import {
1010
createExecutionId,
1111
createCallbackId,
@@ -143,15 +143,17 @@ describe("CallbackManager", () => {
143143
const timeoutSeconds = 30;
144144

145145
// Setup operation data
146-
const mockOperationData = {
146+
const mockOperationData: CheckpointOperation = {
147147
operation: {
148148
Id: operationId,
149149
Type: OperationType.CALLBACK,
150150
Status: OperationStatus.STARTED,
151+
StartTimestamp: undefined,
151152
},
152153
update: {
153154
Id: operationId,
154155
Type: OperationType.CALLBACK,
156+
Action: undefined,
155157
},
156158
events: [],
157159
};
@@ -188,15 +190,17 @@ describe("CallbackManager", () => {
188190
describe("completeCallback", () => {
189191
beforeEach(() => {
190192
// Setup mock operation data
191-
const mockOperationData = {
193+
const mockOperationData: CheckpointOperation = {
192194
operation: {
193195
Id: "test-operation-id",
194196
Type: OperationType.CALLBACK,
195197
Status: OperationStatus.STARTED,
198+
StartTimestamp: undefined,
196199
},
197200
update: {
198201
Id: "test-operation-id",
199202
Type: OperationType.CALLBACK,
203+
Action: undefined,
200204
},
201205
events: [],
202206
};
@@ -343,11 +347,13 @@ describe("CallbackManager", () => {
343347
Id: "test-operation-id",
344348
Type: OperationType.CALLBACK,
345349
Status: OperationStatus.STARTED,
350+
StartTimestamp: undefined,
346351
},
347352
events: [
348353
{
349354
CallbackStartedDetails: {
350355
HeartbeatTimeout: 60,
356+
CallbackId: undefined,
351357
},
352358
},
353359
],
@@ -373,15 +379,18 @@ describe("CallbackManager", () => {
373379
const callbackId = createCallbackId("test-callback-id");
374380

375381
// Update operation to not have heartbeat timeout
376-
const mockOperationData = {
382+
const mockOperationData: CheckpointOperation = {
377383
operation: {
378384
Id: "test-operation-id",
379385
Type: OperationType.CALLBACK,
386+
StartTimestamp: undefined,
387+
Status: undefined,
380388
},
381389
update: {
382390
Id: "test-operation-id",
383391
Type: OperationType.CALLBACK,
384392
CallbackOptions: {},
393+
Action: undefined,
385394
},
386395
events: [],
387396
};
@@ -443,27 +452,31 @@ describe("CallbackManager", () => {
443452
const operationId2 = "operation-2";
444453

445454
// Setup operation data first
446-
const mockOperationData1 = {
455+
const mockOperationData1: CheckpointOperation = {
447456
operation: {
448457
Id: operationId1,
449458
Type: OperationType.CALLBACK,
450459
Status: OperationStatus.STARTED,
460+
StartTimestamp: undefined,
451461
},
452462
update: {
453463
Id: operationId1,
454464
Type: OperationType.CALLBACK,
465+
Action: undefined,
455466
},
456467
events: [],
457468
};
458-
const mockOperationData2 = {
469+
const mockOperationData2: CheckpointOperation = {
459470
operation: {
460471
Id: operationId2,
461472
Type: OperationType.CALLBACK,
462473
Status: OperationStatus.STARTED,
474+
StartTimestamp: undefined,
463475
},
464476
update: {
465477
Id: operationId2,
466478
Type: OperationType.CALLBACK,
479+
Action: undefined,
467480
},
468481
events: [],
469482
};
@@ -527,15 +540,17 @@ describe("CallbackManager", () => {
527540
const operationId = "integration-test-id";
528541

529542
// Setup operation data
530-
const mockOperationData = {
543+
const mockOperationData: CheckpointOperation = {
531544
operation: {
532545
Id: operationId,
533546
Type: OperationType.CALLBACK,
534547
Status: OperationStatus.STARTED,
548+
StartTimestamp: undefined,
535549
},
536550
update: {
537551
Id: operationId,
538552
Type: OperationType.CALLBACK,
553+
Action: undefined,
539554
},
540555
events: [],
541556
};
@@ -579,15 +594,17 @@ describe("CallbackManager", () => {
579594

580595
// Setup operation data for all
581596
operationIds.forEach((id) => {
582-
const mockOperationData = {
597+
const mockOperationData: CheckpointOperation = {
583598
operation: {
584599
Id: id,
585600
Type: OperationType.CALLBACK,
586601
Status: OperationStatus.STARTED,
602+
StartTimestamp: undefined,
587603
},
588604
update: {
589605
Id: id,
590606
Type: OperationType.CALLBACK,
607+
Action: undefined,
591608
},
592609
events: [],
593610
};

packages/aws-durable-execution-sdk-js-testing/src/checkpoint-server/storage/__tests__/checkpoint-manager-complete.test.ts

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import {
33
OperationType,
44
OperationStatus,
55
} from "@aws-sdk/client-lambda";
6-
import {
7-
createInvocationId,
8-
createExecutionId,
9-
} from "../../utils/tagged-strings";
6+
import { createExecutionId } from "../../utils/tagged-strings";
107
import { CheckpointManager } from "../checkpoint-manager";
118

129
jest.mock("node:crypto", () => ({
@@ -16,8 +13,6 @@ jest.mock("node:crypto", () => ({
1613
describe("checkpoint-manager completeOperation", () => {
1714
let storage: CheckpointManager;
1815

19-
const mockInvocationId = createInvocationId();
20-
2116
beforeEach(() => {
2217
storage = new CheckpointManager(createExecutionId("test-execution-id"));
2318
jest.clearAllMocks();
@@ -48,14 +43,11 @@ describe("checkpoint-manager completeOperation", () => {
4843
storage.initialize();
4944

5045
// Register a step operation
51-
storage.registerUpdate(
52-
{
53-
Id: "new-id",
54-
Action: OperationAction.START,
55-
Type: OperationType.STEP,
56-
},
57-
mockInvocationId,
58-
);
46+
storage.registerUpdate({
47+
Id: "new-id",
48+
Action: OperationAction.START,
49+
Type: OperationType.STEP,
50+
});
5951

6052
// Complete the operation
6153
const { operation } = storage.completeOperation({
@@ -101,17 +93,14 @@ describe("checkpoint-manager completeOperation", () => {
10193
storage.initialize();
10294

10395
// Register a step operation
104-
storage.registerUpdate(
105-
{
106-
Id: "new-id",
107-
Action: OperationAction.START,
108-
Type: OperationType.CONTEXT,
109-
ContextOptions: {
110-
ReplayChildren: true,
111-
},
96+
storage.registerUpdate({
97+
Id: "new-id",
98+
Action: OperationAction.START,
99+
Type: OperationType.CONTEXT,
100+
ContextOptions: {
101+
ReplayChildren: true,
112102
},
113-
mockInvocationId,
114-
);
103+
});
115104

116105
// Complete the operation
117106
const { operation } = storage.completeOperation({
@@ -143,15 +132,12 @@ describe("checkpoint-manager completeOperation", () => {
143132
storage.initialize();
144133

145134
// Register a step operation
146-
storage.registerUpdate(
147-
{
148-
Id: "retry-step-id",
149-
Action: OperationAction.START,
150-
Type: OperationType.STEP,
151-
Name: "test-step",
152-
},
153-
mockInvocationId,
154-
);
135+
storage.registerUpdate({
136+
Id: "retry-step-id",
137+
Action: OperationAction.START,
138+
Type: OperationType.STEP,
139+
Name: "test-step",
140+
});
155141

156142
// Complete the operation with RETRY action
157143
const { operation } = storage.completeOperation({
@@ -183,15 +169,12 @@ describe("checkpoint-manager completeOperation", () => {
183169
storage.initialize();
184170

185171
// Register a step operation with initial attempt
186-
storage.registerUpdate(
187-
{
188-
Id: "retry-step-id",
189-
Action: OperationAction.START,
190-
Type: OperationType.STEP,
191-
Name: "test-step",
192-
},
193-
mockInvocationId,
194-
);
172+
storage.registerUpdate({
173+
Id: "retry-step-id",
174+
Action: OperationAction.START,
175+
Type: OperationType.STEP,
176+
Name: "test-step",
177+
});
195178

196179
// Set initial attempt to 2
197180
const operationData = storage.operationDataMap.get("retry-step-id");
@@ -218,15 +201,12 @@ describe("checkpoint-manager completeOperation", () => {
218201
storage.initialize();
219202

220203
// Register a step operation
221-
storage.registerUpdate(
222-
{
223-
Id: "retry-step-id",
224-
Action: OperationAction.START,
225-
Type: OperationType.STEP,
226-
Name: "test-step",
227-
},
228-
mockInvocationId,
229-
);
204+
storage.registerUpdate({
205+
Id: "retry-step-id",
206+
Action: OperationAction.START,
207+
Type: OperationType.STEP,
208+
Name: "test-step",
209+
});
230210

231211
// Add some existing step details
232212
const operationData = storage.operationDataMap.get("retry-step-id");
@@ -270,15 +250,12 @@ describe("checkpoint-manager completeOperation", () => {
270250
storage.initialize();
271251

272252
// Register a step operation
273-
storage.registerUpdate(
274-
{
275-
Id: "retry-step-id",
276-
Action: OperationAction.START,
277-
Type: OperationType.STEP,
278-
Name: "test-step",
279-
},
280-
mockInvocationId,
281-
);
253+
storage.registerUpdate({
254+
Id: "retry-step-id",
255+
Action: OperationAction.START,
256+
Type: OperationType.STEP,
257+
Name: "test-step",
258+
});
282259

283260
// Ensure no existing StepDetails
284261
const operationData = storage.operationDataMap.get("retry-step-id");

0 commit comments

Comments
 (0)