deno icon indicating copy to clipboard operation
deno copied to clipboard

Bug: `vitest run --coverage` crashes with panic

Open yasaichi opened this issue 1 year ago • 7 comments

Version: Deno 1.45.5

I ran into the following error (panic) when running DENO_FUTURE=1 deno run -A npm:vitest run --coverage:

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: macos aarch64
Version: 1.45.5
Args: ["/Users/yuichigoto/.local/share/mise/installs/deno/1.45.5/bin/deno", "run", "-A", "npm:vitest", "run", "--coverage"]

thread 'main' panicked at cli/module_loader.rs:616:7:
internal error: entered unreachable code: Deno bug. node:inspector was misconfigured internally.
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: deno::module_loader::CliModuleLoaderInner<TGraphContainer>::load_prepared_module_or_defer_emit
   3: <deno::module_loader::CliModuleLoader<TGraphContainer> as deno_core::modules::loaders::ModuleLoader>::load::{{closure}}
   4: deno_core::modules::recursive_load::RecursiveModuleLoad::register_and_recurse_inner::{{closure}}
   5: <deno_core::modules::recursive_load::RecursiveModuleLoad as futures_core::stream::Stream>::poll_next
   6: deno_core::modules::map::ModuleMap::poll_progress
   7: deno_core::runtime::jsruntime::JsRuntime::poll_event_loop
   8: deno_core::runtime::jsruntime::JsRuntime::run_event_loop::{{closure}}
   9: deno_runtime::worker::MainWorker::run_event_loop::{{closure}}
  10: deno::worker::CliMainWorker::run::{{closure}}
  11: deno::tools::run::run_script::{{closure}}
  12: deno::spawn_subcommand::{{closure}}
  13: <deno_unsync::tokio::task::MaskFutureAsSend<F> as core::future::future::Future>::poll
  14: tokio::runtime::task::raw::poll
  15: deno::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This bug always happens when trying to measure test coverage with @vitest/coverage-v8. Here is the repo to reproduce it. Thanks you in advance! https://github.com/yasaichi-sandbox/deno-vitest-cov

NOTE: @vitest/coverage-istanbul is another way to measure test coverage and works well with Deno. One cons is that it seems slower than using v8 because of an effort for instrumentation.

yasaichi avatar Aug 12 '24 15:08 yasaichi

Looks like this is caused by node:inspector not being well supported in Deno at the moment.

marvinhagemeister avatar Aug 12 '24 15:08 marvinhagemeister

Related to #23882

yasaichi avatar Aug 13 '24 13:08 yasaichi

I am feeling sorry that all I can do is report bugs. Unfortunately, I ran into the following new error while trying to measure test coverage in the repo with the HEAD of Deno.

Error: Not implemented: inspector.Session.prototype.constructor
 ❯ notImplemented ext:deno_node/_utils.ts:38:9
 ❯ new Session node:inspector:22:5
 ❯ node_modules/.pnpm/@[email protected][email protected]/node_modules/@vitest/coverage-v8/dist/index.js:4:17

It means that thanks to @marvinhagemeister, the bug I originally reported was resolved.

yasaichi avatar Aug 14 '24 13:08 yasaichi

Yeah the whole node:inspector code is basically just stubs at the moment. We need to add code to actually attach and create an inspector.

marvinhagemeister avatar Aug 14 '24 13:08 marvinhagemeister

@marvinhagemeister Thank you so much for your hard work around this topic. BTW as for this issue, feel free to close it.

yasaichi avatar Aug 14 '24 14:08 yasaichi

Due to security implications the Deno team does not plan to polyfill these APIs. https://docs.deno.com/runtime/manual/node/compatibility/

Is the statement about node:inspector still true even now? If so, should I think that I will never be able to measure test coverage in any nodejs-based testing frameworks relying on the module in the future?

yasaichi avatar Aug 15 '24 06:08 yasaichi

This statement isn't true. We're currently in the process of updating our documentation in preparation for Deno 2.

marvinhagemeister avatar Aug 15 '24 07:08 marvinhagemeister

The error now looks like the below (Updated the title):

Error: Not implemented: inspector.Session.prototype.connect
 ❯ notImplemented ext:deno_node/_utils.ts:9:9
 ❯ Session.connect node:inspector:12:5
 ❯ startCoverage node_modules/.deno/@[email protected]/node_modules/@vitest/coverage-v8/dist/index.js:6:11
 ❯ Object.startCoverage node_modules/.deno/@[email protected]/node_modules/@vitest/coverage-v8/dist/index.js:44:12
 ❯ startCoverageInsideWorker node_modules/.deno/[email protected]/node_modules/vitest/dist/chunks/coverage.CqfT4xaf.js:47:42
 ❯ run node_modules/.deno/[email protected]/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:105:3
 ❯ runBaseTests node_modules/.deno/[email protected]/node_modules/vitest/dist/chunks/base.CC5R_kgU.js:31:3
 ❯ ForksBaseWorker.executeTests node_modules/.deno/[email protected]/node_modules/vitest/dist/workers/forks.js:25:7
 ❯ execute node_modules/.deno/[email protected]/node_modules/vitest/dist/worker.js:115:5
 ❯ onMessage node_modules/.deno/[email protected]/node_modules/tinypool/dist/entry/process.js:55:20

kt3k avatar Sep 10 '24 09:09 kt3k

#25198 might solve this issue

kt3k avatar Sep 10 '24 09:09 kt3k