Skip to content

Commit 2fc6cf3

Browse files
authored
docs: sync changes from html-reporter repo (#94)
1 parent d026511 commit 2fc6cf3

File tree

10 files changed

+201
-119
lines changed

10 files changed

+201
-119
lines changed

docs/_partials/html-reporter-config-examples.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Admonition from "@theme/Admonition";
12
import Tabs from "@theme/Tabs";
23
import TabItem from "@theme/TabItem";
34

@@ -33,6 +34,17 @@ import TabItem from "@theme/TabItem";
3334
</TabItem>
3435

3536
<TabItem value="Jest" label="Jest">
37+
```javascript title="jest.config.ts"
38+
const config = {
39+
// ...
40+
reporters: [
41+
'html-reporter/jest', // Connecting our reporter
42+
'default' // Built in Jest reporter or any additional reporters you need (optional)
43+
],
44+
};
45+
```
46+
47+
If you want to pass configuration options, you may do the following:
3648
```javascript title="jest.config.ts"
3749
const config = {
3850
// ...
@@ -43,6 +55,8 @@ import TabItem from "@theme/TabItem";
4355
],
4456
};
4557
```
58+
59+
<Admonition type="warning">If you are using jest@27 or below, you need to use the following path: `html-reporter/build/jest`.</Admonition>
4660
</TabItem>
4761

4862
</Tabs>

docs/html-reporter/html-reporter-api.mdx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ Html-reporter adds an `htmlReporter` object to the `testplane` object with its o
1717
<tr><td>[extraItems](#extraitems)</td><td>Object</td><td>Additional elements to be added to the burger menu of the report.</td></tr>
1818
<tr><td>[imagesSaver](#imagessaver)</td><td>Object</td><td>Interface for saving images to the user's storage.</td></tr>
1919
<tr><td>[reportsSaver](#reportssaver)</td><td>Object</td><td>Interface for saving sqlite databases to the user's storage.</td></tr>
20+
<tr><td>[snapshotsSaver](#snapshotssaver)</td><td>Object</td><td>Interface for saving snapshots to the user's storage.</td></tr>
2021
<tr><td>[addExtraItem](#addextraitem)</td><td>Method</td><td>Adds an additional item to the burger menu of the report.</td></tr>
2122
<tr><td>[downloadDatabases](#downloaddatabases)</td><td>Method</td><td>Downloads all databases from the given files of the type _databaseUrls.json_.</td></tr>
2223
<tr><td>[mergeDatabases](#mergedatabases)</td><td>Method</td><td>Merges all given databases and saves the final report on the specified path.</td></tr>
23-
<tr><td>[getTestsTreeFromDatabase](#getteststreefromdatabase)</td><td>Method</td><td>Returns the test tree from the passed database.</td></tr>
24+
<tr><td>[getTestsTreeFromDatabase](#getteststreefromdatabase)</td><td>Method</td><td>Resolves the test tree from the passed database.</td></tr>
2425

2526
</tbody>
2627
</table>
@@ -109,6 +110,42 @@ module.exports = (testplane, opts) => {
109110
};
110111
```
111112

113+
## snapshotsSaver
114+
115+
Interface for saving DOM-snapshots to the user's storage.
116+
117+
### Usage example
118+
119+
```javascript
120+
const MyStorage = require("my-storage");
121+
const myStorage = new MyStorage();
122+
123+
module.exports = (testplane, opts) => {
124+
testplane.on(testplane.events.INIT, async () => {
125+
testplane.htmlReporter.snapshotsSaver = {
126+
/**
127+
* Save snapshot to user storage.
128+
* The function can be either asynchronous or synchronous.
129+
* The function should return the path or URL to the saved snapshot.
130+
* @property {String} localFilePath – the path to the snapshot on the file system
131+
* @param {Object} options
132+
* @param {String} options.destPath – the path to the snapshot in the html-report
133+
* @param {String} options.reportDir - path to the html-report folder
134+
* @returns {String} the path or URL to the snapshot
135+
*/
136+
saveSnapshot: async (localFilePath, options) => {
137+
const { destPath, reportDir } = options;
138+
const snapshotUrl = await myStorage.save(localFilePath, destPath, reportDir);
139+
140+
// ...
141+
142+
return snapshotUrl;
143+
},
144+
};
145+
});
146+
};
147+
```
148+
112149
## addExtraItem
113150

114151
Adds an additional item to the burger menu of the report.
@@ -177,12 +214,12 @@ await testplane.htmlReporter.mergeDatabases(srcDbPaths, path);
177214

178215
## getTestsTreeFromDatabase
179216

180-
Returns the test tree from the passed database.
217+
Resolves the test tree from the passed database.
181218

182219
### Example of a call {#get_tests_tree_from_database_call_example}
183220

184221
```javascript
185-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
222+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
186223
```
187224

188225
### Call parameters {#get_tests_tree_from_database_call_params}
@@ -192,8 +229,8 @@ The function takes one argument—the path to the database with the result of th
192229
### Usage example {#get_tests_tree_from_database_usage_example}
193230

194231
```javascript
195-
function getSuccessTestRunIds({ testplane, mergedDbPath }) {
196-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
232+
async function getSuccessTestRunIds({ testplane, mergedDbPath }) {
233+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
197234

198235
const successTestRunIds = [];
199236

docs/html-reporter/html-reporter-commands.mdx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,38 @@ It creates a new html-report in the destination folder with data from all passed
5555
The `merge-reports` command supports the following required option:
5656

5757
<table>
58-
<thead>
59-
<tr><td>**Option**</td><td>**Description**</td></tr>
60-
</thead>
61-
<tbody>
62-
<tr><td>-d, --destination &lt;folder></td><td>The path to the folder where you want to save the final report.</td></tr>
63-
64-
</tbody>
58+
<thead>
59+
<tr>
60+
<td>**Option**</td>
61+
<td>**Description**</td>
62+
</tr>
63+
</thead>
64+
<tbody>
65+
<tr>
66+
<td>-d, --destination &lt;folder></td>
67+
<td>The path to the folder where you want to save the final report.</td>
68+
</tr>
69+
<tr>
70+
<td>-h, --header &lt;header></td>
71+
<td>Http header for databaseUrls.json files from source paths.</td>
72+
</tr>
73+
</tbody>
6574
</table>
6675

6776
Usage example:
6877

6978
```bash
70-
npx html-reporter merge-reports report-dir/ path-to-database.db path-to-databaseUrls.json -d dest-report
79+
npx html-reporter merge-reports report-dir/ path-to-database.db path-to-databaseUrls.json -d dest-report -h foo=bar
7180
```
7281

82+
Http headers can also be send using the environment variable — `html_reporter_headers` (has a higher priority than the cli option `--header'). Example:
83+
84+
```bash
85+
html_reporter_headers='{"foo":"bar"}' npx hermione merge-reports path-to-database.db path-to-databaseUrls.json -d dest-report -h baz=qux
86+
```
87+
88+
In this call, the `path-to-databaseUrls.json` will be requested with headers: `{foo: 'bar', baz: 'qux'}`.
89+
7390
## remove-unused-screens
7491

7592
<Admonition type="info" title="Command availability">

docs/html-reporter/html-reporter-events.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ testplane.htmlReporter.on(testplane.htmlReporter.events.DATABASE_CREATED, db =>
2828

2929
#### Handler parameters {#database_created_handler_params}
3030

31-
A database instance is passed to the event handler.
31+
A [sql.js](https://www.npmjs.com/package/sql.js) database instance is passed to the event handler.
3232

3333
### Usage example {#database_created_example}
3434

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

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,14 @@ sidebar_position: 2
44

55
import Tabs from "@theme/Tabs";
66
import TabItem from "@theme/TabItem";
7-
87
import Admonition from "@theme/Admonition";
8+
import ConfigExamples from "/docs/_partials/html-reporter-config-examples.mdx";
99

1010
# Configuration
1111

1212
## Config Examples {#setup}
1313

14-
<Tabs>
15-
<TabItem value="Testplane" label="Testplane">
16-
```javascript title="testplane.config.ts"
17-
export = {
18-
// ...
19-
plugins: {
20-
'html-reporter/testplane': {
21-
enabled: true,
22-
path: 'html-report',
23-
},
24-
},
25-
};
26-
```
27-
28-
</TabItem>
29-
30-
<TabItem value="Playwright" label="Playwright">
31-
```javascript title="playwright.config.ts"
32-
// playwright.config.ts
33-
export default defineConfig({
34-
// ...
35-
reporter: [
36-
['html-reporter/playwright', {
37-
enabled: true,
38-
defaultView: 'failed',
39-
path: 'html-report',
40-
}],
41-
],
42-
});
43-
```
44-
45-
</TabItem>
46-
47-
<TabItem value="Jest" label="Jest">
48-
```javascript title="jest.config.ts"
49-
const config = {
50-
// ...
51-
reporters: [
52-
['html-reporter/jest', {
53-
path: 'html-report',
54-
}]
55-
],
56-
};
57-
```
58-
</TabItem>
59-
60-
</Tabs>
14+
<ConfigExamples />
6115

6216
## Configuration Reference {#setup_description}
6317

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Admonition from "@theme/Admonition";
2+
import Tabs from "@theme/Tabs";
3+
import TabItem from "@theme/TabItem";
4+
5+
<Tabs>
6+
<TabItem value="Testplane" label="Testplane">
7+
```javascript title="testplane.config.ts"
8+
export = {
9+
// ...
10+
plugins: {
11+
'html-reporter/testplane': {
12+
enabled: true,
13+
path: 'html-report',
14+
},
15+
},
16+
};
17+
```
18+
</TabItem>
19+
20+
<TabItem value="Playwright" label="Playwright">
21+
```javascript title="playwright.config.ts"
22+
// playwright.config.ts
23+
export default defineConfig({
24+
// ...
25+
reporter: [
26+
['html-reporter/playwright', {
27+
enabled: true,
28+
defaultView: 'failed',
29+
path: 'html-report',
30+
}],
31+
],
32+
});
33+
```
34+
</TabItem>
35+
36+
<TabItem value="Jest" label="Jest">
37+
```javascript title="jest.config.ts"
38+
const config = {
39+
// ...
40+
reporters: [
41+
'html-reporter/jest', // Подключаем наш репортер
42+
'default' // Встроенный репортер Jest или любые другие необходимые (опционально)
43+
],
44+
};
45+
```
46+
47+
Если нужно передать параметры конфигурации, можно сделать так:
48+
```javascript title="jest.config.ts"
49+
const config = {
50+
// ...
51+
reporters: [
52+
['html-reporter/jest', {
53+
path: 'html-report',
54+
}]
55+
],
56+
};
57+
```
58+
59+
<Admonition type="warning">Если вы используете jest@27 или ниже, нужно указать следующий путь: `html-reporter/build/jest`.</Admonition>
60+
</TabItem>
61+
62+
</Tabs>

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ Html-reporter добавляет к объекту `testplane` объект `htm
1717
<tr><td>[extraItems](#extraitems)</td><td>Object</td><td>Дополнительные элементы, которые будут добавлены в бургер-меню отчета.</td></tr>
1818
<tr><td>[imagesSaver](#imagessaver)</td><td>Object</td><td>Интерфейс для сохранения изображений в хранилище пользователя.</td></tr>
1919
<tr><td>[reportsSaver](#reportssaver)</td><td>Object</td><td>Интерфейс для сохранения sqlite баз данных в хранилище пользователя.</td></tr>
20+
<tr><td>[snapshotsSaver](#snapshotssaver)</td><td>Object</td><td>Интерфейс для сохранения DOM-снапшотов в хранилище пользователя.</td></tr>
2021
<tr><td>[addExtraItem](#addextraitem)</td><td>Method</td><td>Добавляет дополнительный пункт в бургер-меню отчета.</td></tr>
2122
<tr><td>[downloadDatabases](#downloaddatabases)</td><td>Method</td><td>Скачивает все базы данных из переданных файлов типа _databaseUrls.json_.</td></tr>
2223
<tr><td>[mergeDatabases](#mergedatabases)</td><td>Method</td><td>Объединяет все переданные базы данных и сохраняет итоговый отчет по заданному пути.</td></tr>
23-
<tr><td>[getTestsTreeFromDatabase](#getteststreefromdatabase)</td><td>Method</td><td>Возвращает дерево тестов из переданной базы данных.</td></tr>
24+
<tr><td>[getTestsTreeFromDatabase](#getteststreefromdatabase)</td><td>Method</td><td>Асинхронно возвращает дерево тестов из переданной базы данных.</td></tr>
2425

2526
</tbody>
2627
</table>
@@ -109,6 +110,42 @@ module.exports = (testplane, opts) => {
109110
};
110111
```
111112

113+
## snapshotsSaver
114+
115+
Интерфейс для сохранения DOM-снапшотов в хранилище пользователя.
116+
117+
### Пример использования {#snapshots_saver_usage_example}
118+
119+
```javascript
120+
const MyStorage = require("my-storage");
121+
const myStorage = new MyStorage();
122+
123+
module.exports = (testplane, opts) => {
124+
testplane.on(testplane.events.INIT, async () => {
125+
testplane.htmlReporter.snapshotsSaver = {
126+
/**
127+
* Сохранить снапшот в пользовательском хранилище.
128+
* Функция может быть как асинхронной, так и синхронной.
129+
* Функция должна возвращать путь или URL к сохраненному снапшоту.
130+
* @property {String} localFilePath – путь к снапшоту на файловой системе
131+
* @param {Object} options
132+
* @param {String} options.destPath – путь к снапшоту в html-отчете
133+
* @param {String} options.reportDir - путь к папке html-отчета
134+
* @returns {String} путь или URL к снапшоту
135+
*/
136+
saveSnapshot: async (localFilePath, options) => {
137+
const { destPath, reportDir } = options;
138+
const snapshotUrl = await myStorage.save(localFilePath, destPath, reportDir);
139+
140+
// ...
141+
142+
return snapshotUrl;
143+
},
144+
};
145+
});
146+
};
147+
```
148+
112149
## addExtraItem
113150

114151
Добавляет дополнительный пункт в виде ссылки в бургер-меню html-отчета.
@@ -177,12 +214,12 @@ await testplane.htmlReporter.mergeDatabases(srcDbPaths, path);
177214

178215
## getTestsTreeFromDatabase
179216

180-
Возвращает дерево тестов из переданной базы данных.
217+
Асинхронно возвращает дерево тестов из переданной базы данных.
181218

182219
### Пример вызова {#get_tests_tree_from_database_call_example}
183220

184221
```javascript
185-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
222+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
186223
```
187224

188225
### Параметры вызова {#get_tests_tree_from_database_call_params}
@@ -192,8 +229,8 @@ const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
192229
### Пример использования {#get_tests_tree_from_database_usage_example}
193230

194231
```javascript
195-
function getSuccessTestRunIds({ testplane, mergedDbPath }) {
196-
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
232+
async function getSuccessTestRunIds({ testplane, mergedDbPath }) {
233+
const dbTree = await testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);
197234

198235
const successTestRunIds = [];
199236

0 commit comments

Comments
 (0)