How to use IrClass.isProjectConfig method of io.kotest.framework.multiplatform.js.specs class

Best Kotest code snippet using io.kotest.framework.multiplatform.js.specs.IrClass.isProjectConfig

SpecIrGenerationExtension.kt

Source: SpecIrGenerationExtension.kt Github

copy

Full Screen

1package io.kotest.framework.multiplatform.js2import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext3import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension4import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext5import org.jetbrains.kotlin.backend.common.ir.addChild6import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder7import org.jetbrains.kotlin.cli.common.messages.MessageCollector8import org.jetbrains.kotlin.cli.common.toLogger9import org.jetbrains.kotlin.ir.IrStatement10import org.jetbrains.kotlin.ir.builders.declarations.buildFun11import org.jetbrains.kotlin.ir.builders.irBlockBody12import org.jetbrains.kotlin.ir.builders.irCall13import org.jetbrains.kotlin.ir.builders.irVararg14import org.jetbrains.kotlin.ir.declarations.IrClass15import org.jetbrains.kotlin.ir.declarations.IrFile16import org.jetbrains.kotlin.ir.declarations.IrModuleFragment17import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction18import org.jetbrains.kotlin.ir.declarations.name19import org.jetbrains.kotlin.ir.expressions.IrCall20import org.jetbrains.kotlin.ir.util.constructors21import org.jetbrains.kotlin.ir.util.getSimpleFunction22import org.jetbrains.kotlin.ir.util.kotlinFqName23import org.jetbrains.kotlin.name.FqName24import org.jetbrains.kotlin.name.Name25import java.util.concurrent.CopyOnWriteArrayList26class SpecIrGenerationExtension(private val messageCollector: MessageCollector) : IrGenerationExtension {27 override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {28 moduleFragment.transform(object : IrElementTransformerVoidWithContext() {29 val specs = CopyOnWriteArrayList<IrClass>()30 var configs = CopyOnWriteArrayList<IrClass>()31 override fun visitModuleFragment(declaration: IrModuleFragment): IrModuleFragment {32 val fragment = super.visitModuleFragment(declaration)33 messageCollector.toLogger().log("Detected ${configs.size} configs:")34 configs.forEach {35 messageCollector.toLogger().log(it.kotlinFqName.asString())36 }37 messageCollector.toLogger().log("Detected ${specs.size} JS specs:")38 specs.forEach {39 messageCollector.toLogger().log(it.kotlinFqName.asString())40 }41 if (specs.isEmpty()) return fragment42 val file = declaration.files.first()43 val launcherClass = pluginContext.referenceClass(FqName(EntryPoint.TestEngineClassName))44 ?: error("Cannot find ${EntryPoint.TestEngineClassName} class reference")45 val launcherConstructor = launcherClass.constructors.first { it.owner.valueParameters.isEmpty() }46 val promiseFn = launcherClass.getSimpleFunction(EntryPoint.PromiseMethodName)47 ?: error("Cannot find function ${EntryPoint.PromiseMethodName}")48 val withSpecsFn = launcherClass.getSimpleFunction(EntryPoint.WithSpecsMethodName)49 ?: error("Cannot find function ${EntryPoint.WithSpecsMethodName}")50 val withConfigFn = launcherClass.getSimpleFunction(EntryPoint.WithConfigMethodName)51 ?: error("Cannot find function ${EntryPoint.WithConfigMethodName}")52 val main = pluginContext.irFactory.buildFun {53 name = Name.identifier("main")54 returnType = pluginContext.irBuiltIns.unitType55 }.also { func: IrSimpleFunction ->56 func.body = DeclarationIrBuilder(pluginContext, func.symbol).irBlockBody {57 +irCall(promiseFn).also { promise: IrCall ->58 promise.dispatchReceiver = irCall(withSpecsFn).also { withSpecs ->59 withSpecs.putValueArgument(60 0,61 irVararg(62 pluginContext.irBuiltIns.stringType,63 specs.map { irCall(it.constructors.first()) }64 )65 )66 withSpecs.dispatchReceiver = irCall(withConfigFn).also { withConfig ->67 withConfig.putValueArgument(68 0,69 irVararg(70 pluginContext.irBuiltIns.stringType,71 configs.map { irCall(it.constructors.first()) }72 )73 )74 withConfig.dispatchReceiver = irCall(launcherConstructor)75 }76 }77 }78 }79 }80/​/​ val launcher = pluginContext.irFactory.buildProperty {81/​/​ name = Name.identifier(EntryPoint.LauncherValName)82/​/​ }.apply {83/​/​ parent = file84/​/​ backingField = pluginContext.irFactory.buildField {85/​/​ type = pluginContext.irBuiltIns.unitType86/​/​ isFinal = true87/​/​ isExternal = false88/​/​ isStatic = true /​/​ top level vals must be static89/​/​ name = Name.identifier(EntryPoint.LauncherValName)90/​/​ }.also { field ->91/​/​ field.correspondingPropertySymbol = this@apply.symbol92/​/​ field.initializer = pluginContext.irFactory.createExpressionBody(startOffset, endOffset) {93/​/​ this.expression = DeclarationIrBuilder(pluginContext, field.symbol).irBlock {94/​/​ +irCall(promiseFn).also { promise: IrCall ->95/​/​ promise.dispatchReceiver = irCall(withSpecsFn).also { withSpecs ->96/​/​ withSpecs.putValueArgument(97/​/​ 0,98/​/​ irVararg(99/​/​ pluginContext.irBuiltIns.stringType,100/​/​ specs.map { irCall(it.constructors.first()) }101/​/​ )102/​/​ )103/​/​ withSpecs.dispatchReceiver = irCall(withConfigFn).also { withConfig ->104/​/​ withConfig.putValueArgument(105/​/​ 0,106/​/​ irVararg(107/​/​ pluginContext.irBuiltIns.stringType,108/​/​ configs.map { irCall(it.constructors.first()) }109/​/​ )110/​/​ )111/​/​ withConfig.dispatchReceiver = irCall(launcherConstructor)112/​/​ }113/​/​ }114/​/​ }115/​/​ }116/​/​ }117/​/​ }118/​/​119/​/​ addGetter {120/​/​ returnType = pluginContext.irBuiltIns.unitType121/​/​ }.also { func: IrSimpleFunction ->122/​/​ func.body = DeclarationIrBuilder(pluginContext, func.symbol).irBlockBody {123/​/​ }124/​/​ }125/​/​ }126 file.addChild(main)127 return fragment128 }129 override fun visitClassNew(declaration: IrClass): IrStatement {130 super.visitClassNew(declaration)131 if (declaration.isProjectConfig()) configs.add(declaration)132 return declaration133 }134 override fun visitFileNew(declaration: IrFile): IrFile {135 super.visitFileNew(declaration)136 val specs = declaration.specs()137 messageCollector.toLogger()138 .log("${declaration.name} contains ${specs.size} spec(s): ${specs.joinToString(", ") { it.kotlinFqName.asString() }}")139 this.specs.addAll(specs)140 return declaration141 }142 }, null)143 }144}...

