https://kotlinlang.org logo
#feed
Title
# feed
b

Big Chungus

05/29/2021, 4:26 AM
Just released klip@0.0.1 to maven central and gradle plugin portal. It's an exploration project of KSP that lets you do easy snapshot testing. Currently only works on jvm, but all code is multiplatform, so it'll support more targets as KSP expands into MPP. Give it a go!
c

christophsturm

05/29/2021, 7:49 AM
what does it do at compile time?
d

Dmitry Kandalov

05/29/2021, 9:35 AM
Hm, why is it a gradle plugin and not just a library?
b

Big Chungus

05/29/2021, 10:42 AM
To answer both of your questions, ir needs the plugin to generate stubs and assertions for each annotated class and inject system paths.
You might be able to get around that on jvm, but on js you get just one output file, so it's a must. I went with ksp for now, and as such it's not that powerful, but I'm thinking of exploring a direct compiler plugin to inject paths by rewriting call sites.
d

Dmitry Kandalov

05/29/2021, 10:57 AM
Hm, why generate stubs, assertions and inject systems paths? I thought it could be just a function call which compares output with a file content 🤷
b

Big Chungus

05/29/2021, 10:59 AM
To avoid having to pass them in each time. There's a much better solution for java already, but keeping mpp support makes things trickier (thus the compiler plugin route).
d

Dmitry Kandalov

05/29/2021, 11:03 AM
@SnapshotName("i_can_give_custom_names_to_my_snapshots")
not sure I like that 🙈
I used this https://github.com/dmcg/okey-doke which infers approval file name from the current class and test name. I’m also always triggered by “snapshot testing” which I think is more misleading term than “approval testing” (and it existed before facebook anyway).
To avoid having to pass them in each time
I still don’t really get it but I’m guessing you’re trying to avoid reflection and want it to be multiplatform, that’s why gradle or compiler plugin.
b

Big Chungus

05/29/2021, 11:09 AM
I have to avoid reflection (js islimited). Keep in mind that this is just me learning ksp. I expect it'll serve best as an example of ksp setup rather than actual plugin to use (although it is kinda cool). Hopefully it'll mature as kotlin compiler api stabilises.
👍 3
Jvm already has many better solutions, so there's really no point there. Mpp is uncharted territory though 😀
And with ksp promising mpp support in kotlin 1.5.20, this prepares all the groundwork.
d

Dmitry Kandalov

05/29/2021, 11:16 AM
From my experience these kind of libraries need extra tooling which is often missing, e.g. finding orphaned approval/snapshot files, rename files when code is refactored, doing bulk approval, etc.
b

Big Chungus

05/29/2021, 11:17 AM
That's doable with the help of compiler plugin. Just needs work.
d

Dmitry Kandalov

05/29/2021, 11:17 AM
Hm, I think more like an IDE plugin 😅
b

Big Chungus

05/29/2021, 11:17 AM
But having everything seemleasly managed by gradle plugin gives lots of options
I'd like to avoid needing an ide plugin. Any tool in my belt should work with cli alone
1
c

christophsturm

05/29/2021, 12:12 PM
From my experience these kind of libraries need extra tooling which is often missing, e.g. finding orphaned approval/snapshot files, rename files when code is refactored, doing bulk approval, etc.
i think its best if they need no tooling at all. just a simple directory structure where its obvious what file you have to delete. and human readable snapshot files.
b

Big Chungus

05/29/2021, 12:14 PM
That's how it currently does it. All files are placed in src/sourceSetName/klips directory that mimics original file hierarchy from sources
I saw other putting generated files in sources folder besides the actual test file, but that's smells too much like js for me 😀 I prefer keeping my sourceCode isolated
c

christophsturm

05/29/2021, 12:16 PM
if you have it in a separate source root, can you make idea show the snapshot near the source files without a plugin? maybe in package view?
b

Big Chungus

05/29/2021, 12:19 PM
Not without idea plugin. Although I could easily add a flag to gradle plugin to allow overriding this behaviour and place stuff by the test files.
c

christophsturm

05/29/2021, 1:20 PM
idea should just do that per default in the package view imo
d

Dmitry Kandalov

05/29/2021, 1:29 PM
I agree about simple directory structure and human readable files, however, on large project obvious things become less obvious and there will be some orphaned approval files sooner or later 😅
Also it’s not ideal but some changes will make a lot of approval files invalid so it might be useful to run all tests accepting changes and reviewing them in version control before commit.
And regardless of the library I want to be able to see diffs and approve changes with “alt enter” without navigating too far away 🙃
c

christophsturm

05/29/2021, 1:45 PM
ok but for approving the changes you can just use git
and the fixture test library could output a list of orphaned files.
b

Big Chungus

05/29/2021, 1:46 PM
You could revert changes individually inintellij git diff view 😀
As for orphaned files, that's a good idea. I'm thinking warning messages once detected with an option to rerun tests with some flag to clean them up once reviewed
If anyone wants to contribute intellij plugin hit me up. I have no clue how that works to do it myself 😀