I just took the time to open source snapshot. It’s a simple library that makes testing modules that are slow because of side effects and make them run as fast and reliable as the other tests by creating snapshots of function calls and outputs. It just involves adding a single line to your module.
This makes it easy testing complex behaviour of modules that involve network or computational intensive work, snapshotting the bottlenecks, and have the test run every-time instead of putting them behind a separate tag because they are slow.
Note: if the inputs change every requests this will not work. In that case you should set up a mock module with some business logic.
Really interested to know what you think, and how it might be improved.
Maybe you could retrieve the AST from the module you want to test and real compile it with whatever custom transformations you need.
This is probabky something you shoud never ever do in production. Elixir makes it intentionally hard (almost impossible?) for a macro in one module to cause changes in another module, but for testing ir might be ok
@OvermindDL1, I know this is definitely not the elixir way (probably the elixir forbidden road or something), but how can one have access to a module’s AST? Having access to the .beam file is easy, but there might be better ways to apply source transformations to a module. Instrumenting the .beam bytecode seems suboptimal.