-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run k/wasm tests in resources library (#4031)
Co-authored-by: Oleksandr.Karpovich <[email protected]>
- Loading branch information
Showing
6 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
components/resources/library/karma.config.d/wasm/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// see https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file | ||
// This file provides karma.config.d configuration to run tests with k/wasm | ||
|
||
const path = require("path"); | ||
|
||
config.browserConsoleLogOptions.level = "debug"; | ||
|
||
const basePath = config.basePath; | ||
const projectPath = path.resolve(basePath, "..", "..", "..", ".."); | ||
const generatedAssetsPath = path.resolve(projectPath, "build", "karma-webpack-out") | ||
|
||
const debug = message => console.log(`[karma-config] ${message}`); | ||
|
||
debug(`karma basePath: ${basePath}`); | ||
debug(`karma generatedAssetsPath: ${generatedAssetsPath}`); | ||
|
||
config.proxies["/"] = path.resolve(basePath, "kotlin"); | ||
|
||
config.files = [ | ||
{pattern: path.resolve(generatedAssetsPath, "**/*"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.png"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.gif"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.ttf"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.txt"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.json"), included: false, served: true, watched: false}, | ||
{pattern: path.resolve(basePath, "kotlin", "**/*.xml"), included: false, served: true, watched: false}, | ||
].concat(config.files); | ||
|
||
function KarmaWebpackOutputFramework(config) { | ||
// This controller is instantiated and set during the preprocessor phase. | ||
const controller = config.__karmaWebpackController; | ||
|
||
// only if webpack has instantiated its controller | ||
if (!controller) { | ||
console.warn( | ||
"Webpack has not instantiated controller yet.\n" + | ||
"Check if you have enabled webpack preprocessor and framework before this framework" | ||
) | ||
return | ||
} | ||
|
||
config.files.push({ | ||
pattern: `${controller.outputPath}/**/*`, | ||
included: false, | ||
served: true, | ||
watched: false | ||
}) | ||
} | ||
|
||
const KarmaWebpackOutputPlugin = { | ||
'framework:webpack-output': ['factory', KarmaWebpackOutputFramework], | ||
}; | ||
|
||
config.plugins.push(KarmaWebpackOutputPlugin); | ||
config.frameworks.push("webpack-output"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
...nents/resources/library/src/jsTest/kotlin/org/jetbrains/compose/resources/TestUtils.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package org.jetbrains.compose.resources | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.promise | ||
import kotlinx.coroutines.* | ||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
actual fun runBlockingTest(block: suspend CoroutineScope.() -> Unit): dynamic = GlobalScope.promise(block = block) | ||
actual typealias TestReturnType = Any | ||
actual fun runBlockingTest(block: suspend CoroutineScope.() -> Unit): TestReturnType = | ||
TODO("Implement if necessary. We focus on k/wasm target for now") |
16 changes: 13 additions & 3 deletions
16
...sources/library/src/wasmJsTest/kotlin/org/jetbrains/compose/resources/TestUtils.wasmJs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package org.jetbrains.compose.resources | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.test.runTest | ||
|
||
actual fun runBlockingTest(block: suspend CoroutineScope.() -> Unit) { | ||
TODO("To be implemented in PR 4031") | ||
@JsFun("() => ''") | ||
private external fun jsRef(): JsAny | ||
|
||
|
||
actual typealias TestReturnType = Any | ||
/** | ||
* Runs the [block] in a coroutine. | ||
*/ | ||
actual fun runBlockingTest(block: suspend CoroutineScope.() -> Unit): TestReturnType = MainScope().promise { | ||
block() | ||
jsRef() | ||
} |