This page documents the unit and integration testing infrastructure in n8n, covering test frameworks, organization patterns, execution strategies, and coverage reporting. For end-to-end testing with Playwright, see E2E Testing. For information about the overall testing strategy and test suite organization, see Testing Strategy and Tools.
This document covers:
Diagram: Testing Architecture Components
Sources: .github/workflows/ci-pull-requests.yml turbo.json1-50 codecov.yml1-87 CONTRIBUTING.md451-482
Backend packages use Jest as the primary test framework. Jest is configured at the package level with specific setup for TypeORM, database connections, and mocking.
Diagram: Jest Test Execution Flow
The primary backend test suite is located in packages/cli/test/, with TypeScript path aliases configured for test utilities:
Sources: packages/cli/tsconfig.json1-40 CONTRIBUTING.md453-463
Frontend packages use Vitest, which provides better integration with Vite's build system and faster execution through ESM support.
Diagram: Vitest Frontend Testing Structure
Sources: CONTRIBUTING.md453-470 turbo.json29-36
Integration tests use Testcontainers to spin up real database instances and other services, ensuring tests run against actual dependencies rather than mocks.
Diagram: Testcontainers Integration Test Architecture
The Testcontainers system is documented in detail at packages/testing/containers/README.md and provides stack orchestration commands:
Sources: CONTRIBUTING.md315-377 .github/docker-compose.yml1-13
packages/
āāā cli/
ā āāā test/
ā āāā integration/ # Integration tests
ā ā āāā shared/ # @test-integration/* alias
ā ā āāā controllers/ # API endpoint tests
ā āāā unit/ # Unit tests
ā āāā shared/ # @test/* alias
ā āāā db/ # Database test utilities
ā āāā types.ts # Test type definitions
ā āāā utils/ # Test helper functions
āāā nodes-base/
ā āāā nodes/
ā āāā */
ā āāā test/ # Node-specific tests
ā āāā *.test.ts
āāā frontend/
ā āāā editor-ui/
ā āāā src/
ā āāā **/__tests__/ # Co-located tests
āāā testing/
āāā containers/ # Testcontainers utilities
āāā playwright/ # E2E tests (separate)
Sources: packages/cli/tsconfig.json10-14 CONTRIBUTING.md44-62
Test files follow consistent naming patterns:
| Pattern | Purpose | Example |
|---|---|---|
*.test.ts | Unit tests | workflow.service.test.ts |
*.integration.test.ts | Integration tests | workflow.controller.integration.test.ts |
*.spec.ts | Component specs | WorkflowCanvas.spec.ts |
test/*.ts | Test utilities | test/shared/db/users.ts |
Sources: codecov.yml81-86
Diagram: Test Command Execution Flow
From the monorepo root:
Sources: CONTRIBUTING.md453-463 turbo.json25-36
Tests are orchestrated through Turborepo with dependency management:
This configuration ensures:
Sources: turbo.json25-36
Diagram: Coverage Collection and Reporting Pipeline
Coverage is enabled through environment variables:
Sources: CONTRIBUTING.md467-470 turbo.json3 packages/testing/playwright/currents.config.ts1-15
Coverage thresholds and component tracking are configured in codecov.yml:
Component-based coverage tracking:
| Component | Paths | Threshold |
|---|---|---|
| Backend | packages/@n8n/*, packages/workflow, packages/core, packages/cli | Default: 0.5% |
| Frontend | packages/@n8n/codemirror-lang, packages/frontend | Default: 0.5% |
| Nodes | packages/nodes-base, packages/@n8n/nodes-langchain | 0% (no decrease) |
Coverage flags for carryforward:
backend-unit - Backend unit test coveragebackend-integration - Backend integration test coveragenodes-unit - Node package test coveragefrontend - Frontend unit test coveragefrontend-e2e - Frontend E2E test coverageSources: codecov.yml1-87
For VSCode integration, use the Coverage Gutters extension to visualize coverage inline.
Sources: CONTRIBUTING.md467-470 packages/testing/playwright/scripts/coverage-workflow.md1-195
Diagram: Pull Request CI Test Pipeline
The CI filter determines which tests to run based on file changes:
Sources: .github/workflows/ci-pull-requests.yml1-133
The master branch runs tests with multiple Node.js versions:
This ensures compatibility across Node.js versions while collecting coverage only once to avoid redundant uploads.
Sources: .github/workflows/ci-master.yml1-61
Here's how integration tests are typically structured in the CLI package:
Diagram: Integration Test Structure Pattern
Example from the third-party licenses controller test:
Sources: packages/cli/test/integration/controllers/third-party-licenses.controller.test.ts1-96
Common mocking patterns in backend tests:
| Mock Type | Implementation | Use Case |
|---|---|---|
| Module Mock | jest.mock('module') | Replace entire module |
| Partial Mock | jest.mock('module', () => ({ ...actual, fn: jest.fn() })) | Mock specific exports |
| Function Mock | jest.fn() | Track calls and control return values |
| Spy | jest.spyOn(object, 'method') | Monitor real implementations |
| Timer Mock | jest.useFakeTimers() | Control time-based logic |
Example from third-party licenses test:
Sources: packages/cli/test/integration/controllers/third-party-licenses.controller.test.ts5-10
The CLI package provides shared test utilities:
packages/cli/test/shared/
āāā db/
ā āāā users.ts # createOwner(), createMember(), etc.
ā āāā workflows.ts # workflow test fixtures
ā āāā credentials.ts # credential test fixtures
āāā types.ts # SuperAgentTest, test interfaces
āāā utils/
āāā testDb.ts # database test utilities
āāā testServer.ts # setupTestServer()
These utilities are imported via TypeScript path aliases:
Sources: packages/cli/tsconfig.json10-14 packages/cli/test/integration/controllers/third-party-licenses.controller.test.ts1-96
Each test should be independent and able to run in isolation:
Follow the pattern: "should [expected behavior] when [condition]"
From the contributing guide and codecov configuration:
Tests must be included in PRs per community guidelines:
PRs must include tests:
- Unit tests
- Workflow tests for nodes
- UI tests (if applicable)
Sources: CONTRIBUTING.md424-428 codecov.yml13-80
For faster test execution:
Sources: CONTRIBUTING.md383-405 turbo.json25-36
The n8n testing infrastructure provides comprehensive coverage through:
Tests are organized with clear separation between unit and integration tests, use TypeScript path aliases for test utilities, and follow consistent patterns for setup, execution, and teardown. The CI pipeline conditionally runs tests based on file changes to optimize build times while maintaining quality standards.
Sources: .github/workflows/ci-pull-requests.yml1-133 .github/workflows/ci-master.yml1-61 CONTRIBUTING.md451-482 turbo.json1-50 codecov.yml1-87
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.