Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS nested tests v2 #3913

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

JS nested tests v2 #3913

wants to merge 23 commits into from

Conversation

aSemy
Copy link
Contributor

@aSemy aSemy commented Mar 8, 2024

A continuation of #2957 - full credits to @benkuly for the original PR!

This PR updates #2957 with the latest changes from master. I've tested this locally by publishing Kotest to MavenLocal and checking it in a project, and it seems to work.

Slack thread: https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1709829959811199

Fix #3141

Details

The problem: I believe that JS Test Frameworks first run all contexts to discover them, and then execute the tests. This is in contrast to Kotest, which will execute tests as they are discovered, and this prevents JS Test Frameworks from discovering tests that are defined later.

Workaround

As a workaround Kotest will concatenate the contexts with an arrow:

image

Discussions

Discussions have mostly been taking place in #kotest in the Kotlin Slack. If you'd like to get involved, feel free to join us on Slack, or to leave a comment here on GitHub!

benkuly and others added 5 commits May 4, 2022 11:19
@benkuly benkuly mentioned this pull request Mar 8, 2024
Kantis and others added 6 commits March 9, 2024 13:51
- add more typing to JS externals
- add `@KotestInternal` to JS externals
- adapt some of the JVM SpecExecutor code to JS execution
@OliverO2
Copy link
Contributor

The engine changes in this PR would break #3805.

…ests

# Conflicts:
#	kotest-framework/kotest-framework-engine/src/jsHostedMain/kotlin/io/kotest/engine/PromiseTestCaseExecutionListener.kt
#	kotest-framework/kotest-framework-engine/src/jsMain/kotlin/io/kotest/engine/externalTestMethods.kt
#	kotest-framework/kotest-framework-engine/src/jsMain/kotlin/io/kotest/engine/spec/createSpecExecutorDelegate.kt
@OliverO2
Copy link
Contributor

Not a review at this time, but results from experimenting with the code.

Thank you for getting it to this stage! For browser-based JS, results look good already. Also works partially on Node.js and Wasm, yet some challenges remain.

How I tested

  • settings.gradle.kts: Added mavenLocal() to repositories.
  • kotest-tests/kotest-tests-js/build.gradle.kts: used appropriate version numbers for mavenLocal publication:
    • id("io.kotest.multiplatform") version "5.9.0-LOCAL"
    • kotestCompilerPluginVersion.set("5.9.0-LOCAL")
  • kotest-tests/kotest-tests-js/src: Renamed directory jsTest to jsHostedTest. (jsHosted is the common source set for JS and JS-hosted Wasm. In the future, we'll also see Kotlin supporting standalone Wasm runtimes without a JS API.)
  • kotest-framework/kotest-framework-engine/src/commonMain/kotlin/io/kotest/engine/test/TestCaseExecutor.kt: Added @file:OptIn(ExperimentalStdlibApi::class).
  • gradlew publishToMavenLocal
  • gradlew -p kotest-tests/kotest-tests-js --continue jsBrowserTest jsNodeTest wasmJsBrowserTest wasmJsNodeTest

Observations

  • jsBrowserTest: performs as expected
  • jsNodeTest: performs partially
  • wasmJsBrowserTest: performs partially
    • TimeoutTest, 4 occurrences:

      Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

  • wasmJsNodeTest: performs partially
    • Some tests seem to be missing (e.g. NestedTests/level-1-context).
    • Reports a total of 48 tests (the other invocations report 52).

Suggestions before proceeding with a review

  • Fix remaining issues.
  • Make JS functionality CI-testable, e.g.:
  • Consider integrating kotest-tests/kotest-tests-js into kotest-framework/kotest-framework-multiplatform-plugin-gradle/test-project
    • test-project can be auto-tested with the correct library and compiler plugin version via gradlew kotest-framework:kotest-framework-multiplatform-plugin-gradle:test.
    • test-project can also be used for manually configured local tests by temporarily adding the following properties to kotest-framework/kotest-framework-multiplatform-plugin-gradle/test-project/gradle.properties:
      org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
      
      kotlinVersion=1.9.23
      kotestVersion=5.9.0-LOCAL
      useNewNativeMemoryModel=true
      
  • Add an apiDump for CI testing to succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for nested tests on JS target (again)
4 participants