Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JS macrotask executor for CE 2 #194

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ lazy val ce2 = crossProject(JSPlatform, JVMPlatform)
Test / unmanagedSourceDirectories += baseDirectory.value / "../../common/jvm/src/test/scala"
)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
Compile / unmanagedSourceDirectories += baseDirectory.value / "../../common/js/src/main/scala",
Test / unmanagedSourceDirectories += baseDirectory.value / "../../common/js/src/test/scala",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
Expand Down
5 changes: 5 additions & 0 deletions ce2/js/src/main/scala/munit/CatsEffectSuitePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
package munit

import cats.effect.IO
import org.scalajs.macrotaskexecutor.MacrotaskExecutor

import scala.concurrent.ExecutionContext

private[munit] trait CatsEffectSuitePlatform { self: CatsEffectSuite =>

private[munit] def unsafeRunSyncOrForget[A](ioa: IO[A]): Unit = ioa.unsafeRunAsyncAndForget()

private[munit] def suiteExecutionContext: ExecutionContext = MacrotaskExecutor

}
4 changes: 4 additions & 0 deletions ce2/jvm/src/main/scala/munit/CatsEffectSuitePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ package munit

import cats.effect.IO

import scala.concurrent.ExecutionContext

private[munit] trait CatsEffectSuitePlatform { self: CatsEffectSuite =>

private[munit] def unsafeRunSyncOrForget[A](ioa: IO[A]): Unit = {
ioa.unsafeRunSync()
()
}

private[munit] def suiteExecutionContext: ExecutionContext = ExecutionContext.global

}
6 changes: 4 additions & 2 deletions ce2/shared/src/main/scala/munit/CatsEffectSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ abstract class CatsEffectSuite
with CatsEffectFixtures
with CatsEffectFunFixtures {

private val ec: ExecutionContext = suiteExecutionContext

implicit def munitContextShift: ContextShift[IO] =
IO.contextShift(ExecutionContext.global)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use munitExecutionContext instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was intentional #65

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, munit uses parisitic EC ?? thanks for the pointer.

IO.contextShift(ec)

implicit def munitTimer: Timer[IO] =
IO.timer(ExecutionContext.global)
IO.timer(ec)

override def munitValueTransforms: List[ValueTransform] =
super.munitValueTransforms ++ List(munitIOTransform, munitSyncIOTransform)
Expand Down