-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, it was not possible to create fixtures that loaded asynchronously. It was possible to work around this limitation on the JVM by awaiting on futures, but there was no workaround for Scala.js. This commit adds support to return futures (and anything that converts to futures) from the beforeAll/beforeEach/afterEach/afterAll methods. Supersedes #418. This commit is inspired by that PR but uses a different approach: - No new `AsyncFixture[T]` type. This simplies the logic in `MUnitRunner` and reduces the size of the MUnit public API. The downside is that we introduce a breaking change to the existing `Fixture[T]` API, which will require bumping the version to v1.0.0 for the next release. - This approach supports any `Future`-like values by hooking into the default evaluation of test bodies via `munitValueTransforms`. Co-authored-by: Daniel Esik <e.danicheg@yandex.ru>
- Loading branch information
Showing
24 changed files
with
466 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package munit | ||
|
||
class BeforeEach( | ||
val test: Test | ||
) extends Serializable | ||
|
||
class AfterEach( | ||
val test: Test | ||
) extends Serializable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package munit | ||
|
||
/** | ||
* @param name The name of this fixture, used for displaying an error message if | ||
* `beforeAll()` or `afterAll()` fail. | ||
*/ | ||
abstract class Fixture[T](val fixtureName: String) { | ||
|
||
/** The value produced by this suite-local fixture that can be reused for all test cases. */ | ||
def apply(): T | ||
|
||
/** Runs once before the test suite starts */ | ||
def beforeAll(): Any = () | ||
|
||
/** | ||
* Runs before each individual test case. | ||
* An error in this method aborts the test case. | ||
*/ | ||
def beforeEach(context: BeforeEach): Any = () | ||
|
||
/** Runs after each individual test case. */ | ||
def afterEach(context: AfterEach): Any = () | ||
|
||
/** Runs once after the test suite has finished, regardless if the tests failed or not. */ | ||
def afterAll(): Any = () | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package munit | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* Extend this class if you want to create a Fixture where all methods have `Future[Any]` as the result type. | ||
*/ | ||
abstract class FutureFixture[T](name: String) extends Fixture[Future[T]](name) { | ||
override def beforeAll(): Future[Any] = Future.successful(()) | ||
override def beforeEach(context: BeforeEach): Future[Any] = | ||
Future.successful(()) | ||
override def afterEach(context: AfterEach): Future[Any] = | ||
Future.successful(()) | ||
override def afterAll(): Future[Any] = Future.successful(()) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.