Hi! I'm writing a full stack app with kobweb (ver...
# kobweb
j
Hi! I'm writing a full stack app with kobweb (very happy so far) but have a question: I want to add some unit tests for my jvm code. I added the requisite dependencies, etc, but when I try to run the tests I get:
Copy code
> Task :site:kspKotlinJvm FAILED
e: [ksp] java.lang.IllegalStateException: KobwebProcessorProvider: Missing processor mode (kobweb.mode)
	at com.varabyte.kobweb.ksp.KobwebProcessorProvider.create(KobwebProcessorProvider.kt:20)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$7$1.invoke(KotlinSymbolProcessingExtension.kt:277)...snip...
Looks like in order to even compile, Kobweb wants to know what mode should be used. But I don't care about mode, I'm just running tests. Did I miss something obvious? Can I set a mode from my test run configuration to make it happy?
Looks like for js, ksp tasks are given
kobweb.mode
(here) but for jvm, they are not (here)
d
I haven't really thought much about testing
I don't have any good guidance on that yet
For now, I might suggest treating your site as "UI" and moving your business logic into a normal JVM module that is easier to unit test
j
Yeah, I can do that
d
The KSP processing stuff is probably something you want to avoid 🙂
Basically that's Kobweb running through your code, understanding it, and generating code. The mode is related to configuring the KSP processor telling it what kind of code to look for / output to generate.
Another Kobweb contributor pinged me and mentioned this might already be fixed in
0.15.5-SNAPSHOT
in case you wanted to try
j
oh nice, I'll give that a shot
s
I am building a simple app with no backend but there is some logic that I would like to unit test. I added a unit test in
jsTest
but when I tried to run it with
./gradlew :site:jsTest
I got this error
Copy code
Execution failed for task ':site:jsTest'.
> Failed to execute all tests:
  :site:jsBrowserTest: java.lang.IllegalStateException: Errors occurred during launch of browser for testing.
  - ChromeHeadless
  Please make sure that you have installed browsers.
  Or change it via
  browser {
      testTask {
          useKarma {
              useFirefox()
              useChrome()
              useSafari()
          }
      }
  }
I would prefer not to involve a browser for a simple logic validation test. I see two possible options: • Configure node.js to be able to run unit tests without running a browser • Move my logic to
commonMain
and move the test to
jvmTest
. This way I assume I can run the test on the JVM. Is that feasible? Or am I totally in the wrong path?
1
Not sure if this is the correct way of doing it, but I added this logic to my site module's build.gradle.kts
Copy code
kotlin {
    js(IR) {
        browser {
            testTask {
                useKarma {
                    // Use Chrome by default for browser tests
                    useChrome()
                }
            }
        }
        nodejs {
            // Configure NodeJS for running tests
            testTask {
                useMocha()
            }
        }
    }
...
}
And I am able to run tests using
./gradlew jsNodeTest
🙂
👍 1
d
If you're testing business logic then yeah that's a good way to do it
thank you color 1