-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bunch more configuration options and allow running only a singl…
…e file of specs
- Loading branch information
Gregg Van Hove
committed
Feb 13, 2018
1 parent
fdeb901
commit eb08975
Showing
7 changed files
with
150 additions
and
41 deletions.
There are no files selected for viewing
66 changes: 54 additions & 12 deletions
66
src/io/pivotal/intellij/jasmine/JasmineConfigurationEditor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,85 @@ | ||
package io.pivotal.intellij.jasmine | ||
|
||
import com.intellij.execution.configuration.EnvironmentVariablesComponent | ||
import com.intellij.execution.configuration.EnvironmentVariablesTextFieldWithBrowseButton | ||
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterField | ||
import com.intellij.javascript.nodejs.util.NodePackageField | ||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory | ||
import com.intellij.openapi.options.SettingsEditor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.TextFieldWithBrowseButton | ||
import com.intellij.openapi.util.io.FileUtil | ||
import com.intellij.ui.RawCommandLineEditor | ||
import com.intellij.ui.components.fields.ExpandableTextField | ||
import com.intellij.util.ui.ComponentWithEmptyText | ||
import com.intellij.util.ui.FormBuilder | ||
import com.intellij.util.ui.SwingHelper | ||
import javax.swing.JComponent | ||
import javax.swing.JPanel | ||
|
||
|
||
class JasmineConfigurationEditor(project: Project) : SettingsEditor<JasmineRunConfiguration>() { | ||
class JasmineConfigurationEditor(private var project: Project) : SettingsEditor<JasmineRunConfiguration>() { | ||
private var nodeJsInterpreterField: NodeJsInterpreterField = NodeJsInterpreterField(project, false) | ||
private var nodeOptionsField: RawCommandLineEditor = RawCommandLineEditor() | ||
private var workingDirectoryField = createWorkingDirectoryField() | ||
private var envVars: EnvironmentVariablesTextFieldWithBrowseButton = EnvironmentVariablesTextFieldWithBrowseButton() | ||
private var jasminePackageField: NodePackageField = NodePackageField(nodeJsInterpreterField, "jasmine") | ||
private var envVars: EnvironmentVariablesComponent = EnvironmentVariablesComponent() | ||
private var jasmineOptionsField = createJasmineOptionsField() | ||
private var rootForm: JPanel | ||
|
||
init { | ||
nodeOptionsField.dialogCaption = "Node Options" | ||
rootForm = FormBuilder() | ||
.setAlignLabelOnRight(false) | ||
.addLabeledComponent("Node interpreter", nodeJsInterpreterField) | ||
.addLabeledComponent("Jasmine package", jasminePackageField) | ||
.addComponent(envVars) | ||
.addLabeledComponent("Node &interpreter", nodeJsInterpreterField) | ||
.addLabeledComponent("Node &options", nodeOptionsField) | ||
.addLabeledComponent("&Working directory", workingDirectoryField) | ||
.addLabeledComponent("&Environment variables", envVars) | ||
.addLabeledComponent("&Jasmine package", jasminePackageField) | ||
.addLabeledComponent("E&xtra Jasmine options", jasmineOptionsField) | ||
.panel | ||
} | ||
|
||
private fun createWorkingDirectoryField(): TextFieldWithBrowseButton { | ||
val field = TextFieldWithBrowseButton() | ||
SwingHelper.installFileCompletionAndBrowseDialog(project, field, "Jasmine Working Directory", | ||
FileChooserDescriptorFactory.createSingleFolderDescriptor()) | ||
return field | ||
} | ||
|
||
private fun createJasmineOptionsField(): RawCommandLineEditor { | ||
val editor = RawCommandLineEditor() | ||
editor.dialogCaption = "Extra Jasmine Options" | ||
val field = editor.textField | ||
if (field is ExpandableTextField) { | ||
field.putClientProperty("monospaced", false) | ||
} | ||
|
||
if (field is ComponentWithEmptyText) { | ||
(field as ComponentWithEmptyText).emptyText.text = "CLI options, e.g. --fail-fast=true" | ||
} | ||
|
||
return editor | ||
} | ||
|
||
override fun createEditor(): JComponent = rootForm | ||
|
||
override fun applyEditorTo(config: JasmineRunConfiguration) { | ||
config.nodeJs = nodeJsInterpreterField.interpreterRef | ||
config.jasmineRunSettings = config.jasmineRunSettings.copy( | ||
nodeJs = nodeJsInterpreterField.interpreterRef, | ||
nodeOptions = nodeOptionsField.text, | ||
workingDir = workingDirectoryField.text, | ||
envData = envVars.data, | ||
extraJasmineOptions = jasmineOptionsField.text) | ||
config.setJasminePackage(jasminePackageField.selected) | ||
config.envData = envVars.envData | ||
} | ||
|
||
override fun resetEditorFrom(config: JasmineRunConfiguration) { | ||
nodeJsInterpreterField.interpreterRef = config.nodeJs | ||
val runSettings = config.jasmineRunSettings | ||
nodeJsInterpreterField.interpreterRef = runSettings.nodeJs | ||
nodeOptionsField.text = runSettings.nodeOptions | ||
workingDirectoryField.text = FileUtil.toSystemDependentName(runSettings.workingDir) | ||
envVars.data = runSettings.envData | ||
jasminePackageField.selected = config.selectedJasminePackage() | ||
if (config.envData != null) { | ||
envVars.envData = config.envData!! | ||
} | ||
jasmineOptionsField.text = runSettings.extraJasmineOptions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 52 additions & 11 deletions
63
src/io/pivotal/intellij/jasmine/JasmineRunConfigurationProducer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,57 @@ | ||
package io.pivotal.intellij.jasmine; | ||
package io.pivotal.intellij.jasmine | ||
|
||
import com.intellij.execution.actions.ConfigurationContext; | ||
import com.intellij.execution.actions.RunConfigurationProducer; | ||
import com.intellij.openapi.util.Ref; | ||
import com.intellij.psi.PsiElement; | ||
import com.google.common.collect.ImmutableList | ||
import com.intellij.execution.actions.ConfigurationContext | ||
import com.intellij.javascript.testing.JsTestRunConfigurationProducer | ||
import com.intellij.lang.javascript.psi.JSFile | ||
import com.intellij.openapi.util.Ref | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFileSystemItem | ||
import com.intellij.psi.util.PsiUtilCore | ||
import com.intellij.util.ObjectUtils.tryCast | ||
|
||
class JasmineRunConfigurationProducer : RunConfigurationProducer<JasmineRunConfiguration>(JasmineConfigurationType.getInstance()) { | ||
class JasmineRunConfigurationProducer : JsTestRunConfigurationProducer<JasmineRunConfiguration>(JasmineConfigurationType.getInstance(), ImmutableList.of("jasmine")) { | ||
override fun isConfigurationFromCompatibleContext(runConfig: JasmineRunConfiguration, context: ConfigurationContext): Boolean { | ||
val element = context.psiLocation ?: return false | ||
val currentFile = PsiUtilCore.getVirtualFile(element) ?: return false | ||
if (currentFile.isDirectory) { | ||
// not sure the right way to run a dir | ||
return false | ||
} | ||
|
||
override fun setupConfigurationFromContext(runConfig: JasmineRunConfiguration, | ||
config: ConfigurationContext, | ||
sourceElement: Ref<PsiElement>) = true | ||
val psiFile = tryCast(element.containingFile, JSFile::class.java) ?: return false | ||
psiFile.testFileType ?: return false | ||
|
||
override fun isConfigurationFromContext(p0: JasmineRunConfiguration?, | ||
p1: ConfigurationContext?) = true | ||
// if (element is PsiFileSystemItem) { | ||
runConfig.jasmineRunSettings = runConfig.jasmineRunSettings.copy( | ||
specFile = currentFile.path | ||
) | ||
// } else return false | ||
|
||
return true | ||
} | ||
|
||
override fun setupConfigurationFromCompatibleContext(runConfig: JasmineRunConfiguration, context: ConfigurationContext, sourceElement: Ref<PsiElement>): Boolean { | ||
val element = context.psiLocation ?: return false | ||
val currentFile = PsiUtilCore.getVirtualFile(element) ?: return false | ||
if (currentFile.isDirectory) { | ||
// not sure the right way to run a dir | ||
return false | ||
} | ||
|
||
val psiFile = tryCast(element.containingFile, JSFile::class.java) ?: return false | ||
|
||
if (element is PsiFileSystemItem) { | ||
psiFile.testFileType ?: return false | ||
|
||
runConfig.jasmineRunSettings = runConfig.jasmineRunSettings.copy( | ||
specFile = currentFile.path | ||
) | ||
sourceElement.set(psiFile) | ||
runConfig.setGeneratedName() | ||
} else return false | ||
|
||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.pivotal.intellij.jasmine | ||
|
||
import com.intellij.execution.configuration.EnvironmentVariablesData | ||
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef | ||
|
||
data class JasmineRunSettings( | ||
var nodeJs : NodeJsInterpreterRef = NodeJsInterpreterRef.createProjectRef(), | ||
var nodeOptions : String = "", | ||
var workingDir : String = "", | ||
var envData : EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT, | ||
var extraJasmineOptions : String = "", | ||
var jasmineConfigFile : String = "", | ||
var specFile : String = "" | ||
) |