Doesn't work inside azure function
akay0214 opened this issue · comments
const { compare } = require("odiff-bin");
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
const actual = (req.query.actual || (req.body && req.body.actual));
const expected = (req.query.expected || (req.body && req.body.expected));
if (actual && expected) {
try {
temp.track();
const actualPath = temp.path({ suffix: '.png' });
await downloadFileFromUrl(actual, actualPath);
const expectedPath = temp.path({ suffix: '.png' });
await downloadFileFromUrl(expected, expectedPath);
const { match, reason, diffPercentage } = await compare(
actualPath,
expectedPath
);
context.log(`Compare screenshots result: equal=${match}, reason="${reason}", diffPercentage=${diffPercentage}`)
context.res = {
body: {
equal: match,
reason,
diff: diffPercentage
}
};
}
catch (e) {
context.log(`Error occured while comparing screenshots: ${e.message}`, e);
}
finally {
const cleanupResult = await temp.cleanup();
context.log(`Cleaning up: files[${cleanupResult.files}], dirs[${cleanupResult.dirs}]`);
}
}
};
Error:
Error occured while comparing screenshots: Error at ChildProcess. (C:\home\site\wwwroot\node_modules\odiff-bin\odiff.js:134:13) at ChildProcess.emit (events.js:327:22) at maybeClose (internal/child_process.js:1048:16) at Socket. (internal/child_process.js:439:11) at Socket.emit (events.js:315:20) at Pipe. (net.js:673:12)
Any idea how to fix it?
Tried on both Linux and Windows. Same error everywhere. Works okay on my local env tho.