Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ HTTP API, протокол HTTP, Postman, js-playwright, курсы Selenium и

Код обработчиков курсы делят свободно, свой у каждого курса только адрес.

### Навигация

Курс с префиксом получает страницу по самому префиксу (`/http-protocol`, `/http-for-automation`) и строку на главной `/`. Страница ведёт на опыты, которые открываются из браузера, то есть на GET-маршруты курса. HTML лежит в `custom-server/assets/<префикс>/index.html`, маршрут регистрируется в `custom-server/src/index.ts` рядом с остальными страницами.

`test/app.test.ts` проверяет, что ссылки главной и страниц курсов не отдают 404. Страница нового курса добавляется в этот список. `/http-protocol` в нём нет, потому что `/http-protocol/stream` отдаёт пять чанков с паузой в секунду и не укладывается в пятисекундный таймаут vitest.

## Как собран сервер

Четыре спецификации на TypeSpec (`typespec/<app>/`) компилируются в OpenAPI
Expand Down
18 changes: 18 additions & 0 deletions custom-server/assets/http-for-automation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example</title>
</head>
<body>
<h1>It works!</h1>
<ul>
<li><a href="/http-for-automation/login-form">Login form</a></li>
<li><a href="/http-for-automation/session">Session</a></li>
<li><a href="/http-for-automation/cache">Cache</a></li>
<li><a href="/http-for-automation/cache/revalidate">Cache: no-cache</a></li>
<li><a href="/http-for-automation/cache/no-store">Cache: no-store</a></li>
</ul>
</body>
</html>
1 change: 1 addition & 0 deletions custom-server/assets/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>It works!</h1>
<li><a href="/http-api-openapi">HTTP API</a></li>
<li><a href="/http-protocol-openapi">HTTP Protocol</a></li>
<li><a href="/http-protocol/form">HTTP Form</a></li>
<li><a href="/http-for-automation">HTTP for Automation</a></li>
<li><a href="/js-playwright-openapi">JS Playwright</a></li>
<li><a href="/postman-openapi">Postman</a></li>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions custom-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export default async (app: FastifyInstance, _options: unknown) => {

app.get('/http-protocol', (req, res) => res.sendFile('http-protocol/index.html'));

app.get('/http-for-automation', (req, res) => res.sendFile('http-for-automation/index.html'));

app.get('/http-protocol/removed', (req, res) => res.code(301).redirect('/http-protocol/example'));

app.get('/js-playwright/users-list', (req, res) => res.sendFile('users-list/index.html'));
Expand Down
9 changes: 9 additions & 0 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ describe('документация и статика', () => {
expect((await client.send('/')).status).toBe(200);
});

it.each(['/', '/http-for-automation'])('ссылки со страницы %s живые', async (page) => {
const html = String((await client.send(page)).body);
const links = [...html.matchAll(/href="([^"]+)"/g)].map((match) => match[1]);
expect(links.length).toBeGreaterThan(0);
for (const link of links) {
expect({ link, status: (await client.send(link)).status }).not.toEqual({ link, status: 404 });
}
});

it('несуществующий адрес → 404 с кодом в теле', async () => {
const reply = await client.send('/nosuch');
expect(reply.status).toBe(404);
Expand Down
Loading