Skip to content

fix(cdk): optimize test suite via shared CDK template synthesis#195

Draft
scottschreckengaust wants to merge 2 commits into
mainfrom
fix/194-ts-isolated-modules
Draft

fix(cdk): optimize test suite via shared CDK template synthesis#195
scottschreckengaust wants to merge 2 commits into
mainfrom
fix/194-ts-isolated-modules

Conversation

@scottschreckengaust
Copy link
Copy Markdown
Contributor

@scottschreckengaust scottschreckengaust commented May 27, 2026

Summary

  • Refactors the 3 slowest CDK construct test suites to share templates via beforeAll
  • Reduces total CDK synth calls from 84 → 25 across these files (70% fewer)
  • Before: 371s total Jest time
  • After: ~90s total Jest time — ~75% overall reduction

Files optimized

File Synths before Synths after Wall time before
task-api.test.ts 41 11 370s
task-orchestrator.test.ts 33 12 119s
ecs-agent-cluster.test.ts 10 2 34s

Why this works

CDK Template.fromStack() is the expensive operation in construct tests — it synthesizes the full CloudFormation template. The original code called it in every test() block even when the config was identical. Since Template objects are read-only (assertions don't mutate them), tests with the same input safely share a single synthesized template.

Tests requiring unique configurations (custom props, overrides) still synthesize inline.

Test plan

  • All 1789 tests pass (0 failures)
  • All 80 tests across the 3 refactored files pass with identical assertions
  • No test logic changed — only template creation moved to beforeAll
  • ESLint passes on all modified files

Closes #194

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

@scottschreckengaust scottschreckengaust requested a review from a team as a code owner May 27, 2026 00:30
@scottschreckengaust scottschreckengaust marked this pull request as draft May 27, 2026 03:44
@scottschreckengaust scottschreckengaust changed the title fix(cdk): enable isolatedModules for 18% faster Jest execution fix(cdk): optimize test suite via shared CDK template synthesis May 27, 2026
Refactors task-api.test.ts to synthesize CDK templates once per describe
block via beforeAll instead of per-test. Reduces CDK synth calls from
41 to 11 while preserving all 40 test assertions unchanged.

Before: 371s total Jest / task-api.test 370s wall clock
After:  145s total Jest / task-api.test 89s wall clock

Closes #194

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Applies the same beforeAll template-sharing pattern to:
- task-orchestrator.test.ts: 33 → 12 synths (4 shared + 8 unique)
- ecs-agent-cluster.test.ts: 10 → 2 synths (1 shared + 1 unique)

Combined with task-api.test.ts, total CDK synths across the three
heaviest suites drop from 84 to 25 (70% fewer).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(cdk): optimize Jest test suite via shared CDK template synthesis

1 participant