resume/tests/README.md

98 lines
2.6 KiB
Markdown

# Resume Site Tests
This directory contains tests for the resume site.
## Directory Structure
- `unit/`: Unit tests for JavaScript files and other components
- `integration/`: Integration tests that test components working together
- `e2e/`: End-to-end tests that simulate user interactions
- `*.test.js`, `*.spec.js`: Playwright test files
- `lighthouse.js`: Lighthouse performance and accessibility tests
- `serve.js`: Simple Node.js server for testing
- `server.js`: Alternative server implementation
- `pre-test-setup.sh`: Script to set up the test environment, including updating CSP hashes
## Running Tests
To run all tests:
```bash
./run-all-tests.sh
```
Or using npm:
```bash
npm test
```
This will:
1. Run the pre-test setup script to update CSP hashes
2. Check if the server is running
3. Run all shell script tests
4. Run Playwright tests if available
5. Run Lighthouse tests
## Content Security Policy (CSP) Testing
The CSP hash update process is an important part of the testing framework. It ensures that:
1. All JavaScript and CSS files have integrity hashes
2. All inline styles have proper CSP hashes
3. The Caddyfile and HTML files have the correct CSP headers/meta tags
The `pre-test-setup.sh` script runs the `update-csp-hashes.sh` script to update all CSP hashes before running the tests. This ensures that any changes to the website are properly reflected in the CSP hashes.
The `csp-hash-test.sh` integration test checks if the CSP hash update process is working properly by verifying that:
- CSP headers are present in the response
- CSP headers contain the required directives
- JavaScript and CSS files have integrity attributes
- HTML files have CSP meta tags
## Running Specific Tests
### JavaScript Tests
```bash
npm run test:js
```
### Lighthouse Tests
```bash
npm run test:lighthouse
```
### Starting the Test Server
```bash
npm run serve
```
## Adding New Tests
### Shell Script Tests
Add new test scripts to the appropriate directory:
- `unit/`: For unit tests
- `integration/`: For integration tests
- `e2e/`: For end-to-end tests
Shell script tests should:
- Be executable bash scripts
- Return exit code 0 for success, non-zero for failure
- For integration and e2e tests, accept a base URL as the first argument
### Playwright Tests
Add new Playwright tests with the `.test.js` or `.spec.js` extension in the tests directory.
## Test Requirements
As per the project guidelines, all tests must:
- Pass for both mobile and desktop viewports
- Maintain Lighthouse scores: 100/100 for accessibility and SEO
- Include meaningful assertions, not placeholders