Skip to content

Commit aadb276

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

File tree

2 files changed

+175
-4
lines changed

2 files changed

+175
-4
lines changed

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

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import Version from "../_partials/specs/version-en.mdx";
2+
13
---
2-
sidebar_position: 2
3-
---
4+
5+
## sidebar_position: 2
46

57
import Tabs from "@theme/Tabs";
68
import TabItem from "@theme/TabItem";
@@ -35,6 +37,7 @@ import ConfigExamples from "/docs/_partials/html-reporter-config-examples.mdx";
3537
<tr><td>[plugins](#plugins)</td><td>`Plugin[]`</td><td>`[]`</td><td>A list of plugins with their settings.</td></tr>
3638
<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>
3739
<tr><td>[yandexMetrika](#yandexmetrika)</td><td>`YandexMetrika`</td><td>*see below*</td><td>[Yandex.Metrika][yandex-metrika].</td></tr>
40+
<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>
3841

3942
</tbody>
4043
</table>
@@ -288,6 +291,88 @@ If you don't want to share analytics with us, you can disable it in any of the f
288291
- Using environment variables: `html_reporter_yandex_metrika_enabled=false` or simply `NO_ANALYTICS=true`
289292
- Using CLI arguments: `--html-reporter-yandex_metrika_enabled=false`
290293

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

293378
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 +413,4 @@ Files that are created during the execution of tests:
328413
[how-to-create-counter]: https://yandex.ru/support/metrica/general/creating-counter.html
329414
[merge-reports]: ../html-reporter-commands#merge-reports
330415
[http-server]: https://github.com/http-party/http-server#http-server-a-simple-static-http-server
416+
[gravity-ui-icons]: https://gravity-ui.com/ru/icons

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

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import Version from "../../../../docs/_partials/specs/version-ru.mdx";
2+
13
---
2-
sidebar_position: 2
3-
---
4+
5+
## sidebar_position: 2
46

57
import Admonition from "@theme/Admonition";
68
import ConfigExamples from "../_partials/html-reporter-config-examples.mdx";
@@ -33,6 +35,7 @@ import ConfigExamples from "../_partials/html-reporter-config-examples.mdx";
3335
<tr><td>[plugins](#plugins)</td><td>`Plugin[]`</td><td>`[]`</td><td>Список плагинов с их настройками.</td></tr>
3436
<tr><td>[customScripts](#customscripts)</td><td>`AnyFunction[]`</td><td>`[]`</td><td>Список функций, реализующих кастомные скрипты. Например, скрипты Яндекс.Метрики или Жучка.</td></tr>
3537
<tr><td>[yandexMetrika](#yandexmetrika)</td><td>`YandexMetrika`</td><td>*см. ниже*</td><td>[Яндекс.Метрика][yandex-metrika].</td></tr>
38+
<tr><td>[badgeFormatter](#badgeformatter)</td><td>`BadgeFormatter`</td><td>`null`</td><td>Колбэк, который вызывается после каждого запуска теста. Он получает результат теста и возвращает список бейджей.</td></tr>
3639

3740
</tbody>
3841
</table>
@@ -286,6 +289,88 @@ customScripts: [
286289
- С помощью переменных окружения: `html_reporter_yandex_metrika_enabled=false` или просто `NO_ANALYTICS=true`
287290
- С помощью аргументов CLI: `--html-reporter-yandex_metrika_enabled=false`
288291

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

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

0 commit comments

Comments
 (0)