diff options
| author | Matt Mastracci <matthew@mastracci.com> | 2024-05-22 08:08:27 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-22 08:08:27 -0600 |
| commit | 596a2996cf777809fdefdb05a73a5b6253a5c285 (patch) | |
| tree | aba11527acb26f3fa3176944498fb8521a6368a7 /cli/tools/test/reporters | |
| parent | 7ab7a14db74b037ca8b035a04c28ac0b6e30e716 (diff) | |
feat(cli): Add slow test warning (#23874)
By default, uses a 60 second timeout, backing off 2x each time (can be
overridden using the hidden `DENO_SLOW_TEST_TIMEOUT` which we implement
only really for spec testing.
```
Deno.test(async function test() {
await new Promise(r => setTimeout(r, 130_000));
});
```
```
$ target/debug/deno test /tmp/test_slow.ts
Check file:///tmp/test_slow.ts
running 1 test from ../../../../../../tmp/test_slow.ts
test ...'test' is running very slowly (1m0s)
'test' is running very slowly (2m0s)
ok (2m10s)
ok | 1 passed | 0 failed (2m10s)
```
---------
Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/test/reporters')
| -rw-r--r-- | cli/tools/test/reporters/compound.rs | 6 | ||||
| -rw-r--r-- | cli/tools/test/reporters/dot.rs | 1 | ||||
| -rw-r--r-- | cli/tools/test/reporters/junit.rs | 1 | ||||
| -rw-r--r-- | cli/tools/test/reporters/mod.rs | 1 | ||||
| -rw-r--r-- | cli/tools/test/reporters/pretty.rs | 12 | ||||
| -rw-r--r-- | cli/tools/test/reporters/tap.rs | 1 |
6 files changed, 22 insertions, 0 deletions
diff --git a/cli/tools/test/reporters/compound.rs b/cli/tools/test/reporters/compound.rs index 1af0b284b..3ab7297db 100644 --- a/cli/tools/test/reporters/compound.rs +++ b/cli/tools/test/reporters/compound.rs @@ -31,6 +31,12 @@ impl TestReporter for CompoundTestReporter { } } + fn report_slow(&mut self, description: &TestDescription, elapsed: u64) { + for reporter in &mut self.test_reporters { + reporter.report_slow(description, elapsed); + } + } + fn report_output(&mut self, output: &[u8]) { for reporter in &mut self.test_reporters { reporter.report_output(output); diff --git a/cli/tools/test/reporters/dot.rs b/cli/tools/test/reporters/dot.rs index 854ef9666..8fbd59232 100644 --- a/cli/tools/test/reporters/dot.rs +++ b/cli/tools/test/reporters/dot.rs @@ -95,6 +95,7 @@ impl TestReporter for DotTestReporter { std::io::stdout().flush().unwrap(); } + fn report_slow(&mut self, _description: &TestDescription, _elapsed: u64) {} fn report_output(&mut self, _output: &[u8]) {} fn report_result( diff --git a/cli/tools/test/reporters/junit.rs b/cli/tools/test/reporters/junit.rs index eea1d2aca..4b69218df 100644 --- a/cli/tools/test/reporters/junit.rs +++ b/cli/tools/test/reporters/junit.rs @@ -92,6 +92,7 @@ impl TestReporter for JunitTestReporter { fn report_plan(&mut self, _plan: &TestPlan) {} + fn report_slow(&mut self, _description: &TestDescription, _elapsed: u64) {} fn report_wait(&mut self, _description: &TestDescription) {} fn report_output(&mut self, _output: &[u8]) { diff --git a/cli/tools/test/reporters/mod.rs b/cli/tools/test/reporters/mod.rs index a152029c4..07351e9c3 100644 --- a/cli/tools/test/reporters/mod.rs +++ b/cli/tools/test/reporters/mod.rs @@ -19,6 +19,7 @@ pub trait TestReporter { fn report_register(&mut self, description: &TestDescription); fn report_plan(&mut self, plan: &TestPlan); fn report_wait(&mut self, description: &TestDescription); + fn report_slow(&mut self, description: &TestDescription, elapsed: u64); fn report_output(&mut self, output: &[u8]); fn report_result( &mut self, diff --git a/cli/tools/test/reporters/pretty.rs b/cli/tools/test/reporters/pretty.rs index f9121a482..cb9f2c435 100644 --- a/cli/tools/test/reporters/pretty.rs +++ b/cli/tools/test/reporters/pretty.rs @@ -197,6 +197,18 @@ impl TestReporter for PrettyTestReporter { self.started_tests = true; } + fn report_slow(&mut self, description: &TestDescription, elapsed: u64) { + writeln!( + &mut self.writer, + "{}", + colors::yellow_bold(format!( + "'{}' has been running for over {}", + description.name, + colors::gray(format!("({})", display::human_elapsed(elapsed.into()))), + )) + ) + .unwrap(); + } fn report_output(&mut self, output: &[u8]) { if !self.echo_output { return; diff --git a/cli/tools/test/reporters/tap.rs b/cli/tools/test/reporters/tap.rs index 6dc690e6b..62cb58a83 100644 --- a/cli/tools/test/reporters/tap.rs +++ b/cli/tools/test/reporters/tap.rs @@ -140,6 +140,7 @@ impl TestReporter for TapTestReporter { std::io::stdout().flush().unwrap(); } + fn report_slow(&mut self, _description: &TestDescription, _elapsed: u64) {} fn report_output(&mut self, _output: &[u8]) {} fn report_result( |
