garris / BackstopJS

Catch CSS curve balls.
http://backstopjs.org
MIT License
6.66k stars 603 forks source link

testing staged changes #934

Closed AdrienLemaire closed 5 years ago

AdrienLemaire commented 5 years ago

I've discovered BackstopJS recently and am trying to implement it in a project with a very high ratio of dynamic content (random feeds & co).

I would like to use BackstopJS in 2 steps:

Can we handle the staged testing part without using the backstop.json file (which would be used on the ci) ? I'm currently thinking of adding documentation in each component file with metas for the scenarios, eg

/*
 * backstop-label: Contact page
 * backstop-url: /contact/
 * backstop-selectors: ["#contact"]
 */
import React, {Component} from "react";

export default class Contact extends Component {
  …
}

Then I'd be able to generate the label/url/referenceUrl/selectors objects for scenarios and rewrite the backstop.json file to test staged files.

I'm hoping that you have a better suggestion to handle this use-case to avoid the inline documentation overhead.

garris commented 5 years ago

Sorry -- not quite sure I understand what you're trying to test. Configs can be json or JS files that are executed at runtime. Configs can also be dynamically generated when running backstop as a module https://github.com/garris/BackstopJS/blob/master/README.md#integration-options-local-install

Hope that helps.

AdrienLemaire commented 5 years ago

As a developer, if I modify a component related to the contact page, I only want to have backstop test that page, not the whole application. Only the CI should be running the full css regression test suite.

I will try to write a js script by importing backstop and giving it an object built. thanks for pointing to the right documentation :+1:

garris commented 5 years ago

Ah, good. actually, you probably don't even need to use an active script. Just include the --filter=<scenarioForComponentName> argument when invoking backstop. Way easier.

AdrienLemaire commented 5 years ago

Got it, thanks. Closing since this looks resolved, and will reopen if I don't manage to implement it correctly :)

garris commented 5 years ago

Also, CSS is global scope -- so if your touching css you probably do want to test everything else -- at least at commit time. Food for thought there.

AdrienLemaire commented 5 years ago

We use cssInJs, and although we do have global css, we're trying to regulate it through material-ui themes. We also don't want to wait minutes before we can git push something, and pull requests cannot be merged until the CI check has passed, so it's fine in our case. Thanks for the heads up !