Skip to content

Commit 41f750d

Browse files
committed
Make Snapshotter.snapshot() suspending
This makes all of the snapshot-using tests suspending. This requires an update to Burst, which previously didn't suspend nicely for Kotlin/JS.
1 parent c5717a1 commit 41f750d

File tree

14 files changed

+90
-76
lines changed

14 files changed

+90
-76
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ paparazzi = "1.3.2"
1111
zipline = "1.22.0"
1212
coil = "3.3.0"
1313
okio = "3.16.0"
14-
burst = "2.7.1"
14+
burst = "2.8.1"
1515

1616
[libraries]
1717
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
@@ -79,6 +79,7 @@ coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version
7979

8080
androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "8.13.0" }
8181
burst = { module = "app.cash.burst:burst", version.ref = "burst" }
82+
burst-coroutines = { module = "app.cash.burst:burst-coroutines", version.ref = "burst" }
8283
burst-gradle-plugin = { module = "app.cash.burst:burst-gradle-plugin", version.ref = "burst" }
8384
kotlinPoet = { module = "com.squareup:kotlinpoet", version = "2.2.0" }
8485
clikt = "com.github.ajalt.clikt:clikt:5.0.3"

redwood-layout-shared-test/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ kotlin {
2020
api projects.redwoodYoga
2121
api libs.kotlin.test
2222
implementation libs.burst
23+
implementation libs.burst.coroutines
24+
implementation libs.kotlinx.coroutines.test
2325
}
2426
}
2527
jvmMain {

redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractBoxTest.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import app.cash.redwood.snapshot.testing.text
3333
import app.cash.redwood.ui.Margin
3434
import app.cash.redwood.ui.dp
3535
import kotlin.test.Test
36+
import kotlinx.coroutines.test.runTest
3637

3738
@Burst
3839
abstract class AbstractBoxTest<T : Any> {
@@ -48,7 +49,7 @@ abstract class AbstractBoxTest<T : Any> {
4849
* Explicitly apply defaults to our Box instance. This is only necessary in tests; in production
4950
* the framework explicitly sets every property.
5051
*/
51-
protected fun Box<T>.applyDefaults() {
52+
protected fun Box<T>.applyDefaults() = runTest {
5253
width(Constraint.Wrap)
5354
height(Constraint.Wrap)
5455
margin(Margin.Zero)
@@ -57,13 +58,13 @@ abstract class AbstractBoxTest<T : Any> {
5758
}
5859

5960
@Test
60-
fun testEmpty_Defaults() {
61+
fun testEmpty_Defaults() = runTest {
6162
val widget = box()
6263
snapshotterFactory(widget.value).snapshot()
6364
}
6465

6566
@Test
66-
fun testEmpty_Wrap() {
67+
fun testEmpty_Wrap() = runTest {
6768
val widget = box().apply {
6869
width(Constraint.Wrap)
6970
height(Constraint.Wrap)
@@ -72,7 +73,7 @@ abstract class AbstractBoxTest<T : Any> {
7273
}
7374

7475
@Test
75-
fun testEmpty_Fill() {
76+
fun testEmpty_Fill() = runTest {
7677
val widget = box().apply {
7778
width(Constraint.Fill)
7879
height(Constraint.Fill)
@@ -98,7 +99,7 @@ abstract class AbstractBoxTest<T : Any> {
9899
CrossAxisAlignment.End,
99100
CrossAxisAlignment.Stretch,
100101
),
101-
) {
102+
) = runTest {
102103
val widget = box().apply {
103104
width(constraint)
104105
height(constraint)
@@ -130,7 +131,7 @@ abstract class AbstractBoxTest<T : Any> {
130131
}
131132

132133
@Test
133-
fun testMargins() {
134+
fun testMargins() = runTest {
134135
// Different margins allow us to know which direction start and end get applied.
135136
val asymmetric = Margin(start = 10.dp, top = 20.dp, end = 30.dp, bottom = 40.dp)
136137

@@ -156,7 +157,7 @@ abstract class AbstractBoxTest<T : Any> {
156157
}
157158

158159
@Test
159-
fun testBoxMeasurementIncludesMargins() {
160+
fun testBoxMeasurementIncludesMargins() = runTest {
160161
val container = widgetFactory.column()
161162
container.add(
162163
box().apply {
@@ -199,7 +200,7 @@ abstract class AbstractBoxTest<T : Any> {
199200
}
200201

201202
@Test
202-
fun testMarginsAndAlignment() {
203+
fun testMarginsAndAlignment() = runTest {
203204
val widget = box().apply {
204205
width(Constraint.Fill)
205206
height(Constraint.Fill)
@@ -242,7 +243,7 @@ abstract class AbstractBoxTest<T : Any> {
242243
}
243244

244245
@Test
245-
fun testMarginsAndStretch() {
246+
fun testMarginsAndStretch() = runTest {
246247
val widget = box().apply {
247248
width(Constraint.Fill)
248249
height(Constraint.Fill)
@@ -285,7 +286,7 @@ abstract class AbstractBoxTest<T : Any> {
285286
}
286287

287288
@Test
288-
fun testChildrenModifierChanges() {
289+
fun testChildrenModifierChanges() = runTest {
289290
val redColor = widgetFactory.text(
290291
modifier = MarginImpl(30.dp),
291292
text = longText(),
@@ -319,7 +320,7 @@ abstract class AbstractBoxTest<T : Any> {
319320

320321
/** The view shouldn't crash if its displayed after being detached. */
321322
@Test
322-
fun testLayoutAfterDetach() {
323+
fun testLayoutAfterDetach() = runTest {
323324
val widget = box().apply {
324325
width(Constraint.Wrap)
325326
height(Constraint.Wrap)
@@ -361,7 +362,7 @@ abstract class AbstractBoxTest<T : Any> {
361362
}
362363

363364
@Test
364-
fun testDynamicWidgetResizing() {
365+
fun testDynamicWidgetResizing() = runTest {
365366
val container = box()
366367
.apply {
367368
width(Constraint.Fill)
@@ -393,7 +394,7 @@ abstract class AbstractBoxTest<T : Any> {
393394
}
394395

395396
@Test
396-
fun testLayoutUpdatesWithoutSizeChanges() {
397+
fun testLayoutUpdatesWithoutSizeChanges() = runTest {
397398
val container = widgetFactory.column()
398399
val snapshotter = snapshotterFactory(container.value)
399400

@@ -421,7 +422,7 @@ abstract class AbstractBoxTest<T : Any> {
421422
}
422423

423424
@Test
424-
fun testChildExplicitHeight() {
425+
fun testChildExplicitHeight() = runTest {
425426
val container = box()
426427
.apply {
427428
width(Constraint.Fill)
@@ -453,7 +454,7 @@ abstract class AbstractBoxTest<T : Any> {
453454
}
454455

455456
@Test
456-
fun testChildExplicitWidth() {
457+
fun testChildExplicitWidth() = runTest {
457458
val container = box()
458459
.apply {
459460
width(Constraint.Fill)
@@ -486,7 +487,7 @@ abstract class AbstractBoxTest<T : Any> {
486487

487488
/** We had a bug where stretch alignment impacted measurement. It shouldn't. */
488489
@Test
489-
fun testStretchDoesNotImpactMeasurement() {
490+
fun testStretchDoesNotImpactMeasurement() = runTest {
490491
val container = box()
491492
.apply {
492493
width(Constraint.Fill)

0 commit comments

Comments
 (0)