This guide covers how to run tests in Nuda Kit using the Japa test runner.
Before running tests, ensure:
npm install in backendcd backend
# Run all tests
node ace test
# Or using npm script
npm test
Nuda Kit has two test suites configured:
| Suite | Directory | Timeout | Purpose |
|---|---|---|---|
unit | tests/unit/ | 2 seconds | Isolated unit tests |
functional | tests/functional/ | 30 seconds | API/integration tests |
# Run only functional tests
node ace test --suite=functional
# Run only unit tests
node ace test --suite=unit
# Run specific test file
node ace test tests/functional/users/create_user.spec.ts
# Run all user-related tests
node ace test --files="**/users/*.spec.ts"
# Run all team-related tests
node ace test --files="**/teams/*.spec.ts"
# Run all billing tests
node ace test --files="**/billing/*.spec.ts"
# Run tests matching a pattern
node ace test --match="creates a new user"
# Run tests containing "validation"
node ace test --match="validation"
Re-run tests automatically when files change:
node ace test --watch
This is useful during development to get instant feedback.
node ace test
Shows a summary with pass/fail counts.
# Show all test names
node ace test --reporter=spec
# Dot reporter (one dot per test)
node ace test --reporter=dot
Stop on first failure:
node ace test --bail
Useful for CI/CD pipelines or when debugging.
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: app_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
working-directory: backend
- name: Run tests
run: npm test
working-directory: backend
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: root
DB_PASSWORD: root
DB_DATABASE: app_test
QUEUE_REDIS_HOST: localhost
QUEUE_REDIS_PORT: 6379
Tests are configured in adonisrc.ts:
tests: {
suites: [
{
files: ['tests/unit/**/*.spec(.ts|.js)'],
name: 'unit',
timeout: 2000, // 2 seconds
},
{
files: ['tests/functional/**/*.spec(.ts|.js)'],
name: 'functional',
timeout: 30000, // 30 seconds
},
],
forceExit: false,
}
For slow tests, increase the timeout:
// In test file
test('slow operation', async () => {
// ...
}).timeout(60000) // 60 seconds
| Command | Description |
|---|---|
node ace test | Run all tests |
node ace test --suite=functional | Run functional tests only |
node ace test --files="**/users/*" | Run tests matching pattern |
node ace test --match="login" | Run tests with "login" in title |
node ace test --watch | Watch mode |
node ace test --bail | Stop on first failure |
node ace test --reporter=spec | Verbose output |
node ace test --help | Show all options |
Ensure Docker is running:
docker compose up -d
Check for unclosed connections or pending promises. Use --forceExit as a workaround:
node ace test --forceExit
--bail to stop on first failureIf port 5432 is in use, stop other PostgreSQL instances:
# Check what's using the port
lsof -i :5432
# Or use different port in .env.test
DB_PORT=5433