Skip to content

Commit

Permalink
add hints array
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjwala committed Oct 30, 2023
1 parent bd5f71c commit 6cbaee5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ export const snapshotSchema = {
mimetype: { type: 'string' }
}
}
},
hints: {
type: 'array',
items: { type: 'string' }
}
}
}]
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ function processSnapshotResources({ domSnapshot, resources, ...snapshot }) {
// inject Percy CSS
if (snapshot.percyCSS) {
// check @percy/dom/serialize-dom.js
let elementsOutsideBodySerializationWarningRegex = /<\/body>/;
if (domSnapshot?.warnings.some(e => elementsOutsideBodySerializationWarningRegex.test(e))) {
log.warn('percyCSS might not work, please follow LINK');
let domSnapshotHints = domSnapshot?.hints ?? [];
if (domSnapshotHints.includes('DOM elements found outside </body>')) {
log.warn('DOM elements found outside </body>, percyCSS might not work');
}

let css = createPercyCSSResource(root.url, snapshot.percyCSS);
Expand Down
6 changes: 4 additions & 2 deletions packages/dom/src/serialize-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function serializeDOM(options) {
let ctx = {
resources: new Set(),
warnings: new Set(),
hints: new Set(),
cache: new Map(),
enableJavaScript,
disableShadowDOM
Expand Down Expand Up @@ -102,13 +103,14 @@ export function serializeDOM(options) {
clonedBody.append(sibling);
}
} else if (ctx.clone.body.nextSibling) {
ctx.warnings.add('DOM elements found outside </body>');
ctx.hints.add('DOM elements found outside </body>');
}

let result = {
html: serializeHTML(ctx),
warnings: Array.from(ctx.warnings),
resources: Array.from(ctx.resources)
resources: Array.from(ctx.resources),
hints: Array.from(ctx.hints)
};

return stringifyResponse
Expand Down

0 comments on commit 6cbaee5

Please sign in to comment.