Issue 1:
Problem description

Running the deno coverage command against the coverage report of code that printed any unicode character will lead to a panic.

Steps to reproduce

Create a sample file that prints any unicode character, e.g. app.ts:

export function cheers() {
console.log('🍻');
}

cheers();

Create a simple test that calls the given function, e.g. app.test.ts:

import { cheers } from './app.ts'

Deno.test("It should print an emoji", () => {
cheers();
})

Now try to create a coverage report and watch Deno panic.

Output without backtrace

[tmp]➡ deno run app.ts
🍻
[tmp]➡ deno test app.test.ts --coverage=cov
🍻
running 1 test from file:///tmp/app.test.ts
test It should print an emoji ...🍻

ok (6ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (64ms)

[tmp]➡ deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: ["deno", "coverage", "cov"]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error("invalid unicode code point", line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[tmp]➡

Output with backtrace

[tmp]➡ RUST_BACKTRACE=1 deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: ["deno", "coverage", "cov"]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error("invalid unicode code point", line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::result::unwrap_failed
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
3: deno::tools::coverage::cover_files::{{closure}}
4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
5: deno::main::{{closure}}
6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
7: deno_runtime::tokio_util::run_basic
8: deno::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Issue 2:
Hi, I am having an issue where the output of deno coverage appears inaccurate. I was able to narrow it down to a minimal example; instructions below. I hope it is reproducible. The problem goes away if the emojis or the unused function h are removed. Removing a single emoji removes line 2 from the coverage report, but still inaccurately keeps line 3. I have not tested it with other emojis ☺️

This is the mod.ts file:

export default function () {
return "📣❓";
}

function h() {}

This is the mod_test.ts file:

import f from "./mod.ts";

Deno.test("test", () => {
f()
});

These are the shell commands:

deno test --coverage=.cov
deno coverage .cov
rm -rf .cov

This is the output of deno coverage. As far as I understand it, line 2 and 3 should be covered:

cover file:///home/mod.ts ... 25.000% (1/4)
2 | return "📣❓";
3 | }
-----|-----
5 | function h() {}

This is the output of deno --version:

deno 1.11.0 (release, x86_64-unknown-linux-gnu)
v8 9.1.269.35
typescript 4.3.2