Skip to content

Commit 89ee0cf

Browse files
author
rocketraccoon
committed
feat(testplane): badges
1 parent 477d620 commit 89ee0cf

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

docs/html-reporter/html-reporter-setup.mdx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import ConfigExamples from "/docs/_partials/html-reporter-config-examples.mdx";
3535
<tr><td>[plugins](#plugins)</td><td>`Plugin[]`</td><td>`[]`</td><td>A list of plugins with their settings.</td></tr>
3636
<tr><td>[customScripts](#customscripts)</td><td>`AnyFunction[]`</td><td>`[]`</td><td>A list of functions that implement custom scripts. For example, Yandex.Metrika scripts or a Bug.</td></tr>
3737
<tr><td>[yandexMetrika](#yandexmetrika)</td><td>`YandexMetrika`</td><td>*see below*</td><td>[Yandex.Metrika][yandex-metrika].</td></tr>
38+
<tr><td>[badgeFormatter](#badgeformatter)</td><td>`BadgeFormatter`</td><td>`null`</td><td>A callback that is called after every test run. It receives the test result and returns a list of badges.</td></tr>
3839

3940
</tbody>
4041
</table>
@@ -288,6 +289,86 @@ If you don't want to share analytics with us, you can disable it in any of the f
288289
- Using environment variables: `html_reporter_yandex_metrika_enabled=false` or simply `NO_ANALYTICS=true`
289290
- Using CLI arguments: `--html-reporter-yandex_metrika_enabled=false`
290291

292+
### badgeFormatter
293+
294+
A callback that is called after every test run. It receives the test result and returns a list of badges.
295+
296+
Usage example: here we set the ticket name and URL, the branch name, and the speed test indicator.
297+
298+
```typescript title="testplane.config.ts"
299+
{
300+
// other Testplane config...
301+
plugins: {
302+
"html-reporter/testplane": {
303+
//...
304+
badgeFormatter: (test) => [
305+
{
306+
title: test.meta.issueTitle,
307+
icon: 'LogoYandexTracker',
308+
url: test.meta.issueUrl,
309+
},
310+
{
311+
title: test.meta.branch,
312+
icon: 'BranchesRight',
313+
},
314+
test.duration > 3000 ?
315+
{
316+
title: "Slow",
317+
icon: 'Snail',
318+
} :
319+
{
320+
title: "Fast",
321+
icon: 'ChevronsRight',
322+
}
323+
]
324+
}
325+
}
326+
}
327+
```
328+
329+
An example of a test where you can set metadata.
330+
331+
```typescript title="testplane.config.ts"
332+
describe("badges", () => {
333+
it("badge example", async ({ browser }) => {
334+
await browser.setMeta("issueTitle", "ticket-1234");
335+
await browser.setMeta("issueUrl", "https://example.com");
336+
await browser.setMeta("branch", "master");
337+
338+
await browser.pause(3000);
339+
});
340+
});
341+
```
342+
343+
#### Badge params
344+
345+
<table>
346+
<thead>
347+
<tr>
348+
<td>**Name**</td>
349+
<td>**Type**</td>
350+
<td>**Description**</td>
351+
</tr>
352+
</thead>
353+
<tbody>
354+
<tr>
355+
<td>`title`</td>
356+
<td>`string`</td>
357+
<td>Required parameter. Displayed badge title.</td>
358+
</tr>
359+
<tr>
360+
<td>`icon`</td>
361+
<td>`string`</td>
362+
<td>Optional parameter. Name of icon from [GravityUI][gravity-ui-icons].</td>
363+
</tr>
364+
<tr>
365+
<td>`url`</td>
366+
<td>`string`</td>
367+
<td>Optional parameter. Url of badge.</td>
368+
</tr>
369+
</tbody>
370+
</table>
371+
291372
### Passing parameters via the CLI {#setup_by_cli}
292373

293374
All plugin parameters that can be defined in the config can also be passed as command line options or through environment variables during Testplane startup. Use the prefix `--html-reporter-` for command line options and `html_reporter_` for environment variables.
@@ -328,3 +409,4 @@ Files that are created during the execution of tests:
328409
[how-to-create-counter]: https://yandex.ru/support/metrica/general/creating-counter.html
329410
[merge-reports]: ../html-reporter-commands#merge-reports
330411
[http-server]: https://github.com/http-party/http-server#http-server-a-simple-static-http-server
412+
[gravity-ui-icons]: https://gravity-ui.com/ru/icons

i18n/ru/docusaurus-plugin-content-docs/current/html-reporter/html-reporter-setup.mdx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import ConfigExamples from "../_partials/html-reporter-config-examples.mdx";
3333
<tr><td>[plugins](#plugins)</td><td>`Plugin[]`</td><td>`[]`</td><td>Список плагинов с их настройками.</td></tr>
3434
<tr><td>[customScripts](#customscripts)</td><td>`AnyFunction[]`</td><td>`[]`</td><td>Список функций, реализующих кастомные скрипты. Например, скрипты Яндекс.Метрики или Жучка.</td></tr>
3535
<tr><td>[yandexMetrika](#yandexmetrika)</td><td>`YandexMetrika`</td><td>*см. ниже*</td><td>[Яндекс.Метрика][yandex-metrika].</td></tr>
36+
<tr><td>[badgeFormatter](#badgeformatter)</td><td>`BadgeFormatter`</td><td>`null`</td><td>Колбэк, который вызывается после каждого запуска теста. Он получает результат теста и возвращает список бейджей.</td></tr>
3637

3738
</tbody>
3839
</table>
@@ -286,6 +287,86 @@ customScripts: [
286287
- С помощью переменных окружения: `html_reporter_yandex_metrika_enabled=false` или просто `NO_ANALYTICS=true`
287288
- С помощью аргументов CLI: `--html-reporter-yandex_metrika_enabled=false`
288289

290+
### badgeFormatter
291+
292+
Колбэк, который вызывается после каждого запуска теста. Он получает результат теста и возвращает список бейджей.
293+
294+
Пример использования: здесь мы задаём название тикета и URL, название ветки и индикатор скорости теста.
295+
296+
```typescript title="testplane.config.ts"
297+
{
298+
// other Testplane config...
299+
plugins: {
300+
"html-reporter/testplane": {
301+
//...
302+
badgeFormatter: (test) => [
303+
{
304+
title: test.meta.issueTitle,
305+
icon: 'LogoYandexTracker',
306+
url: test.meta.issueUrl,
307+
},
308+
{
309+
title: test.meta.branch,
310+
icon: 'BranchesRight',
311+
},
312+
test.duration > 3000 ?
313+
{
314+
title: "Slow",
315+
icon: 'Snail',
316+
} :
317+
{
318+
title: "Fast",
319+
icon: 'ChevronsRight',
320+
}
321+
]
322+
}
323+
}
324+
}
325+
```
326+
327+
Пример как можно установить метаданные в тесте.
328+
329+
```typescript title="testplane.config.ts"
330+
describe("badges", () => {
331+
it("badge example", async ({ browser }) => {
332+
await browser.setMeta("issueTitle", "ticket-1234");
333+
await browser.setMeta("issueUrl", "https://example.com");
334+
await browser.setMeta("branch", "master");
335+
336+
await browser.pause(3000);
337+
});
338+
});
339+
```
340+
341+
#### Badge params
342+
343+
<table>
344+
<thead>
345+
<tr>
346+
<td>**Имя**</td>
347+
<td>**Тип**</td>
348+
<td>**Описание**</td>
349+
</tr>
350+
</thead>
351+
<tbody>
352+
<tr>
353+
<td>`title`</td>
354+
<td>`string`</td>
355+
<td>Обязательный параметр. Отображаемое имя бейджа.</td>
356+
</tr>
357+
<tr>
358+
<td>`icon`</td>
359+
<td>`string`</td>
360+
<td>Опциональный параметр. Имя иконки из [GravityUI][gravity-ui-icons].</td>
361+
</tr>
362+
<tr>
363+
<td>`url`</td>
364+
<td>`string`</td>
365+
<td>Опциональный параметр. Ссылка которая откроется при клике на бейдж.</td>
366+
</tr>
367+
</tbody>
368+
</table>
369+
289370
### Передача параметров через CLI {#setup_by_cli}
290371

291372
Все параметры плагина, которые можно определить в конфиге, можно также передать в виде опций командной строки или через переменные окружения во время запуска testplane. Используйте префикс `--html-reporter-` для опций командной строки и `html_reporter_` — для переменных окружения.

0 commit comments

Comments
 (0)