-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading the testing JS on non-JVM platforms (#1018)
* Support loading the testing JS on non-JVM platforms * More public APIs for testing
- Loading branch information
1 parent
85e5063
commit 996349c
Showing
28 changed files
with
160 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
zipline/testing/src/hostMain/kotlin/app/cash/zipline/testing/IoTestingCommon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2023 Cash App | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.zipline.testing | ||
|
||
import app.cash.zipline.Zipline | ||
import okio.FileSystem | ||
import okio.Path | ||
import okio.Path.Companion.toPath | ||
import okio.buffer | ||
import okio.use | ||
|
||
expect val systemFileSystem: FileSystem | ||
|
||
expect val resourcesFileSystem: FileSystem? | ||
|
||
val ziplineRoot: Path | ||
get() = ziplineRootOrNull!! | ||
|
||
val ziplineRootOrNull: Path? | ||
get() = getEnv("ZIPLINE_ROOT")?.toPath() | ||
|
||
internal expect fun getEnv(name: String): String? | ||
|
||
/** Load our testing libraries into QuickJS. */ | ||
fun Zipline.loadTestingJs() { | ||
// Load modules in topologically-sorted order. In production the zipline-manifest does this. | ||
loadJsModuleFromResource("./kotlin-kotlin-stdlib-js-ir.js") | ||
loadJsModuleFromResource("./88b0986a7186d029-atomicfu-js-ir.js") | ||
loadJsModuleFromResource("./kotlinx-serialization-kotlinx-serialization-core-js-ir.js") | ||
loadJsModuleFromResource("./kotlinx-serialization-kotlinx-serialization-json-js-ir.js") | ||
loadJsModuleFromResource("./kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js") | ||
loadJsModuleFromResource("./zipline-root-zipline.js") | ||
loadJsModuleFromResource("./zipline-root-testing.js") | ||
quickJs.evaluate("globalThis['testing'] = require('./zipline-root-testing.js');") | ||
} | ||
|
||
private fun Zipline.loadJsModuleFromResource(fileName: String) { | ||
val fileJs = readJsAsResourceOrFile(fileName) | ||
loadJsModule(fileJs, fileName) | ||
} | ||
|
||
/** Read as a resource on Android, and as a file on the file system on other platforms. */ | ||
private fun readJsAsResourceOrFile(fileName: String): String { | ||
val root = ziplineRootOrNull | ||
val resources = resourcesFileSystem | ||
|
||
val source = when { | ||
root != null -> { | ||
systemFileSystem.source( | ||
root / "zipline/testing/build/compileSync/js/main/developmentLibrary/kotlin" / fileName, | ||
) | ||
} | ||
|
||
resources != null -> resources.source(fileName.toPath()) | ||
|
||
else -> error("no mechanism to read $fileName") | ||
} | ||
|
||
return source.buffer().use { | ||
it.readUtf8() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
zipline/testing/src/jvmMain/kotlin/app/cash/zipline/testing/IoTestingJvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2023 Cash App | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.zipline.testing | ||
|
||
import okio.FileSystem | ||
|
||
actual val systemFileSystem = FileSystem.SYSTEM | ||
|
||
actual val resourcesFileSystem: FileSystem? = FileSystem.RESOURCES | ||
|
||
internal actual fun getEnv(name: String): String? = System.getenv(name) |
Oops, something went wrong.