| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
The tests subject contains utilities, helpers, and infrastructure to support automated testing across docs.github.com. This includes test helpers, mock servers, schema validation, and shared testing patterns.
Note
This directory should not include test suites. Test files belong in their respective subject directories (e.g., src/search/tests/, src/frame/tests/).
This subject is responsible for:
Tests are written using Vitest for unit and integration tests, and Playwright for end-to-end browser tests.
Test-only dependencies are optional to keep standard installs faster:
npm ci --include=optionalImportant: Do NOT run npm test without a path argument. Tests must be run per-suite because different suites require different environment variables. Running all tests at once will produce many false failures.
Important: Run npm run build before running tests. Many test suites depend on Next.js build artifacts. Without a build, tests may fail with Could not find a production build or other confusing errors.
Always target the specific suite for the code you changed:
# By directory (recommended)
npm test -- src/search/tests/
# Single test file
npm test -- src/versions/tests/versions.tsSome suites require environment variables or tests will fail with 404s or content mismatches. These suites have dedicated npm scripts that set the required variables automatically:
npm run test:article-api
npm run test:fixtures
npm run test:landings
npm run test:languages # requires Elasticsearch running
npm run test:search # requires Elasticsearch runningFor the content-linter suite, you can optionally scope to changed files:
DIFF_FILES="content/foo.md content/bar.md" \
npm test -- src/content-linter/tests/All other suites (e.g., versions, redirects, rest, frame, content-render) can be run without special environment variables.
The search and languages test suites require Elasticsearch on localhost:9200. To start it with Docker:
docker run -d \
-p 127.0.0.1:9200:9200 \
-e 'discovery.type=single-node' \
-e 'xpack.security.enabled=false' \
--name es-local \
docker.elastic.co/elasticsearch/elasticsearch:8.12.0Wait for it to be ready, then index the test fixtures:
curl --silent --fail http://localhost:9200 # verify ES is up
ELASTICSEARCH_URL=http://localhost:9200/ npm run index-test-fixturesAfter that, npm run test:search and npm run test:languages will work.
See .github/workflows/test.yml for the full CI matrix and per-suite configuration.
Continuously re-runs tests on file changes:
npm test -- --watchBy default, console.log is suppressed. To see output:
npm test -- <TEST_NAME> --silent=falseSome tests require a production build:
npm run build
npm test -- src/<suite>/tests/Error: Could not find a production build means you need to run npm run build.
Tests that make HTTP requests to localhost:4000:
Manual server for debugging:
# Terminal 1
NODE_ENV=test PORT=4000 tsx src/frame/server.ts
# Terminal 2
START_VITEST_SERVER=false vitest src/versions/testsUnit tests - Test individual functions/modules:
import { describe, test, expect } from 'vitest'
describe('myFunction', () => {
test('returns expected value', () => {
expect(myFunction('input')).toBe('output')
})
})Integration tests - Test HTTP endpoints:
import { get } from '@/tests/helpers/e2etest'
test('GET /search returns results', async () => {
const res = await get('/search?query=test')
expect(res.statusCode).toBe(200)
})Playwright tests - Browser automation:
test('search works in browser', async ({ page }) => {
await page.goto('/search')
await page.fill('input[name="query"]', 'test')
// ...assertions
})Middleware errors are suppressed by default in tests. To see full errors:
export DEBUG_MIDDLEWARE_TESTS=true
vitest src/shielding/testsnpm run lintTests should be co-located with their subject:
Shared utilities belong in src/tests/:
Tests run automatically in GitHub Actions on pull requests and merge groups. Each test suite runs as a separate matrix job with its own environment variables—see .github/workflows/test.yml for the full configuration. Locally, always target a specific suite rather than running all tests at once.
Tests fail with missing build: Run npm run build before tests.
Tests hang or timeout: Check if server started correctly. Use DEBUG_MIDDLEWARE_TESTS=true.
Flaky tests:
Mock server issues: Check src/tests/mocks/start-mock-server.ts is running and configured correctly.
| Back | FazBrowse Home | New Git URL |