Adam S
01/04/2023, 10:20 PMdata-test-code=example-hello-world-test.kt
• expected test results are tagged with data-test-expected=example-hello-world-test.kt
• a Compose Web test then scrapes those code blocks out, and saves them to disk, along with a generated test case
• and then another process (another Gradle task maybe?) runs the generated tests
Sample code in 🧵
Thoughts?Adam S
01/04/2023, 10:28 PMintroToKotlin()
in commonMain, and then it would be easier in JVM to save the files, or run them dynamically via a scripting engine or Gradle Test Kit.David Herman
01/05/2023, 1:44 AMDavid Herman
01/05/2023, 1:44 AMCode { Text(...) }
?David Herman
01/05/2023, 1:48 AMDavid Herman
01/05/2023, 1:51 AMproperty
. Those are meant for valid styles. I bet if you inspect the DOM you'll get a bunch of confused highlights. Feels like you're (ab)using the behavior to be able to register random information on your elements.David Herman
01/05/2023, 1:54 AMDiv(attrs = {
attr("data-blah", "example")
})
As a bonus, it's even a little less code
See also: https://css-tricks.com/a-complete-guide-to-data-attributes/David Herman
01/05/2023, 2:01 AMDiv {
P { Text("What does Hello World look like?") }
CodeSnippet("hello-world-example-01.kt")
P { Text("As expected, it logs") }
CodeSnippet("hello-world-example-01-out.kt")
}
}
@Composable
fun CodeSnippet(filename: String) {
var content by remember { mutableStateOf("Loading...") }
LaunchedEffect(Unit) {
window.fetch(filenamen).then { response ->
response.text().then { content = it }
}
}
Pre { Code { Text(content) } }
}
David Herman
01/05/2023, 2:03 AMresources
directory.Adam S
01/05/2023, 10:24 AMI’m not that’s the expected way for people to use propertyoops yes, thanks. I meant to use
attr()
Adam S
01/05/2023, 10:33 AMAs an alternate approach, I imagine you can create a bunch of real .kt files in your resources folder, compile and run them using Gradle and capture their output, and then just embed those kt files directly into your site?Yeah I thought about that. There are some things that I didn’t like: • when writing docs I don’t like switching between the source code and documentation, and I think it will be more likely for them to get out of sync • what happens if you only want to use part of the source code in the site? For example, you want to hide the imports. In Knit, you can put hidden code in a comment. If you’re including something from a file then you need some sort of start/end tagging system (like what the Gradle docs do)