Skip to content

Commit 750ffb2

Browse files
committed
Fix test error caused by mangled jsBrowserTest callstacks
1 parent 2064568 commit 750ffb2

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/commonMain/kotlin/com/varabyte/truthish/failure/FailureStrategy.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,45 @@ class DeferredStrategy(private val summary: String? = null) : FailureStrategy {
5555
private val reports = mutableListOf<Report>()
5656

5757
// e.g. JVM: at com.varabyte.truthish.AssertAllTest.assertAllCallstacksAreCorrect(AssertAllTest.kt:133)
58-
// e.g. Node #1: at /Users/d9n/Code/1p/truthish/src/commonTest/kotlin/com/varabyte/truthish/AssertAllTest.kt:18:25
59-
// e.g. Node #2: at AssertAllTest.protoOf.assertAllCollectsMultipleErrors_tljnxt_k$ (/Users/d9n/Code/1p/truthish/src/commonTest/kotlin/com/varabyte/truthish/AssertAllTest.kt:14:13)
60-
private val jvmNodeCallstackRegex = Regex("\\s+at ?[^ ]* ?([^ ]+\\.kt:\\d+[^ ]+)")
58+
// exclude slashes so as not to clash with js node
59+
private val jvmCallstackRegex = Regex("\\s+at ([^ /]+\\.kt:\\d+[^ ]+)")
60+
61+
// e.g. Node: at /Users/d9n/Code/1p/truthish/src/commonTest/kotlin/com/varabyte/truthish/AssertAllTest.kt:18:25
62+
// NOTE: There are also callstack lines like "at AssertAllTest.protoOf.assertAllCollectsMultipleErrors_tljnxt_k$ (/Users/d9n/Code/1p/truthish/src/commonTest/kotlin/com/varabyte/truthish/AssertAllTest.kt:14:13)"
63+
// but I think we can skip over them and still get the user callstack line that we want.
64+
private val jsNodeCallstackRegex = Regex("\\s+at (/[^)]+)\\)?")
65+
6166
// e.g. at 1 test.kexe 0x104adf41f kfun:com.varabyte.truthish.AssertAllTest#assertAllCallstacksAreCorrect(){} + 1847 (/Users/d9n/Code/1p/truthish/src/commonTest/kotlin/com/varabyte/truthish/AssertAllTest.kt:133:21)
6267
private val knCallstackRegex = Regex("\\s+at.+kfun:(.+)")
6368

69+
// e.g. at protoOf.assertAllCallstacksAreCorrect_nyk2hi(/var/folders/5x/f_r3s2p53rx2l_lffc7m9nmw0000gn/T/_karma_webpack_413015/commons.js:29616)
70+
private val jsBrowserCallstackRegex = Regex("\\.js\\?")
71+
6472
override fun handle(report: Report) {
6573
reports.add(report)
6674

6775
val callstackLine =
6876
Throwable()
6977
.stackTraceToString()
70-
.takeIf { it.contains("common.js") }
78+
// Reject JS browser callstacks because they're mangled
79+
.takeUnless { jsBrowserCallstackRegex.containsMatchIn(it) }
7180
?.split("\n")
7281
?.drop(1) // Drop "java.lang.Throwable" line
7382
?.asSequence()
7483
?.mapNotNull { stackTraceLine ->
75-
jvmNodeCallstackRegex.matchEntire(stackTraceLine) ?: knCallstackRegex.matchEntire(stackTraceLine)
84+
jvmCallstackRegex.matchEntire(stackTraceLine)
85+
?: knCallstackRegex.matchEntire(stackTraceLine)
86+
?: jsNodeCallstackRegex.matchEntire(stackTraceLine)
7687
}
7788
?.map { match -> match.groupValues[1] }
7889
?.filterNot {
7990
it.startsWith("com.varabyte.truthish.failure.")
8091
|| it.startsWith("com.varabyte.truthish.subjects.")
8192
|| it.startsWith("kotlin.") // Kotlin/Native
82-
|| it.contains("/com/varabyte/truthish/failure/")
83-
|| it.contains("/com/varabyte/truthish/subjects/")
84-
|| it.contains("/kotlin/js/runtime/")
93+
|| it.contains("/com/varabyte/truthish/failure/") // NodeJS
94+
|| it.contains("/com/varabyte/truthish/subjects/") // NodeJS
95+
|| it.contains("/kotlin/js/runtime/") // NodeJS
96+
|| it.contains("/src/kotlin/util/") // NodeJS
8597
}
8698
?.firstOrNull()
8799

0 commit comments

Comments
 (0)