Problem
The CDK Jest test suite takes ~6 minutes (371s) because construct tests re-synthesize CDK templates on every test() block — even when the configuration is identical across tests.
Profiling revealed that task-api.test.ts alone calls Template.fromStack() 41 times (370s wall clock), with each synth taking 5-10s for the TaskApi construct (WAF, Cognito, Lambda, API Gateway).
Solution
Share synthesized Template objects via beforeAll within each describe block. Since CDK Template is read-only (assertions don't mutate), tests with identical input can safely reuse a single template.
Results
| Metric |
Before |
After |
Improvement |
| Total Jest time |
371s |
145s |
61% faster |
task-api.test.ts |
370s |
89s |
76% faster |
| CDK synths in file |
41 |
11 |
73% fewer |
Acceptance criteria
PR
#195
Problem
The CDK Jest test suite takes ~6 minutes (371s) because construct tests re-synthesize CDK templates on every
test()block — even when the configuration is identical across tests.Profiling revealed that
task-api.test.tsalone callsTemplate.fromStack()41 times (370s wall clock), with each synth taking 5-10s for the TaskApi construct (WAF, Cognito, Lambda, API Gateway).Solution
Share synthesized
Templateobjects viabeforeAllwithin eachdescribeblock. Since CDKTemplateis read-only (assertions don't mutate), tests with identical input can safely reuse a single template.Results
task-api.test.tsAcceptance criteria
task-api.test.tsto usebeforeAllshared templatestask-orchestrator.test.ts(33 synths, 119s)ecs-agent-cluster.test.ts(11 synths, 34s)PR
#195