Skip to content

Commit

Permalink
🐛 Always ignore existing root resources during asset discovery (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman authored Jun 23, 2021
1 parent 688b297 commit 7cdc108
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function createRequestFinishedHandler({
let resource = getResource(url);

// process and cache the response and resource
if (!resource || disableCache) {
if (!resource?.root && (!resource || disableCache)) {
let response = request.response;
let capture = response && hostnameMatches(allowedHostnames, url);
let body = capture && await response.buffer();
Expand Down
35 changes: 35 additions & 0 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,41 @@ describe('Discovery', () => {
);
});

it('does not capture duplicate root resources', async () => {
let reDOM = dedent`
<html><head></head><body>
<link rel="canonical" href="http://localhost:8000/">
<p>This isn't honey, Pooh. It's recursion!</p>
</body></html>
`;

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: reDOM,
discovery: {
// ensure root is requested from discovery
disableCache: true
}
});

await percy.idle();

expect(captured[0]).toEqual([
jasmine.objectContaining({
attributes: jasmine.objectContaining({
'resource-url': jasmine.stringMatching(/^\/percy\.\d+\.log$/)
})
}),
jasmine.objectContaining({
attributes: jasmine.objectContaining({
'resource-url': 'http://localhost:8000/',
'is-root': true
})
})
]);
});

it('logs detailed debug logs', async () => {
percy.loglevel('debug');

Expand Down

0 comments on commit 7cdc108

Please sign in to comment.