test(scripts): add unit tests for retry/rate-limit utils + fix Jest config under ESM#9561
Open
ash-balla wants to merge 1 commit into
Open
test(scripts): add unit tests for retry/rate-limit utils + fix Jest config under ESM#9561ash-balla wants to merge 1 commit into
ash-balla wants to merge 1 commit into
Conversation
…t config under ESM - Add test/retry_utils.test.ts covering retryWithBackoff: success, retry-then-succeed, non-retryable errors, retry exhaustion, retryable detection (code/status/name/message), custom retryableErrors, and exponential backoff capping. - Add test/rate_limit_utils.test.ts covering processBatch (ordering, empty input, oversized batch, in-batch parallelism) and checkRateLimit (10-call cadence, pause below threshold, no pause above, error tolerance). - Rename jest.config.js to jest.config.cjs so the config loads correctly given package.json "type": "module" (previously threw "module is not defined in ES module scope", which prevented any jest tests from running). All 3 suites pass: 34 tests, jest exit code 0.
dd9a608 to
f61dc06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds unit tests for two previously-untested utility modules in
scripts/, and fixes the Jest configuration so the test runner actually works.While adding tests I found that the existing Jest setup could not run at all:
jest.config.jsused CommonJSmodule.exports, butscripts/package.jsondeclares"type": "module", so Node parsed the config as ESM and threw:This prevented every Jest test (including the existing
test/data_models.test.ts) from executing — consistent with the "Unit Tests (To be implemented)" note inscripts/README.md. Renaming the config tojest.config.cjsresolves it (Jest auto-discovers.cjs).Changes
scripts/jest.config.js→scripts/jest.config.cjs(same contents) so the config loads as CommonJS under"type": "module".scripts/test/retry_utils.test.ts— 13 tests forretryWithBackoff:maxRetries; returns the last error)error.code,error.status,error.name, and message textretryableErrorslist (and overrides defaults)maxDelaycapping (delays[100, 200, 400, 500])scripts/test/rate_limit_utils.test.ts— 8 tests:processBatch: preserves order across batches, handles empty input, handles an oversized batch size, and runs items within a batch in parallelcheckRateLimit: queries the API once per 10 calls, pauses when remaining is below threshold, does not pause when above, and tolerates a failing rate-limit lookup without throwingTest Results
All suites pass:
Jest exit code
0.Notes
test/data_models.test.tsconventions (TypeScript,describe/it, imports without.jsextension).