moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Improve cross-platform static file reading in tests

Open peterkos opened this issue 1 year ago • 1 comments
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! 🚀

peterkos avatar Mar 25 '24 17:03 peterkos

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

Alex009 avatar Apr 12 '24 02:04 Alex009