diff --git a/munit/js/src/main/scala/munit/internal/PlatformCompat.scala b/munit/js/src/main/scala/munit/internal/PlatformCompat.scala index b5ed7e24..7a1ac67b 100644 --- a/munit/js/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/js/src/main/scala/munit/internal/PlatformCompat.scala @@ -36,16 +36,20 @@ object PlatformCompat { ec: ExecutionContext ): Future[T] = { val onComplete = Promise[T]() - val timeoutHandle = timers.setTimeout(duration.toMillis) { - onComplete.tryFailure( - new TimeoutException(s"test timed out after $duration") - ) - } + val timeoutHandle = + if (duration.isFinite) + Some(timers.setTimeout(duration.toMillis) { + onComplete.tryFailure( + new TimeoutException(s"test timed out after $duration") + ) + }) + else + None ec.execute(new Runnable { def run(): Unit = { startFuture().onComplete { result => onComplete.tryComplete(result) - timers.clearTimeout(timeoutHandle) + timeoutHandle.foreach(timers.clearTimeout(_)) }(ec) } }) diff --git a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala index ae6b19dc..c21126ef 100644 --- a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala @@ -56,19 +56,25 @@ object PlatformCompat { ec: ExecutionContext ): Future[T] = { val onComplete = Promise[T]() - val timeout = sh.schedule[Unit]( - () => - onComplete.tryFailure( - new TimeoutException(s"test timed out after $duration") - ), - duration.toMillis, - TimeUnit.MILLISECONDS - ) + val timeout = + if (duration.isFinite) + Some( + sh.schedule[Unit]( + () => + onComplete.tryFailure( + new TimeoutException(s"test timed out after $duration") + ), + duration.toMillis, + TimeUnit.MILLISECONDS + ) + ) + else + None ec.execute(new Runnable { def run(): Unit = { startFuture().onComplete { result => onComplete.tryComplete(result) - timeout.cancel(false) + timeout.foreach(_.cancel(false)) }(ec) } })