This project includes comprehensive test coverage using a real Elasticsearch instance via Docker.
- Node.js (>= 18.x)
- Docker and Docker Compose
- npm or yarn
The simplest way to run the full test suite:
npm run docker:testThis command will:
- Start Elasticsearch in Docker on port 9201
- Wait for Elasticsearch to be ready
- Run the complete test suite
- Clean up the Docker container
If you want more control over the testing process:
# Start Elasticsearch
npm run docker:up
# Wait for it to be ready (optional, runs automatically in docker:test)
npm run docker:wait
# Run tests against the Docker instance
npm run test:integration
# Clean up when done
npm run docker:down- Start Elasticsearch:
npm run docker:up - Stop and clean up:
npm run docker:down - View logs:
npm run docker:logs - Wait for readiness:
npm run docker:wait
ES_VERSION: Elasticsearch version to use (default: 8.15.0)ELASTICSEARCH_URL: Elasticsearch connection URL (default: http://localhost:9201)
The test suite supports multiple Elasticsearch versions:
- 5.0.x
- 6.0.x
- 7.0.x
- 8.0.x (default)
test/- Main test files using@feathersjs/adapter-teststest-utils/- Test utilities and schema definitionstest-utils/schema-*.js- Version-specific Elasticsearch schemas
Test coverage reports are generated with nyc and displayed after test completion.
# Run tests with coverage
npm test
# Run only coverage (after tests)
npm run coverageIf you see an error like Bind for 0.0.0.0:9201 failed: port is already allocated:
# Check what's using the port
lsof -i :9201
# Stop any existing Elasticsearch containers
npm run docker:down
# Or manually stop the container
docker ps
docker stop <container-id>
# Clean up all stopped containers
docker container pruneIf the Elasticsearch container fails to start:
# Check container logs
npm run docker:logs
# Common issues:
# 1. Insufficient memory - Elasticsearch needs at least 2GB RAM
# 2. Docker daemon not running - start Docker Desktop
# 3. Previous container still running - run docker:down first
# Reset everything
npm run docker:down
docker system prune -f
npm run docker:upOn Linux, if you see permission errors:
# Fix Docker socket permissions
sudo chmod 666 /var/run/docker.sock
# Or add your user to docker group
sudo usermod -aG docker $USER
newgrp dockerIf tests fail with ECONNREFUSED:
# 1. Verify Elasticsearch is running
curl http://localhost:9201/_cluster/health
# 2. Wait longer for Elasticsearch to be ready
npm run docker:wait
# 3. Check if correct port is being used
echo $ELASTICSEARCH_URL # Should be http://localhost:9201
# 4. Manually wait and check status
docker logs elasticsearchIf tests timeout waiting for Elasticsearch:
# Increase wait time in docker:wait script
# Or manually check when it's ready
while ! curl -s http://localhost:9201/_cluster/health > /dev/null; do
echo "Waiting for Elasticsearch..."
sleep 2
done
echo "Elasticsearch is ready!"If you see compatibility errors:
# Check your ES version
curl http://localhost:9201/ | grep number
# Set explicit version
ES_VERSION=8.15.0 npm run test:integration
# For ES 9.x testing
ES_VERSION=9.0.0 ELASTICSEARCH_URL=http://localhost:9202 npm run test:es9To run specific tests:
# Run only one test file
npm run mocha -- test/index.test.js
# Run tests matching a pattern
npm run mocha -- --grep "should create"
# Run with specific ES version
ES_VERSION=8.15.0 ELASTICSEARCH_URL=http://localhost:9201 npm run mocha -- --grep "should find"To see detailed output:
# Enable debug logging
DEBUG=feathers-elasticsearch* npm test
# Enable Elasticsearch client debugging
NODE_ENV=development npm test
# Run single test with full output
npm run mocha -- --grep "specific test" --reporter specIf tests suddenly fail:
# 1. Rebuild the project
npm run clean
npm run build
# 2. Restart Elasticsearch (clears all data)
npm run docker:down
npm run docker:up
# 3. Verify dependencies
npm ci
# 4. Run tests with fresh install
rm -rf node_modules package-lock.json
npm install
npm testIf coverage is not generated:
# Make sure nyc is installed
npm ls nyc
# Run coverage explicitly
npm run clean
npm run build
npm run coverage
# Check coverage output
open coverage/index.html # macOS
xdg-open coverage/index.html # LinuxIf you see syntax errors or unexpected behavior:
# Check Node version (needs >= 18.x)
node --version
# Use nvm to switch versions
nvm install 18
nvm use 18If imports fail:
# Clean install
rm -rf node_modules package-lock.json
npm install
# Verify peer dependencies
npm ls @elastic/elasticsearchIf CI tests fail but local tests pass:
- Check the ES version matrix in
.github/workflows/test-matrix.yml - Ensure all ES versions are compatible with your changes
- Test locally with the same ES version:
ES_VERSION=8.15.0 npm run test:integration ES_VERSION=9.0.0 npm run test:es9
If tests pass/fail intermittently:
# Run tests multiple times
for i in {1..10}; do npm test || break; done
# Increase timeouts in problematic tests
# Check for race conditions in bulk operations
# Ensure proper cleanup in afterEach hooksIf you're still experiencing issues:
- Check Elasticsearch documentation
- Review FeathersJS adapter guide
- Open an issue on GitHub
- Include:
- Node version (
node --version) - Elasticsearch version (
curl http://localhost:9201/) - Error messages and stack traces
- Steps to reproduce
- Node version (