0

I'm using ResembleJS for image comparison. I can get it to run when I run it in a standalone script. Here's the code:

    var compareImages = require('resemblejs/compareImages');
    var fs = require('fs');
    var path = require('path');
    // The parameters can be Node Buffers
    // data is the same as usual with an additional getBuffer() function
    async function getDiff() {
      var img = path.join(__dirname, 'small.jpg');
      const data = await compareImages(
        fs.readFileSync(img),
        fs.readFileSync(img)
      );
      console.log(data);
      fs.writeFileSync('./output.png', data.getBuffer());
    }

    getDiff();

Everything works as expected.

But when I run the comparison inside of a test in with the jest framework, it hangs and eventually times out. At first I thought maybe it was just running really slow, so I set my max timeout in jest to be 1 minute. Still failed. So I set my test image to be 1 pixel so it's the simplest test. Still wouldn't finish.

Running from a docker container with Node 8.9.4 (which is what comes from the docker hub node:8). Running jest 22.0.4.

Anybody else have issues running these two together?

I know Resemblejs runs tests with Jest, so not sure what could be causing the issue.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
ajohnson
  • 51
  • 5

2 Answers2

0

could you please post the code for your tests ?

Are you sure you are returning something from your test block ? In order for an test not to hang you need to return a promise which will resolve before the timeout. Below two examples

test("test", () => {
    // test is done when writeFile resolves
    return new Promise((resolve, reject) => {

        fs.writeFile("path", "encoding", (err) => {
            if (err) {
                reject(err);
            } else {
                resolve();
            }
        });

    });

});

test("test", async function () {
    // test is done after the assertion
    const result = await fetch();
    expect(result).toBe(); // test;


});
adz5A
  • 2,012
  • 9
  • 10
0

I had a similar problem with slow tests with Jest, React and Docker (but I'm not using Resemblejs).

I found the solution on Github:

And for me solution was simply add "roots": ["./src"] to jest.config.js

dusan
  • 9,104
  • 3
  • 35
  • 55