goncalossilva / kotlinx-resources

Kotlin Multiplatform (KMP) library for reading resources in tests
MIT License
115 stars 5 forks source link

Cross module test resources not found #131

Closed zt64 closed 1 month ago

zt64 commented 1 month ago

Hi, in my project I have a common testing module that all my other modules depend upon in their commonTest sourceset. testing uses kotlinx-resources for a resource wrapper object. The issue is though when I use a resource from outside the testing module it's unable to find the file.

testing - commonMain

object TestResources {
    val RESOURCE_1 = Resource("src/commonMain/resources/video/SampleVideo_1280x720_5mb.mp4")
}

lib - commonTest

TestResources.RESOURCE_1.readBytes()

src/commonMain/resources/video/SampleVideo_1280x720_5mb.mp4: No such file or directory

And if I add the file to the same path in the current module then it fixes it. Is this something with the library that can be fixed?

goncalossilva commented 1 month ago

Resource path is relative to the project under compilation (ref). There is no support for exporting or consuming resources alongside other projects, and I'm not sure that this would be easy to do in the way the plugin currently works, unfortunately.

It's possible you can still bundle this in your testing module and rely on the relative path to other modules being the same every time. E.g., Resource("../testing/src/commonMain/resources/video/SampleVideo_1280x720_5mb.mp4"). It's not pretty, but it should work, provided the relative path from testing to other modules is the same every time.