test(dataforseo): mock the google-ads section so the SDK stays out of the run - #153
Open
Nordalux wants to merge 1 commit into
Open
test(dataforseo): mock the google-ads section so the SDK stays out of the run#153Nordalux wants to merge 1 commit into
Nordalux wants to merge 1 commit into
Conversation
… the run `client.test.ts` mocks every section module the client wraps, but the sections barrel that `loadDataforseoSections()` imports also re-exports from `google-ads.ts`, which was not mocked. That module statically imports `dataforseo-client`, so the ~3 MB SDK was loaded for real on the first test that touched the client — the exact subtree the lazy boundary in client.ts exists to keep out. The cost lands entirely on whichever test runs first. Locally that is "skips billing in non-hosted mode" at ~2.1s while the next test over the same code path takes 1-2ms, and under a full parallel suite run it crosses the 5s default timeout and fails. Mocking the module alongside the others drops that test from ~2100ms to ~17ms and takes suite test time from ~18s to ~10s. All 18 tests in the file still pass, and the assertions are untouched.
sorcerai
approved these changes
Jul 28, 2026
sorcerai
left a comment
There was a problem hiding this comment.
Reviewed exact current diff. This isolates the test from the google-ads barrel re-export and removes the DataForSEO SDK load that causes the suite timeout; production code is unchanged.
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.
Problem
src/server/lib/dataforseo/client.test.ts > meterDataforseoCall with split balances > skips billing in non-hosted modefails intermittently in a fullpnpm test:cirun withTest timed out in 5000ms. It passes when the file is run on its own.The test itself does almost nothing — one mocked call, three assertions, no timers. The time is spent loading a module.
Cause
client.test.tsmocks the section modules the client wraps (labs,serp,business,backlinks,lighthouse,ai) under the comment "Mock every section module the client wraps". But the client does not reach those modules directly — it reaches them throughloadDataforseoSections(), a single lazyimport("@/server/lib/dataforseo/sections"), and that barrel also re-exports fromgoogle-ads.ts:google-ads.tsis the one section module the test does not mock, and it statically importsdataforseo-client:So the ~3 MB SDK gets loaded for real — precisely the subtree the lazy boundary in
client.tsexists to keep out of the graph:The whole cost is charged to whichever test first touches the client. That happens to be
skips billing in non-hosted mode, which is why the failure always names that test even though nothing is wrong with it. Measured locally, three consecutive isolated runs:skips billing in non-hosted modeUnder a 12-thread suite run the 2.1s crosses the 5s default timeout and the file goes red.
Change
Mock
@/server/lib/dataforseo/google-adsalongside the other section modules. No assertion, fixture, or production file is touched.Result
Full
pnpm test:ci, both runs warm, same machine:All 18 tests in the file still pass.
pnpm ci:checkpasses.Note
The underlying sharp edge is that the mock list has to track the barrel's re-exports rather than the client's own wrappers — the two differ by exactly this module, and nothing fails loudly when they drift, it just gets slow. If you'd like a guard against that (for example a
sections.tsre-export assertion in the test, or moving the SDK-free type re-exports out of the barrel), happy to follow up in a separate PR.