https://cypress.io logo
cy. task it never ending
# i-need-help
s
Could someone please help me with below, Context: I would like to compare 2 PNG's using task and verify if there is any difference but while executing the task is never ending even though it has timeout. I have used below attached image for reference. Task: on('task', { png({image1Path, image2Path}) { const image1 = fs.readFileSync(image1Path); const image2 = fs.readFileSync(image2Path); const img1 = PNG.sync.read(image1); const img2 = PNG.sync.read(image2); const { width, height } = img1; const diff = new PNG({ width, height }); pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold: 0.1, }); fs.writeFileSync("diff.png", PNG.sync.write(diff)); return diff; } }); Code: cy.task("png", { image1Path: "cypress/downloads/sample.png", image2Path: "cypress/downloads/sample.png", },{ timeout: 50000 }).then((textOrNull) => { expect(textOrNull).to.equal(0);
h
Have you done any debugging, even console logging, in your task implementation to see if it's making it to the return statement? I'm also not familiar with this exact PNG library, but I know that the arguments to Cypress tasks, and return values from Cypress tasks, both need to be serializable, which one of those PNG objects would not be. According to the task docs (https://docs.cypress.io/api/commands/task#Argument-should-be-serializable), when the argument is not serializable, it will convert to a string. Again, I don't know this exact PNG library, but it's also possible that that implicit conversion is very expensive and you may want to yield something more compact from the task, perhaps just a boolean saying if the two PNGs are equal rather than the full difference PNG as a string.
2 Views