|
1 | 1 | const path = require('path'); |
2 | 2 | const waitOn = require('wait-on'); |
3 | 3 | const ip = require('ip'); |
4 | | - |
| 4 | +const { compareImages } = require('./utils/imageComparator'); |
5 | 5 | const getBrowser = require('./utils/puppeteer').getBrowser; |
6 | 6 | const { viewports, themes, layouts } = require('./constants'); |
7 | 7 | const DevServer = require('./dev-server'); |
@@ -94,12 +94,19 @@ module.exports = (env, { port = 8080, urls = {} } = {}) => { |
94 | 94 | const customConfig = { threshold: 0.012, includeAA: true }; |
95 | 95 |
|
96 | 96 | function compareSnapshot(image, name, overrideConfig = {}) { |
97 | | - expect(image).toMatchImageSnapshot({ |
98 | | - customDiffConfig: { ...customConfig, ...overrideConfig }, |
99 | | - customSnapshotIdentifier: `${layout}-${theme}-${viewportName}-${name}-snap`, |
100 | | - customDiffDir: diffSnapshotsDir, |
101 | | - storeReceivedOnFailure: true, |
102 | | - customReceivedDir: diffSnapshotsDir |
| 97 | + const snapshotName = `${layout}-${theme}-${viewportName}-${name}`; |
| 98 | + const snapshotPath = path.join(diffSnapshotsDir, `${snapshotName}.png`); |
| 99 | + const diffPath = path.join(diffSnapshotsDir, `${snapshotName}.diff.png`); |
| 100 | + |
| 101 | + return compareImages({ |
| 102 | + imageBuffer: image, |
| 103 | + snapshotPath, |
| 104 | + diffPath, |
| 105 | + threshold: overrideConfig.threshold ?? customConfig.threshold, |
| 106 | + }).then(({ equal, created }) => { |
| 107 | + if (!equal) { |
| 108 | + throw new Error(`Image mismatch for "${snapshotName}". See diff at: ${diffPath}`); |
| 109 | + } |
103 | 110 | }); |
104 | 111 | } |
105 | 112 |
|
@@ -155,11 +162,11 @@ module.exports = (env, { port = 8080, urls = {} } = {}) => { |
155 | 162 | // await page.waitForTimeout(3000); |
156 | 163 | // } |
157 | 164 |
|
158 | | - async function takeScreenshot(options) { |
159 | | - // await hideFooter(); |
| 165 | + async function takeScreenshot(options) { |
160 | 166 | return await page.screenshot({ |
161 | 167 | ...(options || {}), |
162 | | - captureBeyondViewport: false |
| 168 | + captureBeyondViewport: false, |
| 169 | + encoding: 'binary' |
163 | 170 | }); |
164 | 171 | } |
165 | 172 |
|
|
0 commit comments