moko-resources
moko-resources copied to clipboard
Improve cross-platform static file reading in tests
trafficstars
Hello!
Been using 0.24.alpha-5, and it doesn't appear possible to readText() when running a unit test via iOS in KMP. FileResource requires a context, but it's been tricky to implement this.
There's a similar library kotlinx-resources that implements this for text files:
/*
* For Apple platforms, move resources into the binary's output directory so that they
* can be loaded using `NSBundle.mainBundle` and related APIs.
*/
if (isAppleCompilation(kotlinCompilation)) {
val target = kotlinCompilation.target
target.binaries.forEach { binary ->
setupCopyResourcesTask(
kotlinCompilation = kotlinCompilation,
taskName = getTaskName("copyResources", binary.name, target.targetName),
outputDir = binary.outputDirectory,
mustRunAfterTasks = listOf(kotlinCompilation.processResourcesTaskName),
dependantTasks = listOf(binary.linkTaskName)
)
}
}
Would be cool to have something similar here! 🚀
we have unit tests that run on all platforms and successful read resources - https://github.com/icerockdev/moko-resources/tree/master/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library
@ExNDY need to check is it works. maybe something with files specially