Skip to main content

Testing Overview

n8n employs a comprehensive testing strategy with multiple layers:
  • Unit Tests: Jest for backend and nodes, Vitest for frontend
  • Integration Tests: Jest with mocked dependencies
  • E2E Tests: Playwright for full UI and API testing
  • Workflow Tests: JSON-based integration tests for nodes

Running Tests

All Tests

Run all tests across the monorepo:
Run tests for affected packages only:

Package-Specific Tests

Run tests for a specific package:
1

Navigate to the package

2

Run the tests

Always run tests from within the package directory. Running pnpm test from the monorepo root runs all tests, which can be time-consuming.

Specific Test Files

Run a specific test file:
Run tests matching a pattern:

Unit Testing with Jest

Backend Unit Tests

n8n uses Jest for backend unit tests with the following conventions:

Frontend Unit Tests

Frontend tests use Vitest:

Snapshot Updates

If tests fail due to expected changes, update snapshots:
Or press u in Jest watch mode.

Code Coverage

n8n tracks code coverage on Codecov.

Local Coverage

Generate coverage reports locally:
View coverage in the coverage/ folder or use the VSCode Coverage Gutters extension.

E2E Testing with Playwright

n8n uses Playwright for comprehensive E2E testing.

Running E2E Tests

Test Architecture

Playwright tests follow a layered architecture:

Page Object Pattern

Page objects encapsulate UI interactions:

Composables

Composables orchestrate multi-step business workflows:

Writing E2E Tests

Test Tags

Use tags to control test execution:

Test Isolation

For tests requiring isolated databases:
For per-test database reset:
Tests with @db:reset only run in container mode, not locally.

Node Workflow Tests

Nodes include JSON-based workflow tests:
Tests verify node behavior with real workflow execution.

Mocking Dependencies

Server Mocking with nock

Backend tests use nock for HTTP mocking:

Playwright Proxy Server

E2E tests can use proxy server for API mocking:

Testing Best Practices

Mock all external dependencies in unit tests. Never make real HTTP requests or database calls.
Confirm test cases with the team before writing complex unit tests for new features.
Always run typecheck before committing:
Use unique identifiers in E2E tests to avoid conflicts:
Never use waitForTimeout - use proper Playwright waiting strategies:

Debugging Tests

Playwright Debugging

Jest Debugging

Then attach your debugger (VS Code, Chrome DevTools, etc.)

CI/CD Testing

Tests run automatically on CI:

Test Maintenance

The janitor tool helps maintain test quality:
See packages/testing/playwright/README.md for more details.

Next Steps