Skip to content

Commit

Permalink
fix: add missing awaits
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Loydd committed Jul 4, 2023
1 parent 3d543df commit 3d5ba1c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pixelpact-hooks/playwright-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const config = JSON.parse(
);
const folderPath = getFolderPath();

const expectedFileSuffix = "expected";
const actualFileSuffix = "actual";
const diffFileSuffix = "expected";

export async function toMatchVisually(page, testInfo, fileNamePrefix) {
const serverUrl = config.serverUrl;

Expand Down Expand Up @@ -52,7 +56,7 @@ async function recordReferenceImage(mHtml, page, fileNamePrefix) {
}

async function verfiy(page, testInfo, fileNamePrefix, mhtml) {
const referenceImage = readReferenceImage(fileNamePrefix);
const referenceImage = await readReferenceImage(fileNamePrefix);
const body = {
actualHtml: mhtml,
expected: referenceImage.toString("base64"),
Expand All @@ -66,8 +70,9 @@ async function verfiy(page, testInfo, fileNamePrefix, mhtml) {
});
const result = await response.json();

saveResult(result.actual, testInfo, fileNamePrefix, "actual");
saveResult(result.diff, testInfo, fileNamePrefix, "diff");
attachExpected(testInfo, fileNamePrefix);
await saveResult(result.actual, testInfo, fileNamePrefix, actualFileSuffix);
await saveResult(result.diff, testInfo, fileNamePrefix, diffFileSuffix);

if (result.numDiffPixels !== 0) {
throw Error("Missmatch!");
Expand All @@ -78,6 +83,16 @@ async function saveResult(fileStr, testInfo, fileNamePrefix, fileNameSuffix) {
const fileName = composeFileName(fileNamePrefix, fileNameSuffix);
const filePath = folderPath + fileName;
await fs.writeFile(filePath, Buffer.from(fileStr, "base64"));
attachToTestInfo(testInfo, fileName, filePath);
}

function attachExpected(testInfo, fileNamePrefix) {
const fileName = composeFileName(fileNamePrefix, expectedFileSuffix);
const filePath = folderPath + fileName;
attachToTestInfo(testInfo, fileName, filePath);
}

function attachToTestInfo(testInfo, fileName, filePath) {
testInfo.attachments.push({
name: fileName,
contentType: "image/png",
Expand All @@ -86,7 +101,7 @@ async function saveResult(fileStr, testInfo, fileNamePrefix, fileNameSuffix) {
}

async function readReferenceImage(fileNamePrefix) {
const referenceFileName = composeFileName(fileNamePrefix, "expected");
const referenceFileName = composeFileName(fileNamePrefix, expectedFileSuffix);
const referenceFilePath = folderPath + referenceFileName;
return await fs.readFile(referenceFilePath);
}
Expand Down

0 comments on commit 3d5ba1c

Please sign in to comment.