Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hotfix
  • Loading branch information
zishkaz committed Apr 5, 2023
commit 7bb5cde7d4728d4f22c4bc6981bebaf10c348c1c
4 changes: 2 additions & 2 deletions utbot-js/src/main/kotlin/api/JsTestGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class JsTestGenerator(
* Returns String representation of generated tests.
*/
fun run(): String {
parsedFile = runParser(fileText)
parsedFile = runParser(fileText, sourceFilePath)
val packageJson = PackageJsonService(
sourceFilePath,
File(projectPath),
Expand Down Expand Up @@ -274,7 +274,7 @@ class JsTestGenerator(
)
val collectedValues = mutableListOf<List<UtModel>>()
// .location field gets us "jsFile:A:B", then we get A and B as ints
val funcLocation = funcNode.firstChild!!.location.substringAfter("jsFile:")
val funcLocation = funcNode.firstChild!!.location.substringAfter("${funcNode.sourceFileName}:")
.split(":").map { it.toInt() }
logger.info { "Function under test location according to parser is [${funcLocation[0]}, ${funcLocation[1]}]" }
val instrService = InstrumentationService(context, funcLocation[0] to funcLocation[1])
Expand Down
4 changes: 2 additions & 2 deletions utbot-js/src/main/kotlin/parser/JsParserUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import parser.visitors.JsClassAstVisitor
@Suppress("DEPRECATION")
object JsParserUtils {

fun runParser(fileText: String): Node =
Compiler().parse(SourceFile.fromCode("jsFile", fileText))
fun runParser(fileText: String, filePath: String): Node =
Compiler().parse(SourceFile.fromCode(filePath, fileText))

// TODO SEVERE: function only works in the same file scope. Add search in exports.
fun searchForClassDecl(className: String?, parsedFile: Node, strict: Boolean = false): Node? {
Expand Down
4 changes: 2 additions & 2 deletions utbot-js/src/main/kotlin/service/InstrumentationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class InstrumentationService(context: ServiceContext, private val funcDeclOffset
timeout = settings.timeout,
)
val instrumentedFileText = File(instrumentedFilePath).readText()
parsedInstrFile = runParser(instrumentedFileText)
parsedInstrFile = runParser(instrumentedFileText, instrumentedFilePath)
val covFunRegex = Regex("function (cov_.*)\\(\\).*")
val funName = covFunRegex.find(instrumentedFileText.takeWhile { it != '{' })?.groups?.get(1)?.value
?: throw IllegalStateException("")
Expand All @@ -155,7 +155,7 @@ class InstrumentationService(context: ServiceContext, private val funcDeclOffset

private fun File.writeTextAndUpdate(newText: String) {
this.writeText(newText)
parsedInstrFile = runParser(File(instrumentedFilePath).readText())
parsedInstrFile = runParser(File(instrumentedFilePath).readText(), instrumentedFilePath)
}

private fun fixImportsInInstrumentedFile(): String {
Expand Down