Skip to content

Commit

Permalink
feat(Configuration): add support for ember test run configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
makepanic committed Jun 10, 2018
1 parent 29a1ce6 commit 661e695
Show file tree
Hide file tree
Showing 20 changed files with 920 additions and 35 deletions.
8 changes: 8 additions & 0 deletions doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ A new `Ember Serve` run configuration can be created through
To configure advanced settings like the server host, proxy or ssl, expand the
`Advanced settings` panel.

### Running ember tests

This plugin also adds a `Ember Test` run configuration that will run your projects tests.
A new `Ember Test` run configuration can be created through
`Run → Edit Configurations...`.

To configure advanced settings like the server host, test filter or config file, expand the
`Advanced settings` panel.

Live Templates
-------------------------------------------------------------------------------
Expand Down
15 changes: 4 additions & 11 deletions src/main/kotlin/com/emberjs/configuration/BooleanOptionsField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.emberjs.configuration
import com.emberjs.configuration.utils.ElementUtils
import org.jdom.Element
import javax.swing.JCheckBox
import javax.swing.JComponent

class BooleanOptionsField(
default: Boolean,
Expand All @@ -12,23 +11,17 @@ class BooleanOptionsField(
) : OptionsField<Boolean>(default, field, cmdlineOptionName) {
override var value: Boolean = default

override fun writeToElement(element: Element) {
ElementUtils.writeBool(element, this.field, this.value)
}

override fun readFromElement(element: Element) {
this.value = ElementUtils.readBool(element, this.field) ?: this.default
}

override fun writeToComponent(component: JComponent) {
override fun writeTo(component: Any) {
when (component) {
is JCheckBox -> component.isSelected = value
is Element -> ElementUtils.writeBool(component, this.field, this.value)
}
}

override fun readFromComponent(component: JComponent) {
override fun readFrom(component: Any) {
when (component) {
is JCheckBox -> value = component.isSelected
is Element -> this.value = ElementUtils.readBool(component, this.field) ?: this.default
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.emberjs.configuration

import com.emberjs.cli.EmberCli
import com.emberjs.utils.emberRoot
import com.intellij.execution.configurations.CommandLineState
import com.intellij.execution.process.KillableColoredProcessHandler
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.process.ProcessTerminatedListener
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.actionSystem.LangDataKeys

class EmberCommandLineState(environment: ExecutionEnvironment) : CommandLineState(environment) {
open class EmberCommandLineState(environment: ExecutionEnvironment) : CommandLineState(environment) {
override fun startProcess(): ProcessHandler {
val configuration = (environment.runProfile as EmberConfiguration)
val argList = configuration.options.toCommandLineOptions()

val workingDirectory = environment.dataContext?.getData(LangDataKeys.MODULE)?.emberRoot?.path ?:
environment.project.basePath

val cmd = EmberCli(environment.project, configuration.command, *argList)
.apply { workDirectory = environment.project.basePath }
.apply { workDirectory = workingDirectory }
.commandLine()
.apply {
// taken from intellij-rust
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/com/emberjs/configuration/OptionsField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ abstract class OptionsField<T>(
val cmdlineOptionName: String
) {
abstract var value : T
abstract fun writeToElement(element: Element)
abstract fun readFromElement(element: Element)

abstract fun writeToComponent(component: JComponent)
abstract fun readFromComponent(component: JComponent)
abstract fun writeTo(component: Any)
abstract fun readFrom(component: Any)
}
34 changes: 20 additions & 14 deletions src/main/kotlin/com/emberjs/configuration/StringOptionsField.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.emberjs.configuration

import com.emberjs.configuration.utils.ElementUtils
import com.emberjs.configuration.utils.PublicStringAddEditDeleteListPanel
import com.intellij.ui.EditorTextField
import org.jdom.Element
import javax.swing.ButtonGroup
import javax.swing.JComboBox
import javax.swing.JComponent

class StringOptionsField(
default: String,
Expand All @@ -14,28 +15,33 @@ class StringOptionsField(

override var value: String = ""

override fun writeToElement(element: Element) {
ElementUtils.writeString(element, this.field, this.value)
}

override fun readFromElement(element: Element) {
this.value = ElementUtils.readString(element, this.field) ?: this.default
}

override fun writeToComponent(component: JComponent) {
override fun writeTo(component: Any) {
when (component) {
is EditorTextField -> {
component.text = value
component.setPlaceholder(default)
is Element -> ElementUtils.writeString(component, this.field, this.value)
is EditorTextField -> component.apply {
text = value
setPlaceholder(default)
}
is JComboBox<*> -> component.selectedItem = if (value.isEmpty()) default else value
is PublicStringAddEditDeleteListPanel -> component.replaceItems(value.split(",").filter { it.isNotEmpty() })
is ButtonGroup -> {
component.elements.toList()
.find { it.actionCommand == value }
?.let {
it.isSelected = true
component.setSelected(it.model, true)
}
}
}
}

override fun readFromComponent(component: JComponent) {
override fun readFrom(component: Any) {
when (component) {
is Element -> value = ElementUtils.readString(component, this.field) ?: this.default
is EditorTextField -> value = component.text
is JComboBox<*> -> value = component.selectedItem.toString()
is PublicStringAddEditDeleteListPanel -> value = component.listItems.joinToString(",")
is ButtonGroup -> component.selection?.let { value = it.actionCommand }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class EmberServeConfiguration(project: Project, factory: ConfigurationFactory, n
override fun writeExternal(element: Element) {
super.writeExternal(element)
element.let {
options.fields().forEach { optionsField -> optionsField.writeToElement(element)}
options.fields().forEach { optionsField -> optionsField.writeTo(element)}
}
}

override fun readExternal(element: Element) {
super.readExternal(element)
element.let {
options.fields().forEach { optionsField -> optionsField.readFromElement(element) }
options.fields().forEach { optionsField -> optionsField.readFrom(element) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class EmberServeSettingsEditor : SettingsEditor<EmberServeConfiguration>() {

override fun resetEditorFrom(serveConfiguration: EmberServeConfiguration) {
mappings.forEach { (first, second) ->
second.get(serveConfiguration.options).writeToComponent(first as JComponent)
first?.let { second.get(serveConfiguration.options).writeTo(it) }
}
}

@Throws(ConfigurationException::class)
override fun applyEditorTo(serveConfiguration: EmberServeConfiguration) {
mappings.forEach { (first, second) ->
second.get(serveConfiguration.options).readFromComponent(first as JComponent)
first?.let { second.get(serveConfiguration.options).readFrom(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.emberjs.configuration.test

import com.emberjs.configuration.EmberCommandLineState
import com.emberjs.configuration.EmberConfiguration
import com.intellij.execution.DefaultExecutionResult
import com.intellij.execution.ExecutionResult
import com.intellij.execution.Executor
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil.createAndAttachConsole

class EmberTestCommandLineState(environment: ExecutionEnvironment) : EmberCommandLineState(environment) {
private val TEST_FRAMEWORK_NAME = "ember-qunit"

override fun execute(executor: Executor, runner: ProgramRunner<*>): ExecutionResult {
val configuration = (environment.runProfile as EmberConfiguration)

// enforce teamcity reporter because converter requires it
(configuration.options as EmberTestOptions).reporter.value = "teamcity"

val processHandler: ProcessHandler = startProcess()

val properties = EmberTestConsoleProperties(configuration as RunConfiguration, TEST_FRAMEWORK_NAME, executor)
val console = createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)

SMTestRunnerConnectionUtil.createAndAttachConsole(TEST_FRAMEWORK_NAME, processHandler, properties)

val executionResult = DefaultExecutionResult(console, processHandler, *createActions(console, processHandler))
executionResult.setRestartActions(ToggleAutoTestAction())
return executionResult
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.emberjs.configuration.test

import com.emberjs.configuration.EmberConfiguration
import com.emberjs.configuration.test.ui.EmberTestSettingsEditor
import com.intellij.execution.ExecutionException
import com.intellij.execution.Executor
import com.intellij.execution.configurations.*
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import org.jdom.Element
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

class EmberTestConfiguration(project: Project, factory: ConfigurationFactory, name: String) : RunConfigurationBase(project, factory, name), EmberConfiguration {
override val options = EmberTestOptions()
override val command: String = "test"

@NotNull
override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
return EmberTestSettingsEditor()
}

@Throws(RuntimeConfigurationException::class)
override fun checkConfiguration() {

}

@Nullable
@Throws(ExecutionException::class)
override fun getState(@NotNull executor: Executor, @NotNull executionEnvironment: ExecutionEnvironment): RunProfileState? {
return EmberTestCommandLineState(executionEnvironment)
}

override fun writeExternal(element: Element) {
super.writeExternal(element)
element.let {
options.fields().forEach { optionsField -> optionsField.writeTo(element)}
}
}

override fun readExternal(element: Element) {
super.readExternal(element)
element.let {
options.fields().forEach { optionsField -> optionsField.readFrom(element) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.emberjs.configuration.test

import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.ConfigurationType
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.openapi.project.Project

class EmberTestConfigurationFactory(type: ConfigurationType) : ConfigurationFactory(type) {

override fun createTemplateConfiguration(project: Project): RunConfiguration {
return EmberTestConfiguration(project, this, "Ember test")
}

override fun getName(): String {
return FACTORY_NAME;
}

companion object {
private val FACTORY_NAME = "Ember test configuration factory"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.emberjs.configuration.test

import com.emberjs.icons.EmberIcons
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.ConfigurationTypeBase

class EmberTestConfigurationType : ConfigurationTypeBase(
"EMBER_TEST_CONFIGURATION",
"Ember Test",
"Ember Test Configuration",
EmberIcons.ICON_16
) {
override fun getConfigurationFactories(): Array<ConfigurationFactory> {
return arrayOf(EmberTestConfigurationFactory(this))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.emberjs.configuration.test

import com.intellij.execution.Executor
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.testframework.TestConsoleProperties
import com.intellij.execution.testframework.sm.SMCustomMessagesParsing
import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties

class EmberTestConsoleProperties(
configuration: RunConfiguration,
TEST_FRAMEWORK_NAME: String,
executor: Executor) : SMTRunnerConsoleProperties(
configuration,
TEST_FRAMEWORK_NAME,
executor
), SMCustomMessagesParsing {
override fun createTestEventsConverter(testFrameworkName: String, consoleProperties: TestConsoleProperties): OutputToGeneralTestEventsConverter {
return EmberTestOutputToGeneralTestEventsConverter(testFrameworkName, consoleProperties);
}
}
Loading

0 comments on commit 661e695

Please sign in to comment.