Fix webpack delimiter and add test on short path in stack trace

This commit is contained in:
Ilya Goncharov
2019-10-04 15:09:19 +03:00
parent f7ba1c56e2
commit 6688df8f6a
2 changed files with 23 additions and 9 deletions
@@ -9,7 +9,7 @@ private const val WEBPACK_PROTOCOL = "webpack://"
private const val KARMA_SOURCE_MAP_DELIMITER = " <-" private const val KARMA_SOURCE_MAP_DELIMITER = " <-"
private const val STACK_TRACE_DELIMITER = "at " private const val STACK_TRACE_DELIMITER = "at "
private const val WEBPACK_LOCAL_DELIMITER = ".." private const val WEBPACK_LOCAL_DELIMITER = "../"
fun processKarmaStackTrace(stackTrace: String): String { fun processKarmaStackTrace(stackTrace: String): String {
return stackTrace.lines() return stackTrace.lines()
@@ -28,24 +28,29 @@ fun processKarmaStackTrace(stackTrace: String): String {
fun processWebpackName(line: String): String { fun processWebpackName(line: String): String {
// example: "at MyTest../kotlin/check-js-test-test.js.MyTest.foo (/src/test/kotlin/MyTest.kt:7:8)" // example: "at MyTest../kotlin/check-js-test-test.js.MyTest.foo (/src/test/kotlin/MyTest.kt:7:8)"
// should be "at MyTest.foo (/src/test/kotlin/MyTest.kt:7:8)" // should be "at MyTest.foo (/src/test/kotlin/MyTest.kt:7:8)"
val stackTraceDelimiter = line.indexOf(STACK_TRACE_DELIMITER) val stackTraceDelimiterIndex = line.indexOf(STACK_TRACE_DELIMITER)
val webpackLocalDelimiter = line.indexOf(WEBPACK_LOCAL_DELIMITER) val webpackLocalDelimiterIndex = line.indexOf(WEBPACK_LOCAL_DELIMITER)
if (stackTraceDelimiter == -1 || webpackLocalDelimiter == -1) { if (stackTraceDelimiterIndex == -1 || webpackLocalDelimiterIndex == -1) {
return line return line
} }
val traceStartIndex = stackTraceDelimiter + STACK_TRACE_DELIMITER.length val traceStartIndex = stackTraceDelimiterIndex + STACK_TRACE_DELIMITER.length
val name = line.substring( val name = line.substring(
traceStartIndex, traceStartIndex,
webpackLocalDelimiter webpackLocalDelimiterIndex
) // MyTest ) // MyTest
val fileStart = line.indexOf("(") val fileStartIndex = line.indexOf("(")
val fullJsName = line.substring(webpackLocalDelimiter, fileStart) // ../kotlin/check-js-test-test.js.MyTest.foo
if (webpackLocalDelimiterIndex > fileStartIndex) {
return line
}
val fullJsName = line.substring(webpackLocalDelimiterIndex, fileStartIndex) // ../kotlin/check-js-test-test.js.MyTest.foo
val nameIndex = fullJsName.indexOf(name) val nameIndex = fullJsName.indexOf(name)
if (nameIndex == -1) { if (nameIndex == -1) {
return line return line
} }
return line.replaceRange(traceStartIndex, fileStart, fullJsName.substring(nameIndex)) return line.replaceRange(traceStartIndex, fileStartIndex, fullJsName.substring(nameIndex))
} }
@@ -58,6 +58,15 @@ class KarmaStackTraceProcessorKtTest {
) )
} }
@Test
fun notProcessShortPah() {
val line = "at Foo.bar(../Foo.kt)"
assertEquals(
line,
processWebpackName(line)
)
}
@Test @Test
fun notProcessMessage() { fun notProcessMessage() {
val line = "AssertionError: Expected value to be true." val line = "AssertionError: Expected value to be true."