mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2026-05-26 13:00:24 -04:00
* chore(deps): bump ssri from 6.0.1 to 6.0.2 Bumps [ssri](https://github.com/npm/ssri) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/npm/ssri/releases) - [Changelog](https://github.com/npm/ssri/blob/v6.0.2/CHANGELOG.md) - [Commits](https://github.com/npm/ssri/compare/v6.0.1...v6.0.2) Signed-off-by: dependabot[bot] <support@github.com> * chore: add diff image * chore: revert waitFor Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: caele <tsm@qlik.com>
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
const path = require('path');
|
|
const jimp = require('jimp');
|
|
|
|
const differ = () => {
|
|
const artifacts = path.resolve(__dirname, '../__artifacts__/');
|
|
|
|
return {
|
|
async looksLike(name, captured) {
|
|
const file = `${path.basename(__dirname)}-${name}`;
|
|
const stored = await jimp.read(path.resolve(artifacts, 'baseline', file));
|
|
const distance = jimp.distance(stored, captured);
|
|
const diff = jimp.diff(stored, captured);
|
|
if (distance > 0.001 || diff.percent > 0.001) {
|
|
await captured.writeAsync(path.resolve(artifacts, 'regression', file));
|
|
await diff.image.writeAsync(path.resolve(artifacts, 'diff', file));
|
|
throw new Error(`Images differ too much - distance: ${distance}, percent: ${diff.percent}`);
|
|
}
|
|
},
|
|
};
|
|
};
|
|
|
|
const d = differ();
|
|
|
|
describe('snapper', () => {
|
|
const object = '[data-type="bar"]';
|
|
const selector = `${object} .njs-viz`;
|
|
it('should capture an image of a bar', async () => {
|
|
await page.goto(`${process.env.BASE_URL}/snaps/snapper.html`);
|
|
|
|
await page.waitForSelector(selector, { visible: true });
|
|
await page.click(selector);
|
|
await page.waitForSelector(`${object}[data-captured]`, { visible: true });
|
|
const imgSrc = await page.$eval(`${object}[data-captured]`, (el) => el.getAttribute('data-captured'));
|
|
|
|
const captured = await jimp.read(`${process.env.BASE_URL}${imgSrc}`);
|
|
await d.looksLike('bar.png', captured);
|
|
});
|
|
});
|