How to use specs class of io.kotest.framework.multiplatform.js package

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

SpecIrGenerationExtension.kt

Source: SpecIrGenerationExtension.kt Github

copy

Full Screen

...25import 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

build.gradle.kts

Source: build.gradle.kts Github

copy

Full Screen

...54 }55 }56}57openApiValidate {58 inputSpec.set("$projectDir/​specs/​api.yaml")59 recommend.set(true)60}61openApiGenerate {62 inputSpec.set("$rootDir/​multiplatform/​specs/​api.yaml")63 generatorName.set("kotlin")64 library.set("multiplatform")65 generateApiDocumentation.set(true)66 outputDir.set("$projectDir")67 packageName.set("generated")68 configOptions.set(69 mapOf(70 "dateLibrary" to "string",71 "enumPropertyNaming" to "UPPERCASE",72 "collectionType" to "list",73 )74 )75 globalProperties.apply {76 put("models", "")...

Full Screen

Full Screen

specs.kt

Source: specs.kt Github

copy

Full Screen

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

entry.kt

Source: entry.kt Github

copy

Full Screen

...6 /​/​ in JS we use promise() which ultimately calls into GlobalScope.promise on JS platforms7 const val PromiseMethodName = "promise"8 /​/​ the FQN for the class used to launch the MPP engine9 const val TestEngineClassName = "io.kotest.engine.TestEngineLauncher"10 /​/​ the method invoked to add specs to the launcher, must exist on TestEngineLauncher11 const val WithSpecsMethodName = "withSpecs"12 /​/​ the method invoked to add configs on the launcher, must exist on TestEngineLauncher13 const val WithConfigMethodName = "withProjectConfig"14}...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

Complete Guide To Styling Forms With CSS Accent Color

The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

How To Find Hidden Elements In Selenium WebDriver With Java

Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.

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