Just released <klip@0.0.1> to maven central and gr...
# feed
b
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
what does it do at compile time?
d
Hm, why is it a gradle plugin and not just a library?
b
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
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
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
@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
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
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
That's doable with the help of compiler plugin. Just needs work.
d
Hm, I think more like an IDE plugin šŸ˜…
b
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
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
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
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
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
idea should just do that per default in the package view imo
d
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
ok but for approving the changes you can just use git
and the fixture test library could output a list of orphaned files.
b
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 šŸ˜€