Skip to content

Add Tern auto-installation for JavaScript #1781

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 2 commits into from
Feb 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import settings.JsDynamicSettings
import settings.JsExportsSettings.endComment
import settings.JsExportsSettings.startComment
import settings.JsPackagesSettings.mochaData
import settings.JsPackagesSettings.nycData
import settings.JsPackagesSettings.ternData
import settings.JsTestGenerationSettings.dummyClassName
import settings.PackageData
import utils.JsCmdExec
Expand Down Expand Up @@ -56,9 +58,9 @@ object JsDialogProcessor {
) {
override fun run(indicator: ProgressIndicator) {
invokeLater {
if (!mochaData.findPackageByNpm(model.project.basePath!!, model.pathToNPM)) {
installMissingRequirement(model.project, model.pathToNPM, mochaData)
}
checkAndInstallRequirement(model.project, model.pathToNPM, mochaData)
checkAndInstallRequirement(model.project, model.pathToNPM, nycData)
checkAndInstallRequirement(model.project, model.pathToNPM, ternData)
createDialog(model)?.let { dialogProcessor ->
if (!dialogProcessor.showAndGet()) return@invokeLater
// Since Tern.js accesses containing file, sync with file system required before test generation.
Expand Down Expand Up @@ -263,8 +265,21 @@ object JsDialogProcessor {
}
}

// TODO(MINOR): Add indicator.text for each installation
fun installMissingRequirement(project: Project, pathToNPM: String, requirement: PackageData) {
fun checkAndInstallRequirement(
project: Project,
pathToNPM: String,
requirement: PackageData,
) {
if (!requirement.findPackageByNpm(project.basePath!!, pathToNPM)) {
installMissingRequirement(project, pathToNPM, requirement)
}
}

private fun installMissingRequirement(
project: Project,
pathToNPM: String,
requirement: PackageData,
) {
val message = """
Requirement is not installed:
${requirement.packageName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class NycSourceFileChooser(val model: JsTestsModel) : TextFieldWithBrowseButton(
addBrowseFolderListener(
TextBrowseFolderListener(descriptor, model.project)
)
nycData.findPackagePath() ?: installMissingRequirement(model.project, model.pathToNPM, nycData)
text = (replaceSeparator(nycData.findPackagePath() ?: "Nyc was not found")
+ OsProvider.getProviderByOs().npmPackagePostfix)
}
Expand Down
4 changes: 1 addition & 3 deletions utbot-js/src/main/kotlin/settings/JsPackagesSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import utils.OsProvider
object JsPackagesSettings {
val mochaData: PackageData = PackageData("mocha", "-l")
val nycData: PackageData = PackageData("nyc", "-g")

// TODO(MINOR): Add tern auto installation
val ternData: PackageData? = null
val ternData: PackageData = PackageData("tern", "-l")
}

data class PackageData(
Expand Down