From 14a997282c05348e44ee5d2f0e5478a5ff76aa52 Mon Sep 17 00:00:00 2001 From: recursivefunk Date: Tue, 21 Apr 2026 21:17:44 -0400 Subject: [PATCH] Cover AWS_REGION default branch in use() Adds a test that deletes process.env.AWS_REGION before calling env.use(), with a spy SecretsManagerClient that captures the region passed to its constructor. This exercises the `|| 'us-east-1'` fallback that was previously unreached, taking branch coverage on src/index.js to 100%. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test.js b/test/test.js index 610ec0d..6ce645b 100644 --- a/test/test.js +++ b/test/test.js @@ -47,6 +47,26 @@ test('it uses secrets manager (happy path)', async (t) => { t.end(); }); +test('use() defaults region to us-east-1 when AWS_REGION is unset', async (t) => { + let capturedRegion; + class SpyClient { + constructor ({ region }) { capturedRegion = region; } + send () { + return Promise.resolve({ SecretString: JSON.stringify({ spyVal: 'x' }) }); + } + } + const awsSecretsManager = { SecretsManagerClient: SpyClient, GetSecretValueCommand }; + const saved = process.env.AWS_REGION; + delete process.env.AWS_REGION; + try { + await env.use(awsSecretsManager, 'my-secret'); + t.equals(capturedRegion, 'us-east-1'); + } finally { + process.env.AWS_REGION = saved; + } + t.end(); +}); + test('it gets an IP address', (t) => { const ip = env.getIP('VALID_IP'); t.equals(ip, '192.168.1.60');