Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromeless and Testing #1635

Closed
jbolda opened this issue Jul 27, 2017 · 9 comments
Closed

Chromeless and Testing #1635

jbolda opened this issue Jul 27, 2017 · 9 comments
Labels
good first issue Issue that doesn't require previous experience with Gatsby type: maintenance An issue or pull request describing a change that isn't a bug, feature or documentation change

Comments

@jbolda
Copy link
Contributor

jbolda commented Jul 27, 2017

As much of our code runs client side, some of the errors we see are more subtle or opaque until you build or visit a page. I think it would be helpful in maintaining the myriad of examples and starters by including browser based tests within our test suite. Graphcool just put out a library called Chromeless to run chrome headless locally/on AWS Lamda. We could diff screenshots and check for errors in the console. This might also be useful to add to our CI as we only gatsby build and might miss console errors.

Thoughts or anyone interested in creating a PR?

https://github.com/graphcool/chromeless

@jbolda jbolda added DX labels Jul 27, 2017
@KyleAMathews
Copy link
Contributor

Great thoughts!

Loading the example sites and logging errors + taking screenshots (and comparing with old ones) makes a ton of sense.

Making sure Gatsby's runtime is rock solid is really important so this would be great.

@dan-weaver
Copy link
Contributor

this sounds sorta cool. Anyone started working on this yet?

@sebastienfi
Copy link
Contributor

@dan-weaver Not that I know of. Are you digging in ?

@dan-weaver
Copy link
Contributor

Looking into chromeless a bit. Would we want to actually run these in Lambda or just on the normal ci server?

@KyleAMathews KyleAMathews added good first issue Issue that doesn't require previous experience with Gatsby and removed Great Place To Start Helping labels Oct 29, 2017
@KyleAMathews
Copy link
Contributor

This will get a lot easier with #3242

@m-allanson m-allanson added the type: maintenance An issue or pull request describing a change that isn't a bug, feature or documentation change label Apr 13, 2018
@m-allanson
Copy link
Contributor

See also #4790

@m-allanson m-allanson removed the DX label Apr 13, 2018
@sebastienfi
Copy link
Contributor

sebastienfi commented Apr 16, 2018

@jbolda Why not using Chromium and Puppeteer for that?

Here is some code to get anyone started:

const puppeteer = require("puppeteer");
const { imgDiff } = require("img-diff-js");

(async () => {
  const browser = await puppeteer.launch(); // Here a bunch of options can be set like `headless` and `executablePath`
  const page = await browser.newPage();
  await page.goto("https://example.com"); // `waitUntil: 'load'` seems required for a Gatsby site.

  // We can emulate screen dimension
  await page.setViewport({ width: 1600, height: 1100 });
  // ... and device type
  await page.emulateMedia("screen");

  // Take a screenshot and diff it
  await page.screenshot({ path: "actual.png" }).then(() =>
    imgDiff({
      actualFilename: "actual.png",
      expectedFilename: "expected.png",
      diffFilename: "diff.png"
    }).then(result => console.log(result))
  );

  // Listen to a console message containing error
  page.on(
    "console",
    msg =>
      msg.toLowerInvariant().contains("error")
        ? console.log("PAGE LOG ERROR:", msg.text())
        : ""
  );

  await browser.close();
})();

@jbolda
Copy link
Contributor Author

jbolda commented Apr 17, 2018

@sebastienfi because it wasn't published when I posted this :)

I think at this point puppeteer makes more sense, especially that we can include it in the jest testing. The CI would maybe have different considerations, but that still seems in flux.

@jbolda
Copy link
Contributor Author

jbolda commented Apr 17, 2018

Closing this in favor of tracking in #4361 and #4790. @tsriram seems to be doing some great work there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby type: maintenance An issue or pull request describing a change that isn't a bug, feature or documentation change
Projects
None yet
Development

No branches or pull requests

5 participants