Open kof opened 7 years ago
For e.g. we could run a snapshot server and send xhr requests for every snapshot.
Love Karma myself and agree that this would be great to have (not just jsdom). I actually factored the file system vs browser (uses localStorage, but should use XHR to the server) into https://github.com/bahmutov/snap-shot/blob/master/src/browser-system.js and https://github.com/bahmutov/snap-shot/blob/master/src/file-system.js.
Will work on this if have time, but I plan to remove the implementations here and instead make it work in https://github.com/bahmutov/snap-shot-core instead. This way I could reuse snapshot save / load functionality in other projects like https://github.com/bahmutov/schema-shot
Another way would be to load all snapshots upfront to the browser and just compare strings on snapshot()
Sending XHR might be very slow considered platforms like browserstack are not on the same server as the CI. Those are actually real http requests across the global network in that case.
Actually loading all snapshots into memory and comparing snapshot from there should be fine for the regular case as well.
Basically you need to allow passing functions which load and save a snapshot. So we can easily swap them out to use fs or memory.
I could use this project immediately for https://github.com/cssinjs/jss if we get this in.
If I can accurately factor this out to make compatible with Karma ...
I would use this if it was compatible w/ Karma. I'm also using webpack to compile my tests; does that make it more complicated?
The difficulty with Karma is not solved by webpack, because we need to save results of snapshots, get source for the files, etc. So we need to somehow write and load results from the disk. Hmm, it is complicated.
The difficulty with Karma is not solved by webpack
I know, quite the opposite: it makes the whole process more complicated, which is why I mentioned it. I think reporters can write to the filesystem (code coverage is handled as a reporter); maybe there's an in as a custom reporter?
I don't know if its something for this repo, but I am using real browsers, because tests are partially dom related and need to be tested in all the browsers. It would be cool to be able to use snapshots there as well. I realize its an entirely different thing, but maybe we can work something out.