|
| 1 | +# Running Tests for nr-web |
| 2 | + |
| 3 | +## Docker-First Approach |
| 4 | + |
| 5 | +**All tests should be run in Docker by default.** This ensures: |
| 6 | +- Consistent environment across all developers |
| 7 | +- Same Node.js version |
| 8 | +- Proper system dependencies for Playwright |
| 9 | +- Isolated test execution |
| 10 | +- Reproducible results |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +```bash |
| 15 | +# From the nr-web directory |
| 16 | +make test |
| 17 | +``` |
| 18 | + |
| 19 | +This will: |
| 20 | +1. Build the Docker image (if needed) |
| 21 | +2. Run all tests (unit, integration, and E2E) |
| 22 | +3. Clean up the container after completion |
| 23 | + |
| 24 | +## Available Commands |
| 25 | + |
| 26 | +### Using Make (Recommended) |
| 27 | + |
| 28 | +```bash |
| 29 | +make test # Run all tests |
| 30 | +make test-watch # Watch mode for development |
| 31 | +make test-ui # Run with Vitest UI (http://localhost:51204) |
| 32 | +make test-e2e # E2E tests only |
| 33 | +make test-unit # Unit/integration tests only |
| 34 | +make test-coverage # Run with coverage report |
| 35 | +make build # Build Docker image manually |
| 36 | +make clean # Clean up Docker resources |
| 37 | +make help # Show all commands |
| 38 | +``` |
| 39 | + |
| 40 | +### Using Docker Compose Directly |
| 41 | + |
| 42 | +```bash |
| 43 | +# Run all tests |
| 44 | +docker-compose run --rm tests |
| 45 | + |
| 46 | +# Run specific test suite |
| 47 | +docker-compose run --rm tests pnpm test:local |
| 48 | +docker-compose run --rm tests pnpm test:local:e2e |
| 49 | + |
| 50 | +# Watch mode |
| 51 | +docker-compose run --rm tests pnpm test:local:watch |
| 52 | + |
| 53 | +# With UI |
| 54 | +docker-compose run --rm -p 51204:51204 tests pnpm test:local:ui |
| 55 | +``` |
| 56 | + |
| 57 | +## Local Execution (Not Recommended) |
| 58 | + |
| 59 | +If you must run tests locally (not recommended): |
| 60 | + |
| 61 | +```bash |
| 62 | +# Install dependencies |
| 63 | +pnpm install |
| 64 | + |
| 65 | +# Run tests locally |
| 66 | +pnpm test:local |
| 67 | +pnpm test:local:watch |
| 68 | +pnpm test:local:e2e |
| 69 | +``` |
| 70 | + |
| 71 | +**Warning**: Local execution may have issues: |
| 72 | +- Missing Playwright system dependencies |
| 73 | +- Different Node.js versions |
| 74 | +- Platform-specific behavior differences |
| 75 | +- Environment variable differences |
| 76 | + |
| 77 | +## CI/CD Integration |
| 78 | + |
| 79 | +In CI environments, tests automatically run in Docker: |
| 80 | + |
| 81 | +```yaml |
| 82 | +# Example GitHub Actions |
| 83 | +- name: Run tests |
| 84 | + run: | |
| 85 | + cd nr-web |
| 86 | + make test |
| 87 | +``` |
| 88 | +
|
| 89 | +## Troubleshooting |
| 90 | +
|
| 91 | +### Docker image won't build - Lockfile outdated |
| 92 | +
|
| 93 | +If you see an error about `pnpm-lock.yaml` being outdated: |
| 94 | + |
| 95 | +```bash |
| 96 | +# Update the lockfile in the monorepo root |
| 97 | +cd .. |
| 98 | +pnpm install |
| 99 | +cd nr-web |
| 100 | +
|
| 101 | +# Then rebuild |
| 102 | +make build |
| 103 | +``` |
| 104 | + |
| 105 | +Or use the convenience command: |
| 106 | +```bash |
| 107 | +make update-lockfile |
| 108 | +make build |
| 109 | +``` |
| 110 | + |
| 111 | +### Docker image won't build - Other issues |
| 112 | +```bash |
| 113 | +# Clean and rebuild |
| 114 | +make clean |
| 115 | +make build |
| 116 | +``` |
| 117 | + |
| 118 | +### Tests fail in Docker but work locally |
| 119 | +This is expected - Docker is the source of truth. Fix the tests to work in Docker. |
| 120 | + |
| 121 | +### Permission issues |
| 122 | +```bash |
| 123 | +# Clean volumes |
| 124 | +make clean |
| 125 | +``` |
| 126 | + |
| 127 | +### Port conflicts |
| 128 | +If port 8080 or 51204 are in use, modify `docker-compose.yml` to use different ports. |
0 commit comments