• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash / 21475376490
86%
master: 91%

Build:
Build:
LAST BUILD BRANCH: main
DEFAULT BRANCH: master
Ran 29 Jan 2026 11:01AM UTC
Jobs 1
Files 1137
Run time 2min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

29 Jan 2026 10:53AM UTC coverage: 86.197% (-0.01%) from 86.211%
21475376490

push

github

web-flow
chore: don't mount a separate router for the conditional middleware (#11268)

Discovered in
https://github.com/bricks-software/unleash-enterprise/pull/762, there's
an issue with using fake timers and the old implementation of the
condititonal middleware.

By changing the implementation to not use a Router, but instead just a
plain function, we can avoid the issue with fake timers.

## AI explanation

According to Claude:

The issue is the interaction between **`vi.useFakeTimers()`** and
**Express `Router`**.

When Vitest (or Jest) fake timers are active, they replace the global
`setTimeout`, `setInterval`, `setImmediate`, and related functions with
mocked versions that only advance when you explicitly tell them to
(e.g., `vi.advanceTimersByTime`).

### Why the Router causes a hang

Express's `Router` internally uses **asynchronous scheduling** —
specifically `setImmediate` or `process.nextTick` in certain code paths
for dispatching requests through its middleware stack. When you wrap
your middleware in a `Router`:

```typescript
const router = Router();
router.use((req, res, next) => {
    // ...
});
return router;
```

The Router's internal dispatch mechanism may schedule work via
`setImmediate`. With fake timers active, **that `setImmediate` never
fires** because it's been replaced by a mock that waits for
`vi.advanceTimersByTime()` or `vi.runAllTimers()`. The HTTP request
enters the Router and never comes back — it just hangs.

### Why a plain function works

A plain handler function:

```typescript
return (req, res, next) => {
    if (condition()) {
        middleware(req, res, next);
    } else {
        next();
    }
};
```

...runs **synchronously inline** in the existing middleware chain.
There's no sub-router dispatch, no `setImmediate`, nothing for fake
timers to intercept. It just calls `next()` directly and everything
proceeds.

1692 of 1904 branches covered (88.87%)

1 of 1 new or added line in 1 file covered. (100.0%)

3 existing lines in 2 files now uncovered.

14288 of 16576 relevant lines covered (86.2%)

871.38 hits per line

Uncovered Existing Lines

Lines Coverage ∆ File
1
85.94
-0.78% src/lib/services/api-token-service.ts
2
81.63
-1.02% src/lib/features/playground/feature-evaluator/constraint.ts
Jobs
ID Job ID Ran Files Coverage
1 21475376490.1 29 Jan 2026 11:01AM UTC 1137
86.2
GitHub Action Run
Source Files on build 21475376490
  • Tree
  • List 1137
  • Changed 3
  • Source Changed 1
  • Coverage Changed 3
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #21475376490
  • 64e816cc on github
  • Prev Build on main (#21474278767)
  • Next Build on main (#21475672184)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc