Skip to main content
The deno test command discovers and runs tests in your project.

Usage

deno test [OPTIONS] [FILES]...

Basic Examples

# Run all tests
deno test

# Run specific test file
deno test test.ts

# Run tests matching a pattern
deno test --filter "my test"

# Run tests with coverage
deno test --coverage=cov_profile

Test Discovery

Deno automatically discovers test files with these patterns:
  • Files ending with _test.ts, _test.tsx, _test.js, _test.jsx
  • Files ending with .test.ts, .test.tsx, .test.js, .test.jsx
  • Files named test.ts, test.tsx, test.js, test.jsx
  • Files in __tests__ directories

Filtering Options

--filter
string
Run tests with names matching this pattern (string match or regex)
# String match
deno test --filter "user login"

# Regex pattern
deno test --filter "/^user/"
--ignore
string
Ignore files matching this pattern
deno test --ignore=integration/

Execution Options

--parallel
boolean
Run test modules in parallel (default: true)
deno test --parallel
deno test --parallel=false  # Run sequentially
--fail-fast
number
Stop after N failures
# Stop after first failure
deno test --fail-fast=1

# Stop after 5 failures
deno test --fail-fast=5
--shuffle
number
Shuffle test execution order (optionally with a seed)
# Shuffle with random seed
deno test --shuffle

# Shuffle with specific seed for reproducibility
deno test --shuffle=42

Watch Mode

--watch
string
Watch for file changes and rerun tests
# Watch mode
deno test --watch

# Watch specific paths
deno test --watch=src/,tests/
--no-clear-screen
boolean
Don’t clear the screen on watch mode restart

Coverage

--coverage
string
Collect coverage data into the specified directory
deno test --coverage=cov_profile
--clean
boolean
Empty the coverage directory before running tests

Documentation Tests

--doc
boolean
Type-check code blocks in documentation
# Test code blocks in JSDoc comments
deno test --doc

# Test code blocks in markdown files
deno test --doc README.md

Type Checking

--no-run
boolean
Only type-check tests, don’t run them
deno test --no-run

Reporting

--reporter
string
Select test reporter (pretty, dot, junit, tap)
# Default pretty reporter
deno test --reporter=pretty

# Dot reporter (minimal output)
deno test --reporter=dot

# JUnit XML reporter
deno test --reporter=junit

# TAP reporter
deno test --reporter=tap
--junit-path
string
Write JUnit XML report to the specified path
deno test --junit-path=./report.xml
--hide-stacktraces
boolean
Hide stack traces in test output

Debugging

--trace-leaks
boolean
Enable tracing of leaked async operations and timers
deno test --trace-leaks

Permission Flags

All standard Deno permission flags are available:
deno test --allow-read --allow-net test.ts

Writing Tests

Basic Test

import { assertEquals } from "@std/assert";

Deno.test("string concatenation", () => {
  const result = "hello" + " " + "world";
  assertEquals(result, "hello world");
});

Async Test

import { assertEquals } from "@std/assert";

Deno.test("async operation", async () => {
  const data = await fetch("https://api.example.com/data");
  const json = await data.json();
  assertEquals(json.status, "ok");
});

Test Steps

import { assertEquals } from "@std/assert";

Deno.test("user workflow", async (t) => {
  await t.step("create user", () => {
    // Create user logic
  });

  await t.step("login user", () => {
    // Login logic
  });

  await t.step("update profile", () => {
    // Update logic
  });
});

Test Hooks

import { beforeAll, afterAll, beforeEach, afterEach } from "@std/testing/bdd";

beforeAll(() => {
  // Setup before all tests
});

afterAll(() => {
  // Cleanup after all tests
});

beforeEach(() => {
  // Setup before each test
});

afterEach(() => {
  // Cleanup after each test
});

Ignoring Tests

import { assertEquals } from "@std/assert";

Deno.test({
  name: "not implemented yet",
  ignore: true,
  fn: () => {
    // Test code
  },
});

// Or conditionally ignore
Deno.test({
  name: "Windows only test",
  ignore: Deno.build.os !== "windows",
  fn: () => {
    // Test code
  },
});

Test-only Mode

// Run only this test, ignore others
Deno.test({
  name: "focus on this test",
  only: true,
  fn: () => {
    // Test code
  },
});

Examples

Running Tests with Coverage

# Run tests and collect coverage
deno test --coverage=cov_profile

# Generate coverage report
deno coverage cov_profile

# Generate LCOV report
deno coverage cov_profile --lcov --output=cov_profile/coverage.lcov

CI/CD Integration

# Run tests with JUnit output for CI
deno test --junit-path=./test-results.xml

# Run tests with fail-fast and parallel disabled
deno test --fail-fast=1 --parallel=false

Build docs developers (and LLMs) love