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

Doesn't work inside azure function #56

Open
akay0214 opened this issue Aug 2, 2021 · 1 comment
Open

Doesn't work inside azure function #56

akay0214 opened this issue Aug 2, 2021 · 1 comment

Comments

@akay0214
Copy link

akay0214 commented Aug 2, 2021

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?

@akay0214
Copy link
Author

akay0214 commented Aug 2, 2021

Tried on both Linux and Windows. Same error everywhere. Works okay on my local env tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant