Skip to content

Commit 6e552c1

Browse files
authored
fix: improve code coverage plugin (#4252)
1 parent 3ff6ac0 commit 6e552c1

File tree

8 files changed

+320
-156
lines changed

8 files changed

+320
-156
lines changed

docs/playwright.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,25 +540,13 @@ Code coverage can be captured, by enabling the `coverage` plugin in `codecept.co
540540

541541
Once all the tests are completed, `codecept` will create and store coverage in `output/coverage` folder, as shown below.
542542

543-
![](https://user-images.githubusercontent.com/16587779/131362352-30ee9c51-705f-4098-b665-53035ea9275f.png)
544-
545-
Then you need to [convert code coverage from Playwright's format into Istanbul format](https://github.com/codeceptjs/CodeceptJS/wiki/Converting-Playwright-to-Istanbul-Coverage).
546-
547-
Once the istanbul compatible coverage is generated, use [`nyc`](https://www.npmjs.com/package/nyc) to generate your coverage report in your desired format.
548-
549-
```
550-
npx nyc report --reporter html -t coverage
551-
```
552-
553-
The above command will generate will generate coverage in an interactive html format. It should generate `html` files in the directory where your code coverage is present, something like shown below.
554-
555-
![](https://user-images.githubusercontent.com/16587779/131858419-cbc7df7d-0851-47b9-b086-b5e3b9165674.png)
543+
![](https://private-user-images.githubusercontent.com/7845001/313117208-f7165429-426a-44c5-af27-df5536ef492d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEyNTIsIm5iZiI6MTcxMDQ5MDk1MiwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzIwOC1mNzE2NTQyOS00MjZhLTQ0YzUtYWYyNy1kZjU1MzZlZjQ5MmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyMjMyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjRmNTFmOWUyYzJjYWE3ZWE0MDA0MGI3ODY5NzY5MDRlYjQyNTMxODRjZGU1ZWM5ZDdjNDJiNGRmZGUxM2FlOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ._gfEYZn2AK0NVA0bt-sFmzMoMKlyBVpxd7m4590Ux1M)
556544

557545
Open `index.html` in your browser to view the full interactive coverage report.
558546

559-
![](https://user-images.githubusercontent.com/16587779/131858993-87d1aafc-8ef1-4a82-867d-e64a13e36106.png)
547+
![](https://private-user-images.githubusercontent.com/7845001/313117882-cb77beea-c478-49ea-8677-b025d5614545.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEzOTAsIm5iZiI6MTcxMDQ5MTA5MCwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzg4Mi1jYjc3YmVlYS1jNDc4LTQ5ZWEtODY3Ny1iMDI1ZDU2MTQ1NDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyNDUwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmY0YTkxOTM0ZjUyNjZmMzk0NmM4MjU5MGFjZTZlZDc0Njc3OTZkNTNjMjc5YzQxODI3OWUyODJkNTU2NGViZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LATp5aqrvm-8Nn4tRGSuMrOjJQ4L-NIJEwsB3BbB5po)
560548

561-
![](https://user-images.githubusercontent.com/16587779/131859006-c6f17d18-c603-44a5-9d59-0670177276cf.png)
549+
![](https://private-user-images.githubusercontent.com/7845001/313117886-92a11844-0a2b-4bcb-8c73-aef5cf518dbf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEzOTAsIm5iZiI6MTcxMDQ5MTA5MCwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzg4Ni05MmExMTg0NC0wYTJiLTRiY2ItOGM3My1hZWY1Y2Y1MThkYmYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyNDUwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTQ4ODUyMTVlM2MwODRhMzE0Yjg2YWQxYTRiNmYzOWJkYWU2ZWIyNDA2YWMyYjIxYTMyNTZkYjg5NGU3Zjk4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.gxyQ9RgAAtFcCUIqqjzponc53ZRn9sG0hN4cBeQovMg)
562550

563551
## Extending Helper
564552

docs/plugins.md

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -392,23 +392,29 @@ Dumps code coverage from Playwright/Puppeteer after every test.
392392
```js
393393
plugins: {
394394
coverage: {
395-
enabled: true
395+
enabled: true,
396+
debug: true,
397+
name: 'CodeceptJS Coverage Report',
398+
outputDir: 'output/coverage'
396399
}
397400
}
398401
```
399402

400-
Possible config options:
403+
Possible config options, More could be found at [monocart-coverage-reports][1]
401404

402-
- `coverageDir`: directory to dump coverage files
403-
- `uniqueFileName`: generate a unique filename by adding uuid
405+
- `debug`: debug info. By default, false.
406+
- `name`: coverage report name.
407+
- `outputDir`: path to coverage report.
408+
- `sourceFilter`: filter the source files.
409+
- `sourcePath`: option to resolve a custom path.
404410

405411
### Parameters
406412

407413
- `config`
408414

409415
## customLocator
410416

411-
Creates a [custom locator][1] by using special attributes in HTML.
417+
Creates a [custom locator][2] by using special attributes in HTML.
412418

413419
If you have a convention to use `data-test-id` or `data-qa` attributes to mark active elements for e2e tests,
414420
you can enable this plugin to simplify matching elements with these attributes:
@@ -582,9 +588,9 @@ This method works with WebDriver, Playwright, Puppeteer, Appium helpers.
582588
Function parameter `el` represents a matched element.
583589
Depending on a helper API of `el` can be different. Refer to API of corresponding browser testing engine for a complete API list:
584590
585-
- [Playwright ElementHandle][2]
586-
- [Puppeteer][3]
587-
- [webdriverio element][4]
591+
- [Playwright ElementHandle][3]
592+
- [Puppeteer][4]
593+
- [webdriverio element][5]
588594
589595
#### Configuration
590596
@@ -598,11 +604,11 @@ const eachElement = codeceptjs.container.plugins('eachElement');
598604
599605
### Parameters
600606
601-
- `purpose` **[string][5]**
607+
- `purpose` **[string][6]**
602608
- `locator` **CodeceptJS.LocatorOrString**
603-
- `fn` **[Function][6]**
609+
- `fn` **[Function][7]**
604610
605-
Returns **([Promise][7]<any> | [undefined][8])**
611+
Returns **([Promise][8]<any> | [undefined][9])**
606612
607613
## fakerTransform
608614
@@ -680,7 +686,7 @@ Steps to heal:
680686
681687
## pauseOnFail
682688
683-
Automatically launches [interactive pause][9] when a test fails.
689+
Automatically launches [interactive pause][10] when a test fails.
684690
685691
Useful for debugging flaky tests on local environment.
686692
Add this plugin to config file:
@@ -863,14 +869,14 @@ Possible config options:
863869
864870
## selenoid
865871
866-
[Selenoid][10] plugin automatically starts browsers and video recording.
872+
[Selenoid][11] plugin automatically starts browsers and video recording.
867873
Works with WebDriver helper.
868874
869875
### Prerequisite
870876
871877
This plugin **requires Docker** to be installed.
872878
873-
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][11] tool from Selenoid
879+
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][12] tool from Selenoid
874880
875881
### Usage
876882
@@ -899,7 +905,7 @@ plugins: {
899905
}
900906
```
901907
902-
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][12] and start Selenoid automatically.
908+
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][13] and start Selenoid automatically.
903909
It will also create `browsers.json` file required by Selenoid.
904910
905911
In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
@@ -911,10 +917,10 @@ In automatic mode the latest version of browser will be used for tests. It is re
911917
While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
912918
This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
913919
914-
> Use [Selenoid Configuration Manager][11] to create and start containers semi-automatically.
920+
> Use [Selenoid Configuration Manager][12] to create and start containers semi-automatically.
915921
916922
1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
917-
[Refer to Selenoid documentation][13] to know more about browsers.json.
923+
[Refer to Selenoid documentation][14] to know more about browsers.json.
918924
919925
_Sample browsers.json_
920926
@@ -939,7 +945,7 @@ _Sample browsers.json_
939945
940946
2. Create Selenoid container
941947
942-
Run the following command to create a container. To know more [refer here][14]
948+
Run the following command to create a container. To know more [refer here][15]
943949
944950
```bash
945951
docker create \
@@ -972,15 +978,15 @@ When `allure` plugin is enabled a video is attached to report automatically.
972978
| enableVideo | Enable video recording and use `video` folder of output (default: false) |
973979
| enableLog | Enable log recording and use `logs` folder of output (default: false) |
974980
| deletePassed | Delete video and logs of passed tests (default : true) |
975-
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][15] to know more |
981+
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][16] to know more |
976982
977983
### Parameters
978984
979985
- `config`
980986
981987
## stepByStepReport
982988
983-
![step-by-step-report][16]
989+
![step-by-step-report][17]
984990
985991
Generates step by step report for a test.
986992
After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
@@ -1161,7 +1167,7 @@ This plugin allows to run webdriverio services like:
11611167
- browserstack
11621168
- appium
11631169
1164-
A complete list of all available services can be found on [webdriverio website][17].
1170+
A complete list of all available services can be found on [webdriverio website][18].
11651171
11661172
#### Setup
11671173
@@ -1173,7 +1179,7 @@ See examples below:
11731179
11741180
#### Selenium Standalone Service
11751181
1176-
Install `@wdio/selenium-standalone-service` package, as [described here][18].
1182+
Install `@wdio/selenium-standalone-service` package, as [described here][19].
11771183
It is important to make sure it is compatible with current webdriverio version.
11781184
11791185
Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
@@ -1190,7 +1196,7 @@ plugins: {
11901196
11911197
#### Sauce Service
11921198
1193-
Install `@wdio/sauce-service` package, as [described here][19].
1199+
Install `@wdio/sauce-service` package, as [described here][20].
11941200
It is important to make sure it is compatible with current webdriverio version.
11951201
11961202
Enable `wdio` plugin in plugins list and add `sauce` service:
@@ -1220,40 +1226,42 @@ In the same manner additional services from webdriverio can be installed, enable
12201226
12211227
- `config`
12221228
1223-
[1]: https://codecept.io/locators#custom-locators
1229+
[1]: https://github.com/cenfun/monocart-coverage-reports?tab=readme-ov-file#default-options
1230+
1231+
[2]: https://codecept.io/locators#custom-locators
12241232
1225-
[2]: https://playwright.dev/docs/api/class-elementhandle
1233+
[3]: https://playwright.dev/docs/api/class-elementhandle
12261234
1227-
[3]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
1235+
[4]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
12281236
1229-
[4]: https://webdriver.io/docs/api
1237+
[5]: https://webdriver.io/docs/api
12301238
1231-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
1239+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
12321240
1233-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1241+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
12341242
1235-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
1243+
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
12361244
1237-
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
1245+
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
12381246
1239-
[9]: /basics/#pause
1247+
[10]: /basics/#pause
12401248
1241-
[10]: https://aerokube.com/selenoid/
1249+
[11]: https://aerokube.com/selenoid/
12421250
1243-
[11]: https://aerokube.com/cm/latest/
1251+
[12]: https://aerokube.com/cm/latest/
12441252
1245-
[12]: https://hub.docker.com/u/selenoid
1253+
[13]: https://hub.docker.com/u/selenoid
12461254
1247-
[13]: https://aerokube.com/selenoid/latest/#_prepare_configuration
1255+
[14]: https://aerokube.com/selenoid/latest/#_prepare_configuration
12481256
1249-
[14]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
1257+
[15]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
12501258
1251-
[15]: https://docs.docker.com/engine/reference/commandline/create/
1259+
[16]: https://docs.docker.com/engine/reference/commandline/create/
12521260
1253-
[16]: https://codecept.io/img/codeceptjs-slideshow.gif
1261+
[17]: https://codecept.io/img/codeceptjs-slideshow.gif
12541262
1255-
[17]: https://webdriver.io
1263+
[18]: https://webdriver.io
12561264
1257-
[18]: https://webdriver.io/docs/selenium-standalone-service.html
1265+
[19]: https://webdriver.io/docs/selenium-standalone-service.html
12581266
1259-
[19]: https://webdriver.io/docs/sauce-service.html
1267+
[20]: https://webdriver.io/docs/sauce-service.html

docs/puppeteer.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,30 @@ I.usePuppeteerTo('emulate offline mode', async (Puppeteer) => {
288288
});
289289
```
290290

