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

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