From 2d49f7f3c1ac39e98413d668762775224c8c10dc Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Thu, 4 Apr 2024 15:30:13 +0200 Subject: [PATCH] Fix wasm config issues related to tests --- appyx-navigation/common/build.gradle.kts | 2 + .../common/karma.config.d/wasm/config.js | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 appyx-navigation/common/karma.config.d/wasm/config.js diff --git a/appyx-navigation/common/build.gradle.kts b/appyx-navigation/common/build.gradle.kts index 3e0ebcbbd..4b5df9db5 100644 --- a/appyx-navigation/common/build.gradle.kts +++ b/appyx-navigation/common/build.gradle.kts @@ -25,6 +25,7 @@ kotlin { // Adding moduleName as a workaround for this issue: https://youtrack.jetbrains.com/issue/KT-51942 moduleName = "appyx-navigation-common" browser() + binaries.executable() } wasmJs { // Adding moduleName as a workaround for this issue: https://youtrack.jetbrains.com/issue/KT-51942 @@ -38,6 +39,7 @@ kotlin { } } } + binaries.executable() } iosX64() diff --git a/appyx-navigation/common/karma.config.d/wasm/config.js b/appyx-navigation/common/karma.config.d/wasm/config.js new file mode 100644 index 000000000..22429e585 --- /dev/null +++ b/appyx-navigation/common/karma.config.d/wasm/config.js @@ -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"); \ No newline at end of file