bahmutov / snap-shot

Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
169 stars 3 forks source link

Make it work in the browser with karma #34

Open kof opened 7 years ago

kof commented 7 years ago

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.

kof commented 7 years ago

For e.g. we could run a snapshot server and send xhr requests for every snapshot.

bahmutov commented 7 years ago

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

kof commented 7 years ago

Another way would be to load all snapshots upfront to the browser and just compare strings on snapshot()

kof commented 7 years ago

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.

kof commented 7 years ago

Actually loading all snapshots into memory and comparing snapshot from there should be fine for the regular case as well.

kof commented 7 years ago

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.

kof commented 7 years ago

I could use this project immediately for https://github.com/cssinjs/jss if we get this in.

bahmutov commented 7 years ago

If I can accurately factor this out to make compatible with Karma ...

mAAdhaTTah commented 7 years ago

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?

bahmutov commented 7 years ago

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.

mAAdhaTTah commented 7 years ago

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?