denoland/deno · error

Test failed because the "only" option was used

Error message

Test failed because the "only" option was used

What it means

The Deno language server's test runner (backing the VS Code Deno extension's Test Explorer) fails the entire run if any executed module used the "only" filter (Deno.test(..., { only: true }, ...) or it.only). This is deliberate: an only-filtered run skips most tests, and reporting it green could hide failures. The flag latches when the test event stream reports plan.used_only for any module (cli/lsp/testing/execution.rs:417) and the error is returned after the summary is printed.

Source

Thrown at cli/lsp/testing/execution.rs:503

              // `TestEvent::Result`.
            }
            test::TestEvent::Completed => {
              reporter.report_completed();
            }
            // LSP-driven test runs never use `--update-snapshots`.
            test::TestEvent::SnapshotSummary(_) => {}
            test::TestEvent::ForceEndReport => {}
            test::TestEvent::Sigint => {}
            test::TestEvent::Exit(_) => {}
            test::TestEvent::IsolateExit(_, _) => {}
          }
        }

        let elapsed = Instant::now().duration_since(earlier);
        reporter.report_summary(&summary, &elapsed);

        if used_only {
          return Err(anyhow!(
            "Test failed because the \"only\" option was used"
          ));
        }

        if summary.failed > 0 {
          return Err(anyhow!("Test failed"));
        }

        Ok(())
      })
    };

    let (join_results, result) = future::join(join_stream, handler).await;

    // propagate any errors
    for join_result in join_results {
      join_result??;
    }

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Search the workspace for `only: true` and `.only(` in test files, remove the flags, and re-run.
  2. Use the Test Explorer's run-single-test action or `deno test --filter <name>` to focus a test instead of using only.
  3. Add a pre-commit/pre-run grep or lint step for only-markers in test files so leftovers are caught before a run.

Example fix

// before
Deno.test("adds numbers", { only: true }, () => {
  assertEquals(1 + 1, 2);
});

// after
Deno.test("adds numbers", () => {
  assertEquals(1 + 1, 2);
});
Defensive patterns

Strategy: validation

Validate before calling

// Scan test sources before an IDE run so a leftover `only` doesn't fail
// the whole LSP test run.
const ONLY_PATTERNS = [/\bonly\s*:\s*true/, /\.only\s*\(/, /\bit\.only\b/];
export function assertNoOnlyFlags(source, path) {
  for (const re of ONLY_PATTERNS) {
    if (re.test(source)) {
      throw new Error(`${path} contains an 'only' test filter — remove it before running the suite`);
    }
  }
}

Try / catch

// When driving LSP test runs programmatically, branch on this exact failure.
try {
  await runTests(session, modules);
} catch (err) {
  if (err?.message?.includes('"only" option was used')) {
    // the executed subset may have passed, but the run must not count as green:
    // strip `only` flags and re-run, or mark the run as blocked
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Starting a test run from the IDE Test Explorer while any test in the run scope declares { only: true } (or a .only variant for BDD-style tests). The run executes only that subset, then the handler returns this error instead of Ok even though the executed tests may all have passed.

Common situations: A developer isolates one test with only: true during debugging and forgets to remove it before running the suite in the IDE; teams that treat IDE test runs as authoritative gate their PRs on a red run caused by a leftover filter.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/7686d41187822c55. Report an issue: GitHub.