Vampire
01/13/2025, 10:09 AMwithData
with an argument that is the result of a suspending call (readdir
).LeoColman
01/13/2025, 1:04 PMLeoColman
01/13/2025, 1:06 PMVampire
01/13/2025, 1:16 PMclass SchemaTest : FunSpec({
beforeSpec {
validate = Ajv(Options(strict = true)).compile(
JSON.parse(readFile(schemaFile, utf8))
)
}
withData(readdir(dataDir).asIterable()) {
readFile(path.join(dataDir, it), utf8) should beValid()
}
})
lateinit var validate: ValidateFunction
fun beValid(): Matcher<String> {
return Matcher { data ->
MatcherResult(
validate(YAML.parse(data)),
{ "..." },
{ "..." },
)
}
}
Where readdir
is the "problematic" call that is not working as not in a suspending context.
Wrapping the withData(...) { ... }
into context("foo") { ... }
compiles as now the readdir
is done in the suspending context, but it fails at runtime as nested tests are not supported on JS due to https://github.com/kotest/kotest/issues/3141.Vampire
01/13/2025, 1:17 PMVampire
01/13/2025, 1:20 PMfunSpec(...)
function also is not suspending so would have the same problem, wouldn't it?Vampire
01/13/2025, 1:31 PMwithData
or something else, I don't care too much.
But it has to work for K/JS, so cannot use nested tests currently.Vampire
01/14/2025, 1:27 PMEmil Kantis
01/14/2025, 2:58 PMrunBlocking
?Emil Kantis
01/14/2025, 2:59 PMVampire
01/14/2025, 3:49 PMException during run: IllegalStateException: runBlocking is not available on JS๐
Oliver.O
01/14/2025, 3:53 PMCLOVIS
01/14/2025, 3:53 PMVampire
01/14/2025, 3:59 PMI'm not sure whether you might get away with invoking the suspending setup function in the first leaf test, then reusing its results in subsequent tests.That wouldn't help here. I do that with
beforeSpec
already where I do a suspending call to read a file that I then later use in the tests.
But I want to generate test cases from the result of the suspending call here.Vampire
01/14/2025, 3:59 PMVampire
01/14/2025, 4:02 PMOliver.O
01/14/2025, 4:03 PMsuite
invocations.CLOVIS
01/14/2025, 4:03 PMVampire
01/14/2025, 4:05 PMCLOVIS
01/14/2025, 4:07 PMVampire
01/14/2025, 4:08 PMCLOVIS
01/14/2025, 4:09 PM:runner-kotest
and possibly :compat-parameterize
, with the setup being described here: https://opensavvy.gitlab.io/groundwork/prepared/api-docs/runners/runner-kotest/index.htmlVampire
01/14/2025, 4:16 PMsuite
is not suspending so I cannot do the readdir
callCLOVIS
01/14/2025, 4:16 PMprepared {}
: https://opensavvy.gitlab.io/groundwork/prepared/docs/features/prepared-values.htmlOliver.O
01/14/2025, 4:18 PMprepared
lambda, right?CLOVIS
01/14/2025, 4:18 PMCLOVIS
01/14/2025, 4:19 PMVampire
01/14/2025, 4:26 PMCLOVIS
01/14/2025, 5:22 PMVampire
01/14/2025, 5:37 PMVampire
01/14/2025, 6:32 PMreaddirSync
instead of readdir
as that is not suspending but blocking.
The general question is still interesting on whether it can be solved, but my use-case is solved with that.
๐