Adam S
01/02/2026, 4:00 PM@TempDir? The directory is only deleted if the test passes, or on CI. On local failures the directory path is logged to console, so it can be checked.Oliver.O
01/02/2026, 4:45 PM@OptIn(ExperimentalPathApi::class)
@TestRegistering
fun TestSuiteScope.testWithDirectory(
name: String,
testConfig: TestConfig = TestConfig,
action: suspend Test.ExecutionScope.(temporaryDirectory: Path) -> Unit
) = testSuiteInScope.test(name, testConfig = testConfig) {
val temporaryDirectory = Files.createTempDirectory("test-$name")
try {
action(temporaryDirectory)
temporaryDirectory.deleteRecursively()
} catch (exception: Throwable) {
if (testPlatform.environment("CI") == null) {
println("Temporary directory: file://${temporaryDirectory.toAbsolutePath()}")
} else {
temporaryDirectory.deleteRecursively()
}
throw exception
}
}
Invoked like so:
val mySuite by testSuite {
testWithDirectory("min") { directory ->
(directory / "my-result.txt").writeText("hello")
assertEquals(4, min(5, 3))
}
}
There are probably ways to make it even simpler, e.g. if a fixture's closeWith had access to the test result, so that it could delete on failure.
And eventually, this seems to be a good use case for platform-independent test metadata (which is on the map), so that we could have it on browsers, too.
What does your use case look like? Would something from the above options be a good fit or do you have something even better in mind?Adam S
01/02/2026, 4:48 PMAdam S
01/02/2026, 4:49 PMmbonnin
01/02/2026, 5:16 PMmbonnin
01/02/2026, 5:17 PM