291+
## Capturing Code Coverage
292+
293+
Code coverage can be captured, by enabling the `coverage` plugin in `codecept.config.js`.
294+
295+
```js
296+
{
297+
plugins: {
298+
coverage: {
299+
enabled: true
300+
}
301+
}
302+
}
303+
```
304+
305+
Once all the tests are completed, `codecept` will create and store coverage in `output/coverage` folder, as shown below.
306+
307+
![](https://private-user-images.githubusercontent.com/7845001/313117208-f7165429-426a-44c5-af27-df5536ef492d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEyNTIsIm5iZiI6MTcxMDQ5MDk1MiwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzIwOC1mNzE2NTQyOS00MjZhLTQ0YzUtYWYyNy1kZjU1MzZlZjQ5MmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyMjMyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjRmNTFmOWUyYzJjYWE3ZWE0MDA0MGI3ODY5NzY5MDRlYjQyNTMxODRjZGU1ZWM5ZDdjNDJiNGRmZGUxM2FlOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ._gfEYZn2AK0NVA0bt-sFmzMoMKlyBVpxd7m4590Ux1M)
308+
309+
Open `index.html` in your browser to view the full interactive coverage report.
310+
311+
![](https://private-user-images.githubusercontent.com/7845001/313117882-cb77beea-c478-49ea-8677-b025d5614545.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEzOTAsIm5iZiI6MTcxMDQ5MTA5MCwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzg4Mi1jYjc3YmVlYS1jNDc4LTQ5ZWEtODY3Ny1iMDI1ZDU2MTQ1NDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyNDUwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmY0YTkxOTM0ZjUyNjZmMzk0NmM4MjU5MGFjZTZlZDc0Njc3OTZkNTNjMjc5YzQxODI3OWUyODJkNTU2NGViZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LATp5aqrvm-8Nn4tRGSuMrOjJQ4L-NIJEwsB3BbB5po)
312+
313+
![](https://private-user-images.githubusercontent.com/7845001/313117886-92a11844-0a2b-4bcb-8c73-aef5cf518dbf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0OTEzOTAsIm5iZiI6MTcxMDQ5MTA5MCwicGF0aCI6Ii83ODQ1MDAxLzMxMzExNzg4Ni05MmExMTg0NC0wYTJiLTRiY2ItOGM3My1hZWY1Y2Y1MThkYmYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDMxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAzMTVUMDgyNDUwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTQ4ODUyMTVlM2MwODRhMzE0Yjg2YWQxYTRiNmYzOWJkYWU2ZWIyNDA2YWMyYjIxYTMyNTZkYjg5NGU3Zjk4OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.gxyQ9RgAAtFcCUIqqjzponc53ZRn9sG0hN4cBeQovMg)
314+
291315

292316
## Extending Helper
293317

0 commit comments

Comments
 (0)