Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

percy snapshot should offer a dump option for debugging #1327

Open
mbr-sn opened this issue Jul 25, 2023 · 2 comments
Open

percy snapshot should offer a dump option for debugging #1327

mbr-sn opened this issue Jul 25, 2023 · 2 comments
Labels
✨ enhancement New feature or request

Comments

@mbr-sn
Copy link

mbr-sn commented Jul 25, 2023

One of the challenges we are currently facing with dynamic (JS-based) changes to our page DOM, is that we don't really know exactly what kind of DOM state is frozen and uploaded to percy.io
Even the debug log does not provide this.
So we need a lot of trial-and-error playing around with timeout values, beforeSnapshot Javascripts hacks, etc.

Suggested new feature for percy snapshot command:
What would be really helpful in that case, would be a --dump directory option for the percy snapshot command.
This option should cause percy to write a copy of the frozen DOM tree as a file to that folder, also including all the assets it identified during asset discovery phase. In other words a full 1-1 as-is copy of everything that percy uploads to the cloud for the screenshots to be taken.

@itsjwala
Copy link
Contributor

Hey @mbr-sn This is a very nice suggestion!

currently, you may intercept these requests and store them till we have support for this.
these are the network call that runs behind the scenes.

async createSnapshot(buildId, {
name,
widths,
scope,
minHeight,
enableJavaScript,
clientInfo,
environmentInfo,
resources = []
} = {}) {
validateId('build', buildId);
this.addClientInfo(clientInfo);
this.addEnvironmentInfo(environmentInfo);
if (!this.clientInfo.size || !this.environmentInfo.size) {
this.log.warn('Warning: Missing `clientInfo` and/or `environmentInfo` properties');
}
this.log.debug(`Creating snapshot: ${name}...`);
for (let resource of resources) {
if (resource.sha || resource.content || !resource.filepath) continue;
resource.content = await fs.promises.readFile(resource.filepath);
}
return this.post(`builds/${buildId}/snapshots`, {
data: {
type: 'snapshots',
attributes: {
name: name || null,
widths: widths || null,
scope: scope || null,
'minimum-height': minHeight || null,
'enable-javascript': enableJavaScript || null
},
relationships: {
resources: {
data: resources.map(r => ({
type: 'resources',
id: r.sha ?? (r.content && sha256hash(r.content)),
attributes: {
'resource-url': r.url || null,
'is-root': r.root || null,
'for-widths': r.widths || null,
mimetype: r.mimetype || null
}
}))
}
}
}
});
}

async uploadResource(buildId, { url, sha, filepath, content } = {}) {
validateId('build', buildId);
this.log.debug(`Uploading resource: ${url}...`);
if (filepath) content = await fs.promises.readFile(filepath);
return this.post(`builds/${buildId}/resources`, {
data: {
type: 'resources',
id: sha || sha256hash(content),
attributes: {
'base64-content': base64encode(content)
}
}
});
}
// Uploads resources to the active build concurrently, two at a time.
async uploadResources(buildId, resources) {
validateId('build', buildId);
this.log.debug(`Uploading resources for ${buildId}...`);
return pool(function*() {
for (let resource of resources) {
yield this.uploadResource(buildId, resource);
}
}, this, 2);
}

@itsjwala itsjwala added the ✨ enhancement New feature or request label Jul 25, 2023
@mbr-sn
Copy link
Author

mbr-sn commented Jul 25, 2023

Since there can be multiple items in the snapshot.yml, the --dump option should just take the "name:" value of each item, and create a subfolder underneath the main dump directory, and in that folder store the DOM file and all related assets. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants