Skip to content

Fix package.json search for JavaScript #2040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion utbot-js/src/main/kotlin/api/JsTestGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class JsTestGenerator(
)
context.packageJson = PackageJsonService(
sourceFilePath,
projectPath,
File(projectPath),
).findClosestConfig()
val paramNames = mutableMapOf<ExecutableId, List<String>>()
val testSets = mutableListOf<CgMethodTestSet>()
Expand Down
8 changes: 4 additions & 4 deletions utbot-js/src/main/kotlin/service/PackageJsonService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ data class PackageJson(

class PackageJsonService(
private val filePathToInference: String,
private val projectPath: String
private val projectDir: File
) {

fun findClosestConfig(): PackageJson {
var currDir = File(filePathToInference.substringBeforeLast("/"))
var currDir = File(filePathToInference)
do {
currDir = currDir.parentFile
val matchingFiles: Array<File> = currDir.listFiles(
FilenameFilter { _, name ->
return@FilenameFilter name == "package.json"
}
) ?: throw IllegalStateException("Error occurred while scanning file system")
if (matchingFiles.isNotEmpty()) return parseConfig(matchingFiles.first())
currDir = currDir.parentFile
} while (currDir.path != projectPath)
} while (currDir != projectDir)
return PackageJson.defaultConfig
}

Expand Down
3 changes: 2 additions & 1 deletion utbot-js/src/main/kotlin/settings/JsPackagesSettings.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package settings

import java.io.File
import org.utbot.common.PathUtil.replaceSeparator
import service.PackageJsonService
import settings.JsPackagesSettings.mochaData
Expand Down Expand Up @@ -51,7 +52,7 @@ class PackageDataService(
private val projectPath: String,
private val pathToNpm: String,
) {
private val packageJson = PackageJsonService(filePathToInference, projectPath).findClosestConfig()
private val packageJson = PackageJsonService(filePathToInference, File(projectPath)).findClosestConfig()

companion object {
var nycPath: String = ""
Expand Down