How to use producerType class of org.spekframework.intellij package

Best Spek code snippet using org.spekframework.intellij.producerType

SpekRunConfigurationProducer.kt

Source:SpekRunConfigurationProducer.kt Github

copy

Full Screen

...21import org.spekframework.intellij.support.SpekCommonProgramRunConfigurationParameters.GeneratedNameHint22import org.spekframework.intellij.util.maybeGetContext23import org.spekframework.spek2.runtime.scope.Path24import org.spekframework.spek2.runtime.scope.PathBuilder25abstract class SpekRunConfigurationProducer(val producerType: ProducerType, type: SpekConfigurationType)26    : RunConfigurationProducer<SpekRunConfiguration<*>>(type) {27    override fun isConfigurationFromContext(configuration: SpekRunConfiguration<*>,28                                            context: ConfigurationContext): Boolean {29        val descriptorCache = checkNotNull(30            context.project.getComponent(ScopeDescriptorCache::class.java)31        )32        return context.psiLocation?.let {33            var nameHint: GeneratedNameHint? = null34            val path = if (it is PsiDirectory) {35                getPathFromDir(context, it)36                nameHint = GeneratedNameHint.PACKAGE37            } else if (it is PsiPackage) {38                getPathFromPackage(it)39                nameHint = GeneratedNameHint.PACKAGE40            } else {41                val elementContext = maybeGetContext(it)42                val descriptor = when (elementContext) {43                    is KtClassOrObject -> {44                        nameHint = GeneratedNameHint.CLASS45                        descriptorCache.fromClassOrObject(elementContext)46                    }47                    is KtCallExpression -> {48                        nameHint = GeneratedNameHint.SCOPE49                        descriptorCache.fromCallExpression(elementContext)50                    }51                    else -> null52                }53                if (descriptor != null && !descriptor.excluded && descriptor.runnable) {54                    descriptor.path55                } else {56                    null57                }58            }59            configuration.data.path == path && configuration.data.generatedNameHint == nameHint60        } ?: false61    }62    override fun setupConfigurationFromContext(configuration: SpekRunConfiguration<*>,63                                               context: ConfigurationContext,64                                               sourceElement: Ref<PsiElement>): Boolean {65        val descriptorCache = checkNotNull(66            context.project.getComponent(ScopeDescriptorCache::class.java)67        )68        return sourceElement.get().let {69            var nameHint: GeneratedNameHint? = null70            val path = if (it is PsiDirectory) {71                nameHint = GeneratedNameHint.PACKAGE72                getPathFromDir(context, it)73            } else if (it is PsiPackage) {74                nameHint = GeneratedNameHint.PACKAGE75                getPathFromPackage(it)76            } else {77                val elementContext = maybeGetContext(it)78                val descriptor = when (elementContext) {79                    is KtClassOrObject -> {80                        nameHint = GeneratedNameHint.CLASS81                        descriptorCache.fromClassOrObject(elementContext)82                    }83                    is KtCallExpression -> {84                        nameHint = GeneratedNameHint.SCOPE85                        descriptorCache.fromCallExpression(elementContext)86                    }87                    else -> null88                }89                if (descriptor != null && !descriptor.excluded && descriptor.runnable) {90                    descriptor.path91                } else {92                    null93                }94            }95            if (path != null) {96                configuration.data.path = path97                configuration.data.generatedNameHint = nameHint98                val kotlinFacetSettings = KotlinFacetSettingsProvider.getInstance(context.project)99                        .getInitializedSettings(context.module)100                var canRun = false101                if (isPlatformSupported(kotlinFacetSettings.platform!!.kind)) {102                    configuration.configureForModule(context.module)103                    configuration.data.producerType = producerType104                    canRun = true105                    configuration.data.producerType = producerType106                } else if (kotlinFacetSettings.platform!!.kind == CommonIdePlatformKind) {107                    val result = findSupportedModule(context.project, context.module)108                    if (result != null) {109                        val (module, moduleKotlinFacetSettings) = result110                        configuration.configureForModule(module)111                        configuration.data.producerType = moduleKotlinFacetSettings.platform!!.kind.toProducerType()112                        canRun = true113                    }114                }115                canRun116            } else {117                false118            }119        }120    }121    private fun getPathFromDir(context: ConfigurationContext, dir: PsiDirectory): Path? {122        if (context.module != null) {123            val moduleRootManager = ModuleRootManager.getInstance(context.module)124            if (context.module == dir.module || moduleRootManager.isDependsOn(dir.module)) {125                val psiPackage = dir.getPackage()126                if (psiPackage != null) {127                    return getPathFromPackage(psiPackage)128                }129            }130        }131        return null132    }133    private fun getPathFromPackage(pkg: PsiPackage): Path {134        if (pkg.qualifiedName.isEmpty()) {135            return PathBuilder().build()136        }137        return PathBuilder()138            .appendPackage(pkg.qualifiedName)139            .build()140    }141    private fun findSupportedModule(project: Project, commonModule: Module): Pair<Module, KotlinFacetSettings>? {142        val kotlinFacetSettingsProvider = KotlinFacetSettingsProvider.getInstance(project)143        return commonModule.implementingModules144            .map { it to kotlinFacetSettingsProvider.getInitializedSettings(it) }145            .firstOrNull {146                isPlatformSupported(it.second.platform!!.kind)147            }148    }149    private fun isPlatformSupported(kind: IdePlatformKind<*>) = kind.toProducerType() == producerType150}...

