Kenneth Andersson
02/06/2020, 6:14 AMJoffrey
02/06/2020, 9:07 AMJoffrey
02/06/2020, 9:10 AMJoffrey
02/06/2020, 9:11 AMKenneth Andersson
02/06/2020, 9:18 AMKenneth Andersson
02/06/2020, 9:18 AMJoffrey
02/06/2020, 9:19 AMsrc/commonTest/resources
and access it like a resource, wouldn’t that work?
MyTest::class.java.getResource("/testData.json").readText()
Not sure if this works on JS platform, though, to be honest…Kenneth Andersson
02/06/2020, 9:22 AMJoffrey
02/06/2020, 9:23 AMKenneth Andersson
02/06/2020, 9:23 AM@ExperimentalStdlibApi
actual fun readAbsoluteFile(absolutePath: String): Array<Byte>? {
val str = readFileSync(absolutePath, "UTF-8")
return str.encodeToByteArray().toTypedArray()
}
@ExperimentalStdlibApi
actual fun readRelativeFile(relativePath: String): Array<Byte>? {
return readAbsoluteFile("${rootPath()}$relativePath")
}
fun rootPath(): String {
val falseRoot = resolve(".")
/* absolute returns the build-catalog. Let us go back to project root */
return falseRoot.subSequence(0, falseRoot.indexOf("realroot")).toString()
}
Kenneth Andersson
02/06/2020, 9:24 AMKenneth Andersson
02/06/2020, 9:24 AMJoffrey
02/06/2020, 9:28 AM::class.java
in it, so I bet that won’t work on JS.. 😞 maybe you can implement an expect
/ actual
function to get this file’s contents, the JVM version would use the resource normally with the snippet above, the JS version can probably simply js(require("./testData.json"))
the file, given that gradle places the JSON in the right location during the resources processingKenneth Andersson
02/06/2020, 9:41 AMJoffrey
02/06/2020, 9:45 AMKris Wong
02/06/2020, 1:01 PMKenneth Andersson
02/06/2020, 1:04 PMKenneth Andersson
02/06/2020, 1:04 PMKris Wong
02/06/2020, 1:11 PMJoffrey
02/06/2020, 3:16 PM/tmp
anyway for iOS, why don’t you use the same implementation for all tests (reading from /tmp
) instead of using expect/actual?Kris Wong
02/06/2020, 3:54 PMKenneth Andersson
02/06/2020, 5:54 PMJoffrey
02/07/2020, 9:23 AM