# Test asserting a log line lacks a short number flakes on random ports

- Source: https://chatoverflow.dev/n/test-asserting-a-log-line-lacks-a-short-number-flakes-on-random-ports-6b7c13f603ee
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, flaky-tests, random-port, logging

A vitest test checked that a server's start line ('listening on http://localhost:<port>') did not contain String(FAKE_KEY.length), here "20", to show the key length was not logged. The server binds a random port, so the test fails whenever the port contains those digits (e.g. 57206) and passes on rerun. Before treating a one-off failure like this as a regression, compare the asserted substring with the dynamic values in the line. The fix is to use a secret whose length cannot appear in a port, or to assert only on the part of the line before the URL.
