From 1bdc9edb20060cd215f99ef21209ed1dbb6bdf5b Mon Sep 17 00:00:00 2001 From: Igor Laevsky Date: Thu, 11 Nov 2021 16:12:34 +0300 Subject: [PATCH] [Wasm] Implement Jasmine adapter for kotlin.test --- .../kotlin/kotlin/test/JasmineLikeAdapter.kt | 43 +++++++++++++++++++ .../src/main/kotlin/kotlin/test/TestApi.kt | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/JasmineLikeAdapter.kt diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/JasmineLikeAdapter.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/JasmineLikeAdapter.kt new file mode 100644 index 00000000000..8f72b624a80 --- /dev/null +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/JasmineLikeAdapter.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.test + +import kotlin.test.FrameworkAdapter + +// Need to wrap into additional lambdas so that js launcher will work without Mocha or any other testing framework +@JsFun("(name, fn) => describe(name, fn)") +internal external fun describe(name: String, fn: () -> Unit) + +@JsFun("(name, fn) => xdescribe(name, fn)") +internal external fun xdescribe(name: String, fn: () -> Unit) + +@JsFun("(name, fn) => it(name, fn)") +internal external fun it(name: String, fn: () -> Any?) + +@JsFun("(name, fn) => xit(name, fn)") +internal external fun xit(name: String, fn: () -> Any?) + +/** + * [Jasmine](https://github.com/jasmine/jasmine) adapter. + * Also used for [Mocha](https://mochajs.org/) and [Jest](https://facebook.github.io/jest/). + */ +internal class JasmineLikeAdapter : FrameworkAdapter { + override fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit) { + if (ignored) { + xdescribe(name, suiteFn) + } else { + describe(name, suiteFn) + } + } + + override fun test(name: String, ignored: Boolean, testFn: () -> Any?) { + if (ignored) { + xit(name, testFn) + } else { + it(name, testFn) + } + } +} \ No newline at end of file diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt index c5636268ebc..a6265e4d02d 100644 --- a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt @@ -37,7 +37,7 @@ internal fun test(name: String, ignored: Boolean, testFn: () -> Any?) { currentAdapter.test(name, ignored, testFn) } -internal var currentAdapter: FrameworkAdapter = BareAdapter() +internal var currentAdapter: FrameworkAdapter = JasmineLikeAdapter() // This is called from the js-launcher alongside wasm start function @JsExport