denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.28k stars 5.36k forks source link

Deno.bench, Deno.test in the same file break each other #23041

Closed rotu closed 7 months ago

rotu commented 7 months ago

Version: Deno 1.40.5, 1.41.3

If you have both tests and benchmarks in the same file, both deno test and deno bench fail. This appears to work in 1.39.4.

// example.js
Deno.test('atest', async () => {})
Deno.bench('abench', async () => {})
$ deno test example.js 
Check file:///Users/dan/Source/MiniProjects/example.js
Uncaught error from ./example.js FAILED

 ERRORS 

./example.js (uncaught error)
error: (in promise) TypeError: ops.op_register_bench is not a function
Deno.bench('abench', async () => {})
     ^
    at Object.bench (ext:cli/40_bench.js:53:32)
    at file:///Users/dan/Source/MiniProjects/example.js:2:6
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

 FAILURES 

./example.js (uncaught error)

FAILED | 0 passed | 1 failed (0ms)

error: Test failed

Stack backtrace:
   0: std::backtrace::Backtrace::capture
   1: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   2: deno_core::error::generic_error
   3: deno::tools::test::report_tests::{{closure}}
   4: <deno_unsync::task::MaskFutureAsSend<F> as core::future::future::Future>::poll
   5: tokio::runtime::task::raw::poll
   6: deno::main
   7: std::sys_common::backtrace::__rust_begin_short_backtrace
   8: _main

$ deno bench example.js 
error: (in promise) TypeError: op_register_test is not a function
Deno.test('atest', async () => {})
     ^
    at testInner (ext:cli/40_test.js:472:18)
    at Object.test (ext:cli/40_test.js:499:10)
    at file:///Users/dan/Source/MiniProjects/example.js:1:6
This error was not caught from a benchmark and caused the bench runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

error: Bench failed

Stack backtrace:
   0: std::backtrace::Backtrace::capture
   1: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   2: deno_core::error::generic_error
   3: <deno_unsync::task::MaskFutureAsSend<F> as core::future::future::Future>::poll
   4: tokio::runtime::task::raw::poll
   5: deno::main
   6: std::sys_common::backtrace::__rust_begin_short_backtrace
   7: _main
rotu commented 7 months ago

I'm thinking this was caused by #22112, namely removing the supposedly unused checks in https://github.com/mmastrac/deno/commit/c8dd0c7c1470a6c7ab3751304b17c892343ffe6f