Skip to content

Commit 80c0e68

Browse files
authored
Fix package.json search for JavaScript (#2040)
1 parent 164f2fc commit 80c0e68

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

utbot-js/src/main/kotlin/api/JsTestGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class JsTestGenerator(
113113
)
114114
context.packageJson = PackageJsonService(
115115
sourceFilePath,
116-
projectPath,
116+
File(projectPath),
117117
).findClosestConfig()
118118
val paramNames = mutableMapOf<ExecutableId, List<String>>()
119119
val testSets = mutableListOf<CgMethodTestSet>()

utbot-js/src/main/kotlin/service/PackageJsonService.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ data class PackageJson(
1515

1616
class PackageJsonService(
1717
private val filePathToInference: String,
18-
private val projectPath: String
18+
private val projectDir: File
1919
) {
2020

2121
fun findClosestConfig(): PackageJson {
22-
var currDir = File(filePathToInference.substringBeforeLast("/"))
22+
var currDir = File(filePathToInference)
2323
do {
24+
currDir = currDir.parentFile
2425
val matchingFiles: Array<File> = currDir.listFiles(
2526
FilenameFilter { _, name ->
2627
return@FilenameFilter name == "package.json"
2728
}
2829
) ?: throw IllegalStateException("Error occurred while scanning file system")
2930
if (matchingFiles.isNotEmpty()) return parseConfig(matchingFiles.first())
30-
currDir = currDir.parentFile
31-
} while (currDir.path != projectPath)
31+
} while (currDir != projectDir)
3232
return PackageJson.defaultConfig
3333
}
3434

utbot-js/src/main/kotlin/settings/JsPackagesSettings.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package settings
22

3+
import java.io.File
34
import org.utbot.common.PathUtil.replaceSeparator
45
import service.PackageJsonService
56
import settings.JsPackagesSettings.mochaData
@@ -51,7 +52,7 @@ class PackageDataService(
5152
private val projectPath: String,
5253
private val pathToNpm: String,
5354
) {
54-
private val packageJson = PackageJsonService(filePathToInference, projectPath).findClosestConfig()
55+
private val packageJson = PackageJsonService(filePathToInference, File(projectPath)).findClosestConfig()
5556

5657
companion object {
5758
var nycPath: String = ""

0 commit comments

Comments
 (0)