Full Screen

Full Screen

SpekCommonProgramRunConfigurationParameters.kt

Source:SpekCommonProgramRunConfigurationParameters.kt Github

copy

Full Screen

...8import org.spekframework.spek2.runtime.scope.Path9import org.spekframework.spek2.runtime.scope.PathBuilder10abstract class SpekCommonProgramRunConfigurationParameters(private val _project: Project): CommonProgramRunConfigurationParameters {11    var path: Path = PathBuilder.ROOT12    var producerType: ProducerType? = null13    private var workingDirectory: String? = null14    private var envs = mutableMapOf<String, String>()15    private var passParentEnvs: Boolean = true16    private var programParameters: String? = null17    override fun getWorkingDirectory(): String? {18        return workingDirectory19    }20    override fun getEnvs(): MutableMap<String, String> {21        return envs22    }23    override fun setWorkingDirectory(workingDirectory: String?) {24        this.workingDirectory = workingDirectory25    }26    override fun setEnvs(envs: MutableMap<String, String>) {...

Full Screen

Full Screen

SpekRunConfiguration.kt

Source:SpekRunConfiguration.kt Github

copy

Full Screen

...30    }31    override fun suggestedName(): String {32        val path = data.path33        val parent = path.parent34        val prefix = data.producerType?.let {35            "($it)"36        } ?: ""37        return if (path.name.isEmpty() && parent != null && parent.isRoot) {38            "$prefix Spek tests in <default package>"39        } else if (parent != null && parent.isRoot) {40            "$prefix Spek tests in ${path.name}"41        } else {42            "$prefix ${path.name}"43        }.trim()44    }45}...

Full Screen

Full Screen

producerType.kt

Source:producerType.kt Github

copy

Full Screen

1package org.spekframework.intellij2import org.jetbrains.kotlin.platform.IdePlatformKind3import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind4import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind5import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind6import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind7enum class ProducerType {8    COMMON,9    JVM,10    NATIVE,11    JS12}13fun IdePlatformKind<*>.toProducerType(): ProducerType {14    return when (this) {15        CommonIdePlatformKind -> ProducerType.COMMON16        JvmIdePlatformKind -> ProducerType.JVM17        NativeIdePlatformKind -> ProducerType.NATIVE18        JsIdePlatformKind -> ProducerType.JS19        else -> throw IllegalArgumentException("Unsupported platform kind: ${this}")20    }21}...

Full Screen

Full Screen

SpekAndroidRunConfigurationProducer.kt

Source:SpekAndroidRunConfigurationProducer.kt Github

copy

Full Screen

1package org.spekframework.intellij2import com.intellij.execution.configurations.ConfigurationTypeUtil3class SpekAndroidRunConfigurationProducer: SpekRunConfigurationProducer(4    ProducerType.JVM,5    ConfigurationTypeUtil.findConfigurationType(SpekAndroidConfigurationType::class.java)6)...

Full Screen

Full Screen

SpekJvmRunConfigurationProducer.kt

Source:SpekJvmRunConfigurationProducer.kt Github

copy

Full Screen

1package org.spekframework.intellij2import com.intellij.execution.configurations.ConfigurationTypeUtil3class SpekJvmRunConfigurationProducer: SpekRunConfigurationProducer(4    ProducerType.JVM,5    ConfigurationTypeUtil.findConfigurationType(SpekJvmConfigurationType::class.java)6)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spek automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in producerType

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful