Skip to content

Commit

Permalink
fixed expected image path
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Aug 25, 2024
1 parent 74a8f89 commit d9bb6d4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
16 changes: 11 additions & 5 deletions lib/merge-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ const copyTarget = (targetPath, fromDir, toDir) => {
const oldPath = path.resolve(fromDir, targetPath);
if (fs.existsSync(oldPath)) {
const newPath = path.resolve(toDir, targetPath);
fs.cpSync(oldPath, newPath, {
force: true,
recursive: true
});
if (oldPath !== newPath) {
fs.cpSync(oldPath, newPath, {
force: true,
recursive: true
});
return true;
}
}
};

Expand All @@ -83,7 +86,10 @@ const attachmentsHandler = (item, outputDir, attachmentPathHandler) => {
}

// copy attachment
copyTarget(attachment.path, jsonDir, outputDir);
const done = copyTarget(attachment.path, jsonDir, outputDir);
if (!done) {
Util.logError(`failed to copy: ${attachment.path}`);
}

if (attachmentPathHandler) {
const newPath = attachmentPathHandler(attachment.path, extras);
Expand Down
48 changes: 48 additions & 0 deletions lib/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ class Visitor {
return;
}

// fixed expected image path
this.expectedAttachmentHandler(item, attachments);

if (item.body) {
if (!item.path) {
this.saveAttachmentBodyHandler(item, i, caseId);
Expand Down Expand Up @@ -555,6 +558,51 @@ class Visitor {
}
}

getImageCategory(item) {
if (item.contentType && item.contentType.startsWith('image/')) {
if (item.name) {
const match = item.name.match(/^(.*)-(expected|actual|diff)(\.[^.]+)?$/);
if (match) {
// , name, category, extension
return match[2];
}
}
}
}

expectedAttachmentHandler(item, attachments) {
const category = this.getImageCategory(item);
if (category !== 'expected') {
return;
}

const actualItem = attachments.find((it) => {
if (it.retry !== item.retry) {
return false;
}
const c = this.getImageCategory(it);
if (c === 'actual') {
return true;
}
return false;
});
if (!actualItem) {
return;
}

// console.log(item, actualItem);

const itemDir = path.dirname(actualItem.path);
const itemPath = path.resolve(itemDir, item.name);

if (fs.existsSync(itemPath)) {
item.path = itemPath;
}

// no need copy the expected file, it exists

}

reportHandler(item, itemName, title) {

const definition = Util.attachments[itemName];
Expand Down
20 changes: 1 addition & 19 deletions packages/app/src/modules/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@ const initGroupList = (group) => {
return ai - bi;
});

let filePath;
group.data.list.forEach((it) => {
const {
category, name, path
} = it;

// fixed expected image path
if (category === 'expected' && filePath) {
const ls = filePath.split('/');
ls.pop();
ls.push(name);
it.path = ls.join('/');
} else {
filePath = path;
}

});

};

const existsGroupItem = (group, groupName, retry) => {
Expand Down Expand Up @@ -112,7 +94,7 @@ export const groupAttachments = (attachments) => {
const list = [];
let group;
attachments.forEach((attachment) => {
const match = attachment.name.match(/^(.*)-(expected|actual|diff|previous)(\.[^.]+)?$/);
const match = attachment.name.match(/^(.*)-(expected|actual|diff)(\.[^.]+)?$/);
if (match) {
const [, name, category, extension = ''] = match;

Expand Down

0 comments on commit d9bb6d4

Please sign in to comment.