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:

Are Agile Self-Managing Teams Realistic with Layered Management?

Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.

How To Refresh Page Using Selenium C# [Complete Tutorial]

When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.

An Interactive Guide To CSS Hover Effects

Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.

How To Handle Multiple Windows In Selenium Python

Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.

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. ????

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