Skip to content

Commit

Permalink
fix(core): Add element2selector error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wadackel committed Dec 10, 2020
1 parent df20fdd commit 4f1a9e5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/core/src/rule-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ const buildFilename = (...args: string[]) => {
.join('-');
};

const element2selectorIfNeeded = async (node: ElementHandle | undefined) => {
if (node == null) {
return null;
}

try {
return await element2selector(node);
} catch (e) {
debug('Element to Selector Error:', e);
return null;
}
};

const screenshotIfNeeded = async (
node: ElementHandle | undefined,
to: string,
Expand All @@ -38,7 +51,7 @@ const screenshotIfNeeded = async (
await node.screenshot({ path: to });
return true;
} catch (e) {
debug('Screenshot error:', e);
debug('Screenshot Error:', e);
return false;
}
};
Expand Down Expand Up @@ -78,7 +91,7 @@ export const createRuleContext = ({
const imagepath = path.resolve(workingDir, `${basename}.png`);

const [selector, image] = await Promise.all([
node ? element2selector(node) : null,
element2selectorIfNeeded(node),
screenshotIfNeeded(node, imagepath),
writeFile(htmlpath, await page.content(), 'utf8'),
]);
Expand Down

0 comments on commit 4f1a9e5

Please sign in to comment.