cashapp / molecule

Build a StateFlow stream using Jetpack Compose
https://cashapp.github.io/molecule/docs/1.x/
Apache License 2.0
1.86k stars 81 forks source link

`moleculeFlow` with immediate recomposition mode errors on NodeJS #441

Open kevincianfarini opened 4 months ago

kevincianfarini commented 4 months ago

I introduced molecule as a way to test some library code which exposes a Composable function. In doing so, I exposed that molecule does not seem to be compatible with NodeJS while running tests. I get the following error:

io.github.kevincianfarini.monarch.StateOfTest.stateOf_starts_with_current_value[js, node] FAILED
    ReferenceError: window is not defined
        at <global>.sendFrame(/home/kevin/code/monarch/compose/build/compileSync/js/test/testDevelopmentExecutable/kotlin/js-ir/runtime/long.kt:27)
        at GatedFrameClock.protoOf.set_isRunning_m21k59(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/GatedFrameClock.kt:45)
        at slambda.protoOf.doResume_5yljmg(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/molecule.kt:80)
        at slambda.protoOf.invoke_d9fzmj(kotlin/molecule-molecule-runtime.js:459)
        at <global>.l(kotlin/molecule-molecule-runtime.js:543)
        at <global>.startUndispatchedOrReturn(/home/kevin/code/monarch/compose/build/compileSync/js/test/testDevelopmentExecutable/kotlin/js-ir/src/kotlin/coroutines_13/IntrinsicsJs.kt:99)
        at <global>.coroutineScope(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/CoroutineScope.kt:261)
        at slambda.protoOf.doResume_5yljmg(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/molecule.kt:61)
        at slambda.protoOf.invoke_ilgcjr(kotlin/molecule-molecule-runtime.js:556)
        at SafeFlow.block(kotlin/molecule-molecule-runtime.js:603)
        at SafeFlow.protoOf.collectSafely_blptet(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/Builders.kt:57)
        at 3.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/Flow.kt:226)
        at SafeFlow.protoOf.collect_aksokr(kotlin/kotlinx-coroutines-core.js:10079)

Is this expected behavior? I see that this repository declares JS targets that run tests on the browser, but should that preclude it from running on NodeJS? I've tried using both the Jetbrains Compose plugin while declaring molecule's runtime as implementation, and using the molecule plugin directly. Both produce the same results.

Here's a public reproducer sample: https://github.com/kevincianfarini/monarch/commit/b1566e6b1f91bfdfd03b200b6109d0440aff94e7