Skip to content

Commit

Permalink
Recreate golden with this before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Jun 24, 2023
1 parent f3a3d29 commit f62aa1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/browser/vdiff.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { chai, expect } from '@open-wc/testing';
import { executeServerCommand } from '@web/test-runner-commands';

chai.Assertion.addMethod('golden', ScreenshotAndCompare);
mocha.setup({ // eslint-disable-line no-undef
rootHooks: {
beforeEach() {
chai.Assertion.addMethod('golden',
(test => function(...args) {
return ScreenshotAndCompare.call(test, this._obj, ...args); // eslint-disable-line no-invalid-this
})(this.currentTest));
}
}
});

async function ScreenshotAndCompare(name, opts) {
const elem = this._obj;
async function ScreenshotAndCompare(elem, opts) {
const name = this.fullTitle();
const rect = elem.getBoundingClientRect();
const { pass, message } = await executeServerCommand('brightspace-visual-diff', { name, rect, opts });
if (!pass) {
Expand Down
8 changes: 4 additions & 4 deletions test/browser/element.vdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ describe('element-matches', () => {
{ name: 'rtl', rtl: true },
{ name: 'transition', action: elem => elem.style.opacity = '0.2' }
].forEach(({ name, rtl, action }) => {
it(name, async function() {
it(name, async() => {
const elem = await fixture(`<${elementTag} text="Visual Difference"></${elementTag}>`, { rtl: rtl });
if (action) await action(elem);
await expect(elem).to.be.golden(this.test.fullTitle());
await expect(elem).to.be.golden();
});
});
});
Expand All @@ -65,7 +65,7 @@ describe('element-different', () => {
elem.style.height = '70px';
} }*/
].forEach(({ name, action }) => {
it(name, async function() {
it(name, async() => {
const elem = await fixture(`<${elementTag} text="Visual Difference"></${elementTag}>`);
const isGolden = await executeServerCommand('vdiff-get-golden-flag');
if (!isGolden) {
Expand All @@ -75,7 +75,7 @@ describe('element-different', () => {

let fail = false;
try {
await expect(elem).to.be.golden(this.test.fullTitle());
await expect(elem).to.be.golden();
} catch (ex) {
fail = true;
}
Expand Down

0 comments on commit f62aa1a

Please sign in to comment.