Compare JS source maps in readable way in IC tests
This commit is contained in:
+25
-4
@@ -17,7 +17,11 @@
|
||||
package org.jetbrains.kotlin.incremental.testingUtils
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream
|
||||
import org.jetbrains.kotlin.incremental.LocalFileKotlinClass
|
||||
import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapError
|
||||
import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapParser
|
||||
import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapSuccess
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.metadata.DebugProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf
|
||||
@@ -32,10 +36,7 @@ import org.jetbrains.org.objectweb.asm.ClassReader
|
||||
import org.jetbrains.org.objectweb.asm.util.TraceClassVisitor
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertNotNull
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.util.zip.CRC32
|
||||
import java.util.zip.GZIPInputStream
|
||||
@@ -186,6 +187,22 @@ private fun metaJsToString(metaJsFile: File): String {
|
||||
return out.toString()
|
||||
}
|
||||
|
||||
private fun sourceMapFileToString(sourceMapFile: File, generatedJsFile: File): String {
|
||||
val sourceMapParseResult = SourceMapParser.parse(StringReader(sourceMapFile.readText()))
|
||||
return when (sourceMapParseResult) {
|
||||
is SourceMapSuccess -> {
|
||||
val bytesOut = ByteArrayOutputStream()
|
||||
PrintStream(bytesOut).use { printStream ->
|
||||
sourceMapParseResult.value.debugVerbose(printStream, generatedJsFile)
|
||||
}
|
||||
bytesOut.toString()
|
||||
}
|
||||
is SourceMapError -> {
|
||||
sourceMapParseResult.message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getExtensionRegistry(): ExtensionRegistry {
|
||||
val registry = ExtensionRegistry.newInstance()!!
|
||||
DebugJvmProtoBuf.registerAllExtensions(registry)
|
||||
@@ -200,6 +217,10 @@ private fun fileToStringRepresentation(file: File): String {
|
||||
file.name.endsWith(KotlinJavascriptMetadataUtils.META_JS_SUFFIX) -> {
|
||||
metaJsToString(file)
|
||||
}
|
||||
file.name.endsWith(".js.map") -> {
|
||||
val generatedJsPath = file.canonicalPath.removeSuffix(".map")
|
||||
sourceMapFileToString(file, File(generatedJsPath))
|
||||
}
|
||||
else -> {
|
||||
file.readText()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user