-
Notifications
You must be signed in to change notification settings - Fork 227
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
Conversation
test: add Travis CI
There was a problem hiding this 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
scripts/upload-screenshots.js
Outdated
|
||
const screenshots = glob.sync(`${DIR}/**/*.png`); | ||
|
||
screenshots.forEach((fname) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never seen moz-osx 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stole this from here
There was a problem hiding this 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 | ||
|
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
scripts/run-ci-tests.sh
Outdated
@@ -0,0 +1,36 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
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
scripts/upload-screenshots.js
Outdated
const BUCKET_NAME = process.env.BUCKET_NAME; | ||
const COMMIT_HASH = process.env.COMMIT_HASH; | ||
const DIR = './test/screenshot'; | ||
|
There was a problem hiding this comment.
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
scripts/upload-screenshots.js
Outdated
* limitations under the License. | ||
*/ | ||
|
||
const PATH_TO_KEY = process.env.PATH_TO_KEY; |
There was a problem hiding this comment.
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.
scripts/upload-screenshots.js
Outdated
const storage = new Storage({ | ||
keyFilename: PATH_TO_KEY, | ||
}); | ||
|
There was a problem hiding this comment.
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
scripts/upload-screenshots.js
Outdated
|
||
screenshots.forEach((fname) => { | ||
const fileName = path.resolve(fname); | ||
const bucketFileName = fname.replace(DIR, COMMIT_HASH); |
There was a problem hiding this comment.
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.
scripts/upload-screenshots.sh
Outdated
@@ -0,0 +1,40 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should disappear
test/screenshot/screenshot.js
Outdated
readFilePromise(imagePath), | ||
]); | ||
|
||
const options = { |
There was a problem hiding this comment.
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
test/screenshot/screenshot.js
Outdated
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
await page.goto(url); | ||
if (path) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/README.md
Outdated
@@ -0,0 +1,5 @@ | |||
# Uploading screenshots |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
sudo: required | ||
|
||
matrix: | ||
include: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
scripts/README.md
Outdated
@@ -0,0 +1,5 @@ | |||
# Uploading screenshots |
There was a problem hiding this comment.
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
scripts/upload-screenshots.js
Outdated
@@ -0,0 +1,50 @@ | |||
/** |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAY
Add support for screenshot testing through Puppeteer. Tests run on Travis CI in a headless Chrome browser, parallel with the unit tests.