Full Screen

Full Screen

specs.kt

Source: specs.kt Github

copy

Full Screen

1package io.kotest.framework.multiplatform.js2import org.jetbrains.kotlin.ir.declarations.IrClass3import org.jetbrains.kotlin.ir.declarations.IrFile4import org.jetbrains.kotlin.ir.types.IrType5import org.jetbrains.kotlin.ir.types.classFqName6import org.jetbrains.kotlin.ir.types.getClass7import org.jetbrains.kotlin.name.FqName8val specClasses = listOf(9 "io.kotest.core.spec.style.BehaviorSpec",10 "io.kotest.core.spec.style.DescribeSpec",11 "io.kotest.core.spec.style.ExpectSpec",12 "io.kotest.core.spec.style.FeatureSpec",13 "io.kotest.core.spec.style.FreeSpec",14 "io.kotest.core.spec.style.FunSpec",15 "io.kotest.core.spec.style.ShouldSpec",16 "io.kotest.core.spec.style.StringSpec",17 "io.kotest.core.spec.style.WordSpec",18)19val abstractProjectConfigFqName = FqName("io.kotest.core.config.AbstractProjectConfig")20/​**21 * Returns any specs declared at the top level in this file.22 */​23fun IrFile.specs() = declarations.filterIsInstance<IrClass>().filter { it.isSpecClass() }24/​**25 * Returns true fi this IrClass is a project config26 */​27fun IrClass.isProjectConfig() = superTypes().any { it.classFqName == abstractProjectConfigFqName }28/​**29 * Recursively returns all supertypes for an [IrClass] to the top of the type tree.30 */​31fun IrClass.superTypes(): List<IrType> =32 this.superTypes + this.superTypes.flatMap { it.getClass()?.superTypes() ?: emptyList() }33/​**34 * Returns true if any of the parents of this class are a spec class.35 */​36fun IrClass.isSpecClass() =37 superTypes().mapNotNull { it.classFqName?.asString() }.intersect(specClasses).isNotEmpty()...

Full Screen

Full Screen

IrClass.isProjectConfig

Using AI Code Generation

copy

Full Screen

1return IrClass.isProjectConfig ( this )2}3}4}5}6}7}8fun IrClass.isProjectConfig(): Boolean {9return this.annotations.any { it.symbol.owner.name.asString() == "ProjectConfig" }10}11}12}13if (irClass.isProjectConfig()) {14irClass.functions.forEach { function ->15if (function.name.asString() == "beforeProject") {16function.call(null, emptyList())17}18}19}20}21}22}23}24irClass.functions.forEach { function ->25if (function.name.asString() == "afterProject") {26function.call(null, emptyList())27}28}29}30}31}32}33irClass.functions.forEach { function ->34if (function.name.asString() == "beforeSpec") {35function.call(null, emptyList())36}37}38}39}40}41}

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Feeding your QA Career – Developing Instinctive &#038; Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

A Reconsideration of Software Testing Metrics

There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Options for Manual Test Case Development &#038; Management

The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.

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 Kotest automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful