Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): create coverage reports when --coverage specified in deno test #28260

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Feb 23, 2025

part of #21325
closes #28218

This PR updates the behavior of deno test --coverage option. Now if --coverage option is specified, deno test command automatically shows summary report in the terminal, and generates the lcov report in $coverage_dir/lcov.info and html report in $coverage_dir/html/

This change also adds --coverage-raw-data-only flag, which prevents the above reports generated, instead only generates the raw json coverage data (which is the same as current behavior)


An example of execution looks like:

$ deno test --coverage
running 41 tests from ./yaml/parse_test.ts
parse() handles single document yaml string ... ok (2ms)
parseAll() handles yaml string with multiple documents ... ok (0ms)
parse() throws with `!!js/*` yaml types with default schemas ... ok (0ms)

... snip ...

stringify() handles undefined object entry with skipInvalid and flowLevel option ... ok (0ms)
stringify() handles undefined object entry with big key and skipInvalid and flowLevel option ... ok (0ms)
stringify() handles duplicate binary references ... ok (0ms)

ok | 83 passed | 0 failed (442ms)

-----------------------------------------------------
File                            | Branch % | Line % |
-----------------------------------------------------
 assert/almost_equals.ts        |    100.0 |    4.5 |
 assert/array_includes.ts       |    100.0 |   10.3 |
 assert/assert.ts               |      0.0 |   50.0 |

... snip ...

 yaml/_utils.ts                 |    100.0 |  100.0 |
 yaml/parse.ts                  |    100.0 |  100.0 |
 yaml/stringify.ts              |    100.0 |  100.0 |
-----------------------------------------------------
 All files                      |     86.9 |   54.1 |
-----------------------------------------------------
Lcov coverage report has been generated at file:///Users/kt3k/denoland/std/coverage/lcov.info
HTML coverage report has been generated at file:///Users/kt3k/denoland/std/coverage/html/index.html

Note: jest --coverage outputs 'summary' and 'lcov' reports by default. This outputs 'html' reports in addition to them.


Planning to land for Deno 2.3

@kt3k kt3k added the ci-draft Run the CI on draft PRs. label Feb 23, 2025
@kt3k kt3k marked this pull request as ready for review February 25, 2025 00:47
@bartlomieju bartlomieju added this to the 2.3.0 milestone Feb 25, 2025
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea 👍

) -> Result<(), AnyError> {
if coverage_flags.files.include.is_empty() {
if files_include.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this function should remove previously generated coverage before dumping new reports to the directory. Otherwise the results might be skewed from previous runs. WDYT?

Copy link
Member Author

@kt3k kt3k Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Now deno test --coverage clears the reports & raw data from the previous runs. It still keeps the contents of coverage_dir when --coverage-raw-data-only specified (and --clean not specified) to support the advanced scenarios.

_coverage_root: &Path,
file_reports: &[(CoverageReport, String)],
) {
file_reports.iter().for_each(|(report, file_text)| {
self.report(report, file_text).unwrap();
});
if let Some((report, _)) = file_reports.first() {
if let Some(ref output) = report.output {
let path = output.canonicalize().unwrap().to_string_lossy().to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unwrap is sus here 😬 maybe consider failing gracefully with an error message? Also you don't need to do the conversion to string first - Url::from_file_path will accept a PathBuf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Now it prints error message when .canonicalize failed

@kt3k kt3k removed the ci-draft Run the CI on draft PRs. label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge deno coverage to deno test --coverage with 3 default outputs
2 participants