Skip to content

Commit

Permalink
Revert element-different failure files
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Sep 16, 2024
1 parent 9e0ff28 commit 53f9e56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 6 additions & 2 deletions test/browser/element.vdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ describe('element-different', () => {
} catch (ex) {
fail = true;
}
await expect(fail, 'current and golden images to be different').equal(!isGolden);

expect(fail, 'current and golden images to be different').equal(!isGolden);
if (!isGolden) {
await executeServerCommand('vdiff-revert-golden-file', { testCategory: 'element-different', fileName: `${name}.png` });
}
});
});

Expand All @@ -237,7 +240,8 @@ describe('element-different', () => {
}

if (!isGolden) {
expect(fail, 'current and golden images to have different byte size').equal(true);
await expect(fail, 'current and golden images to have different byte size').equal(true);
await executeServerCommand('vdiff-revert-golden-file', { testCategory: 'element-different', fileName: 'byte-size.png' });
} else {
// Modify golden file to be different byte size than what the test will generate
await executeServerCommand('vdiff-modify-golden-file', { testCategory: 'element-different', fileName: 'byte-size.png' });
Expand Down
26 changes: 24 additions & 2 deletions test/browser/vdiff.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { argv, env } from 'node:process';
import { dirname, join } from 'node:path';
import { readFile, writeFile } from 'node:fs/promises';
import { copyFile, readFile, writeFile } from 'node:fs/promises';
import { PATHS } from '../../src/server/paths.js';
import { PNG } from 'pngjs';

Expand Down Expand Up @@ -40,7 +40,29 @@ function modifyGolden() {
};
}

function revertGolden() {
let rootDir;
return {
name: 'vdiff-revert-golden-file',
async serverStart({ config }) {
rootDir = config.rootDir;
},
async executeCommand({ command, payload, session }) {
if (command !== 'vdiff-revert-golden-file') return;
const browser = session.browser.name.toLowerCase();
const testPath = dirname(session.testFile).replace(rootDir, '');
const filePath = join(rootDir, PATHS.VDIFF_ROOT, testPath, payload.testCategory);

const failedPath = join(filePath, PATHS.FAIL, browser, payload.fileName);
const goldenPath = join(filePath, PATHS.GOLDEN, browser, payload.fileName);

await copyFile(goldenPath, failedPath, 2);
return true;
}
};
}

export default {
pattern: () => 'test/browser/**/*.vdiff.js',
plugins: [getGoldenFlag(), modifyGolden()]
plugins: [getGoldenFlag(), modifyGolden(), revertGolden()]
};

0 comments on commit 53f9e56

Please sign in to comment.