test: Fix flaky unit tests across three packages (no-changelog)#28336
Merged
shortstacked merged 1 commit intomasterfrom Apr 13, 2026
Merged
test: Fix flaky unit tests across three packages (no-changelog)#28336shortstacked merged 1 commit intomasterfrom
shortstacked merged 1 commit intomasterfrom
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bundle ReportBundle size has no change ✅ Affected Assets, Files, and Routes:view changes for bundle: editor-ui-esmAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Performance ComparisonComparing current → latest master → 14-day baseline docker-stats
Idle baseline with Instance AI module loaded
Memory consumption baseline with starter plan resources
How to read this table
|
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Architecture diagram
sequenceDiagram
participant Test as Test Runner (Jest/Vitest)
participant SUT as System Under Test
participant Mocks as Mocking Layer (Jest/Nock/Vi)
participant Infra as External Infra (DB/CDN/API)
Note over Test,Infra: Flow 1: ExecutionPersistence (Deterministic Timestamps)
Test->>Mocks: NEW: jest.useFakeTimers()
Test->>SUT: deleteInFlightExecution()
SUT->>SUT: Calculate deletedAt (now - buffer)
SUT->>Infra: update(executionId, { deletedAt })
Test->>Test: NEW: Assert deletedAt matches fixed mock time
Test->>Mocks: jest.useRealTimers()
Note over Test,Infra: Flow 2: TypeScript Worker (Cache Isolation)
Test->>Mocks: NEW: vi.mock('@/app/plugins/cache')
Test->>SUT: Initialize Worker
SUT->>Mocks: Get types from cache
alt NEW: Cache Mocked
Mocks-->>SUT: Return empty object/mocked types
else OLD: Cache Miss (Flaky Path)
SUT->>Infra: Open IndexedDB (fake-indexeddb)
SUT->>Infra: Fetch from cdn.jsdelivr.net (Timeout Risk)
end
SUT-->>Test: Worker ready (9ms)
Note over Test,Infra: Flow 3: GoogleSheetsTrigger (Network Isolation)
Test->>Mocks: NEW: nock.disableNetConnect()
Test->>SUT: Execute Trigger Node
SUT->>Mocks: HTTP GET /spreadsheets/...
alt Mock Match
Mocks-->>SUT: Return 200 OK (Defined fixture)
else NEW: Unmatched Request
Mocks-->>SUT: Throw NetConnectNotAllowedError
else OLD: Request Leak (Flaky Path)
Mocks->>Infra: Call real Google Sheets API
end
SUT-->>Test: Return node output
Test->>Mocks: NEW: nock.cleanAll() / enableNetConnect()
schrothbn
approved these changes
Apr 13, 2026
Contributor
|
Got released with |
Aijeyomah
pushed a commit
to Aijeyomah/n8n
that referenced
this pull request
Apr 15, 2026
…io#28336) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Fix three flaky unit tests that accounted for ~200 CI failures across 40+ branches in the last 7 days (data from Codecov test analytics).
1.
ExecutionPersistence— timestamp off-by-one (15 failures / 15 branches)The test captured
Date.now()after calling the function under test, then asserted the backdateddeletedAtwas<=that value minus the buffer. When the clock ticked by 1ms between the implementation's and the test'sDate.now()calls, the assertion failed. Fixed by using Jest fake timers soDate.now()is deterministic.2.
TypeScript Worker— CDN fetch timeout (8 failures / 8 branches)The test didn't mock
indexedDbCache, so it opened real IndexedDB viafake-indexeddb. When the luxon type cache missed, the worker tried to fetch types fromcdn.jsdelivr.net, which timed out under CI network constraints. Fixed by mocking the cache module with a cache hit, eliminating both IndexedDB and network overhead (tests now run in 9ms vs timing out at 5000ms).3.
GoogleSheetsTrigger— missing nock isolation (23 failures each × 5 tests / 8 branches)The test file was missing
nock.disableNetConnect(). WhileglobalSetup.tscalls it, Jest runs global setup in a separate context from test workers. Without it, unmatched requests could leak to the real Google Sheets API. Fixed by adding proper nock lifecycle hooks (disableNetConnect,cleanAll,enableNetConnect).Related Linear tickets, Github issues, and Community forum posts
N/A — identified via Codecov test analytics API flaky test analysis.
Review / Merge checklist