Skip to content

Commit

Permalink
setup screenshot test config properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 7, 2019
1 parent 1d70276 commit 613c97b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

deploy-preview:
docker:
- image: circleci/node:10.6
- image: circleci/node:latest-browsers
working_directory: ~/repo
steps:
- checkout
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:

deploy-release:
docker:
- image: circleci/node:10.6
- image: circleci/node:latest-browsers
working_directory: ~/repo
steps:
- checkout
Expand Down
3 changes: 1 addition & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
- rc/*

- name: deploy-preview
image: node:10.6
image: buildkite/puppeteer
environment:
FIGMA_MAIN_FILE:
from_secret: FIGMA_MAIN_FILE
Expand Down Expand Up @@ -81,7 +81,6 @@ steps:
- yarn test-ci
- yarn prepublish-ci
- yarn build-ci
- yarn test-ci-screenshots
- yarn deploy-ci
- yarn publish-ci
when:
Expand Down
3 changes: 3 additions & 0 deletions packages/dnb-ui-lib/jest-screenshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pixelThresholdRelative": 0.15
}
3 changes: 2 additions & 1 deletion packages/dnb-ui-lib/jest.config.screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const config = require('./jest.config.js')
module.exports = {
...config,
...{
testRegex: 'screenshot.test.js$',
globalSetup: './src/core/jest/jestPuppeteerSetup.js',
globalTeardown: './src/core/jest/jestPuppeteerTeardown.js',
testEnvironment: './src/core/jest/jestPuppeteerEnvironment.js',
testRegex: 'screenshot.test.js$',
setupFilesAfterEnv: ['./src/core/jest/setupJestScreenshot.js'],
modulePathIgnorePatterns: config.modulePathIgnorePatterns.filter(i => {
return i !== 'screenshot'
})
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/scripts/figma/helpers/docHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const getFigmaDoc = async ({
forceRefetch = null,
preventUpdate = null
} = {}) => {
if (!figmaFile) {
if (!(figmaFile && String(figmaFile).length > 0)) {
figmaFile = defaultFigmaFile
}

Expand Down
5 changes: 4 additions & 1 deletion packages/dnb-ui-lib/src/core/jest/jestPuppeteerSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module.exports = async function() {
// })
}

const browser = await puppeteer.launch()
const browser = await puppeteer.launch({
// to get rid of the "libX11-xcb.so" missing problem, we set these flags
args: ['--no-sandbox', '--disable-setuid-sandbox']
})
// store the browser instance so we can teardown it later
// this global is only available in the teardown but not in TestEnvironments
global.__BROWSER_GLOBAL__ = browser
Expand Down
10 changes: 0 additions & 10 deletions packages/dnb-ui-lib/src/core/jest/jestSetupScreenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

const path = require('path')
const os = require('os')
const { setupJestScreenshot } = require('jest-screenshot')

const screenshotConfig = {
// detectAntialiasing: true, // Whether to attempt to detect antialiasing and ignore related changes when comparing both images.
// pixelThresholdRelative: 0, // If specified, jest-screenshot will fail if more than the specified relative amount of pixels are different from the snapshot. When setting this to 0.5 for example, more than 50% of the pixels need to be different for the test to fail.
// colorThreshold: 1 // A number in the range from 0 to 1 describing how sensitive the comparison of two pixels should be.
// colorThreshold: 0
}

const testScreenshotOnHost = '127.0.0.1'
const testScreenshotOnPort = 8000
Expand Down Expand Up @@ -62,6 +54,4 @@ module.exports.setupPageScreenshot = (options = { timeout: 10e3 }) => {
}
done()
})

setupJestScreenshot({ ...screenshotConfig, ...options })
}
7 changes: 7 additions & 0 deletions packages/dnb-ui-lib/src/core/jest/setupJestScreenshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Jest Setup for Screenshot testing
*
*/

const { setupJestScreenshot } = require('jest-screenshot')
setupJestScreenshot()

0 comments on commit 613c97b

Please sign in to comment.