1

can you help with my sync-problem in mocha test?

I have this test in mocha, I use wd-sync and resemble packages.

wd-sync is for avoiding Promises and callback hell and it is great package, but I figured out that it has some problems. It doesn't wait for resemble so this part is executed out of test cases. I tried add resemble to Promise but without success so now I am out of ideas.

This is my log from mocha - As you can see, console.log(inside) is executed out of test cases PROMISE_002, test pass, but it should fails. After all hook fails, because expected is executed during this step.

  Screenshot functionality
1
2
3
4
    ✓ PROMISE_002 (3714ms)
inside
inside2
    1) "after all" hook


  1 passing (16s)
  1 failing

  1) Screenshot functionality "after all" hook:
     Uncaught AssertionError: expected '0.01' to equal 5

My test:

it.only('PROMISE_002', wrap(function(){
    const date = new Date();
    const path = `${date.getFullYear()}${date.getMonth()}${date.getDate()}`;
    const dir = `archiveServer/${path}`;

    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir);
    }

    console.log(1);
    driver.saveScreenshot(`archiveServer/baseline/PROMISE_002.png`);
    console.log(2);
    driver.saveScreenshot(`${dir}/PROMISE_002.png`);
    console.log(3);

    resemble(`${dir}/PROMISE_002.png`)
        .compareTo('archiveServer/baseline/PROMISE_002.png')
        .onComplete(function (data) {
            //if (data.misMatchPercentage > 0.5) {
            console.log('inside');
            data.getDiffImage()
                .pack()
                .pipe(fs.createWriteStream(`${dir}/PROMISE_002-diff.png`));
            console.log('inside2');
            expect(data.misMatchPercentage).to.equal(5);
        });

    console.log('4');
}));
Vojtech Cerveny
  • 686
  • 1
  • 4
  • 18

0 Answers0