Skip to content
Latchkey

node:test "subtest was not run" / Promise Not Awaited - Fix Flaky Suites in CI

Node’s built-in test runner finalizes a test when its function returns. If you create subtests (or async assertions) without awaiting them, the parent finishes first and the runner warns that a subtest "was not run" - tests pass that never actually executed.

What this error means

CI shows node:test warnings like "test did not finish before its parent" or a subtest that "was not run", and the suite is green despite assertions never executing. The cause is an un-awaited t.test(...) or async call inside a test.

node:test output
(node:12345) Warning: A subtest was created after its parent test
completed. ... 'inner check'
# or
ℹ test "outer" did not await subtest "inner"; it was not run

Common causes

Subtests created without awaiting

Calling t.test(...) without await lets the parent return before the subtest runs. The runner finalizes the parent and the subtest is dropped or warned about.

Async assertions not returned/awaited

An async test body that does not await its promises returns early, so failures resolve after the runner already recorded a pass.

How to fix it

Await subtests and async work

Await every subtest and async assertion so the parent only completes when they do.

JavaScript
import { test } from 'node:test'

test('outer', async (t) => {
  await t.test('inner check', async () => {
    // assertions here actually run before 'outer' finishes
  })
})

Make missed tests fail loudly

  1. Treat the "subtest was not run" warning as an error to fix, not noise.
  2. Return or await all promises in async test bodies.
  3. Run with a non-zero exit on warnings if your CI should fail on them.

How to prevent it

  • Await every subtest and async assertion in node:test.
  • Return promises from async test bodies.
  • Fail CI on “subtest was not run” warnings.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →