Run tests across the backend and frontend of the To-Do List WebApp
This skill provides guidance for running tests across the entire To-Do List WebApp project.
The project uses:
Run all tests for both backend and frontend:
npm test
This will:
For development, run tests in watch mode to auto-rerun on file changes:
# Backend tests in watch mode
cd backend && npm run test:watch
# Frontend tests in watch mode
cd frontend && npm run test:watch
npm run test:backend
Or from the backend directory:
cd backend
npm test
cd backend
npm test -- path/to/test-file.test.js
cd backend
npm run test:coverage
Coverage report will be generated in backend/coverage/.
Backend tests are located in:
backend/tests/ - Main test directory*.test.js or *.spec.jsnpm run test:frontend
Or from the frontend directory:
cd frontend
npm test
Vitest provides a UI for better test visualization:
cd frontend
npm run test:ui
cd frontend
npm run test:coverage
Coverage report will be generated in frontend/coverage/.
Frontend tests are located in:
frontend/src/test/ - Main test directoryComponent.test.jsx*.test.jsx or *.spec.jsxnpm run lint
This runs ESLint on both backend and frontend.
npm run lint:backend
npm run lint:frontend
npm run lint:fix
This will automatically fix any auto-fixable linting issues.
npm run format:check
npm run format
This runs Prettier on all JavaScript, JSX, JSON, Markdown, CSS, and YAML files.
Before committing, run:
# 1. Format code
npm run format
# 2. Fix linting issues
npm run lint:fix
# 3. Run tests
npm test
Run a complete verification (useful before creating a PR):
# Format code
npm run format
# Lint all code
npm run lint
# Run all tests
npm test
# Build production bundles (optional)
npm run build
// backend/tests/example.test.js
const request = require('supertest');
const app = require('../src/app');
describe('Example API Tests', () => {
it('should return health status', async () => {
const response = await request(app).get('/api/health');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('status', 'ok');
});
});
// frontend/src/components/Example.test.jsx
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import Example from './Example';
describe('Example Component', () => {
it('renders correctly', () => {
render(<Example />);
expect(screen.getByText('Hello')).toBeInTheDocument();
});
});
Ensure you have test environment files:
backend/.env.test - Test environment for backendfrontend/.env.test - Test environment for frontendBackend tests should use a separate test database. Check backend/.env.test:
MONGODB_URI=mongodb://localhost:27017/todolist-test
If tests fail due to port conflicts, ensure no development servers are running.
Aim for:
Check coverage with:
# Backend coverage
cd backend && npm run test:coverage
# Frontend coverage
cd frontend && npm run test:coverage
cd backend
node --inspect-brk node_modules/.bin/jest --runInBand
Then open Chrome DevTools at chrome://inspect.
cd frontend
npm run test:debug
After running tests:
backend/coverage/ and frontend/coverage/