snapguidist icon indicating copy to clipboard operation
snapguidist copied to clipboard

How do I run the snapshots in CI

Open ForbesLindesay opened this issue 7 years ago • 14 comments

I want to be able to test all the snapshots automatically on travis. When I run styleguidist build, it builds successfully even with invalid snapshots.

ForbesLindesay avatar Jun 11 '17 23:06 ForbesLindesay

Thanks @ForbesLindesay for opening this issue. This is a very good point, we'll look into it.

MicheleBertoli avatar Jun 12 '17 06:06 MicheleBertoli

I’m also interested in that ;-) I think it’s the most useful use case for snapshots in Styleguidist.

sapegin avatar Jun 12 '17 07:06 sapegin

I wouldn't say it's the most useful use case (snapshot testing gives you much more) :) But it's absolutely something we should think about.

MicheleBertoli avatar Jun 12 '17 09:06 MicheleBertoli

Love the library so far! But not having this is a deal breaker for using it in our project.

Keep up the good work @MicheleBertoli .

hugogrochau avatar Jul 13 '17 19:07 hugogrochau

Thanks @hugogrochau.

In order to run the tests at build time, we'd need a way to get all the code snippets from react-styleguidist without running the UI. Is there a way to do it @sapegin?

Otherwise, we'd need to generate "real" test files (instead of running Jest through an endpoint), which would solve #18 as well.

MicheleBertoli avatar Jul 21 '17 08:07 MicheleBertoli

Not now, but it would be a useful feature. Feel free to send a pull request for that ;-)

sapegin avatar Jul 21 '17 08:07 sapegin

Would be great to generate "real" test files from examples, stored in every component folder (where jest expects them, aka. __tests__), we could start by creating two simple tests (renders without crashing & renders correctly). Exposing both the target folder and actual template filepath used to generate tests as options would be nice.

One issue that I encountered trying to implement it was that the Playground component from styleguidist does not receive the component path as a prop, so we would have to further override components up the chain to grab that (to give back the proper path on the server side) or land a PR upstream to add the missing props.

One other issue would be that these test would be auto-generated and therefore you could not add extra test in the same files, so it would need a big disclaimer (eg. auto-generated, do not edit)

But for my use case, having a non-crashing test, tree-snapshot test and also a visual-snapshot test (can be done with puppeteer) for every example in my readme would be just perfect. And having the README as the single source of truth for both docs and testing sounds nice.

mgcrea avatar Aug 20 '17 16:08 mgcrea

Any news on this issue?

nanndoj avatar Sep 26 '17 10:09 nanndoj

Hello @nanndoj we didn't receive any PR yet : )

MicheleBertoli avatar Sep 30 '17 07:09 MicheleBertoli

It seems like it shouldn't be too hard to extract all code snippets from the markdown and generate a .test.js file that could be used with jest.

kevinbarabash avatar Apr 17 '18 20:04 kevinbarabash

I'm glad to hear it shouldn't be too hard @kevinbarabash, would you be happy to submit a PR? Thank you very much!

MicheleBertoli avatar Apr 19 '18 20:04 MicheleBertoli

@MicheleBertoli I'm not sure how much time I'll have. Here's a link to the code that I used in my own project for this: https://github.com/Khan/wonder-blocks/commit/f0a4c7511321e9bf4c40f5d792c949a701cf448f. Unfortunately, it doesn't handle some of the cases allowed by styleguide.config.js. It also doesn't handle the case where a example contains multiple components at the root level.

kevinbarabash avatar Apr 20 '18 00:04 kevinbarabash

I am very interested in this being supported. I am a little bit concerned however, of the difficulty of making sure that the snapshots are generated identically inside a standard jest environment and inside the browser at dev time.

For example, I insert a custom wrapper component into my styleguidist config to give each example an appropriate context, I am not sure how snapguidist would be able to maintain this properly during CI if it was running outside of styleguidist.

Has it been considered to actually run the standard styleguidist dev server at CI time and evaluate the tests in the actual browser? Granted, it feels odd to do that, but on the other hand if we think that the browser is a fine place to generate snapshots today, why not maintain the same during CI?

I threw together a very quick POC of this to see what it would take and it was pretty small. Thoughts?

joeljeske avatar Oct 19 '18 01:10 joeljeske

I threw together a very quick POC of this to see what it would take and it was pretty small.

Lovely, please submit a PR!

MicheleBertoli avatar Oct 21 '18 13:10 MicheleBertoli