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

feat: screenshot testing #10

Merged
merged 39 commits into from
Mar 19, 2018
Merged

Conversation

patrickrodee
Copy link
Contributor

Add support for screenshot testing through Puppeteer. Tests run on Travis CI in a headless Chrome browser, parallel with the unit tests.

Copy link

@moog16 moog16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a comment. If you don't wanna change it LGTM


const screenshots = glob.sync(`${DIR}/**/*.png`);

screenshots.forEach((fname) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember you changed this from fname --> screenshot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... changed it back.

@@ -3,4 +3,6 @@

body {
color: blue;
-moz-osx-font-smoothing: grayscale;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never seen moz-osx 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stole this from here

Copy link
Contributor

@lynnmercier lynnmercier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAY!

Write a README in test/screenshot explaining this workflow for both local/travisCI and new-feature/checking-for-regressions

.travis.yml Outdated

dist: trusty
sudo: required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup a matrix in travis.yml with two different jobs, see the MDC Web for an example.

package.json Outdated
"test:ci": "karma start karma.ci.js --single-run",
"test:image-diff": "./node_modules/.bin/mocha --compilers js:babel-core/register --ui tdd --timeout 15000 test/screenshot/diff-suite.js"
"test:unit-ci": "karma start karma.ci.js --single-run",
"test:ci": "./scripts/run-ci-tests.sh",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont htink you'll need test:ci if you split up the travis.yml into two jobs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1,36 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this file once you split up travis.yml into two jobs

const BUCKET_NAME = process.env.BUCKET_NAME;
const COMMIT_HASH = process.env.COMMIT_HASH;
const DIR = './test/screenshot';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase your variables...no need to intense caps

* limitations under the License.
*/

const PATH_TO_KEY = process.env.PATH_TO_KEY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need PATH_TO_KEY. I think the key is always at root.

const storage = new Storage({
keyFilename: PATH_TO_KEY,
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have extra empty lines all over this file


screenshots.forEach((fname) => {
const fileName = path.resolve(fname);
const bucketFileName = fname.replace(DIR, COMMIT_HASH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use PR instead of commit hash

Im worried that if we upload per commit to GCP, then we will end up storing a lot of files. At least with PR number you override the screenshots as you make changes within a PR.

And look into setting up a cron job in GCP to delete all the files in the screenshot-image-captures bucket.

@@ -0,0 +1,40 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should disappear

readFilePromise(imagePath),
]);

const options = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't redefine this variable everytime diff() is called. Make this a variable that screenshot.js imports

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
if (path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to always pass path into createScreenshotTask so you don't need this if check

.travis.yml Outdated
matrix:
include:
- node_js: 8
env: TEST_SUITE=unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think you need these environment variables anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't, but they help to provide names for the builds in Travis. Otherwise, you'd have to click into a build and parse the logs to figure out which test it is.

screen shot 2018-03-19 at 10 10 35 am

@@ -0,0 +1,5 @@
# Uploading screenshots
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This readme should cover

  • running capture locally
  • running screenshot tests locally
  • how screenshot tests work in CI (aka where it uploads the diffs to)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually this should be under test/screenshot

.travis.yml Outdated
- node_js: 8
env: TEST_SUITE=screenshots
install: npm i
script: npm run test:image-diff-ci
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you run ./test/screenshot/start.sh && sleep 10s here before running npm run test:image-diff.

Then you don't even need the test:image-diff-ci NPM command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

sudo: required

matrix:
include:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another job for just linting, it can run npm run lint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.travis.yml Outdated
install: npm i
script: npm run test:image-diff-ci
after_script:
- echo $SERVICE_ACCOUNT_KEY > ./key.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not just reference SERVICE_ACCOUNT_KEY directly? Why do you have to write it to key.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From digging into the docs, it looks like there's support for passing the key directly as a credentials attribute instead of a keyFilename attribute.

I'll update to use that.

@@ -0,0 +1,5 @@
# Uploading screenshots
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually this should be under test/screenshot

@@ -0,0 +1,50 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to test/screenshot directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@lynnmercier lynnmercier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAY

@patrickrodee patrickrodee merged commit 5fd6d86 into master Mar 19, 2018
@moog16 moog16 deleted the experimental/screenshot-testing branch July 17, 2018 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants