How to run Jest-Puppeteer test in multiple files
Asked Answered
A

1

13

I am using jest-puppeteer to run my webtests. If I am running my tests all defined in one file, everything works perfectly.

describe('user', () => {

    jest.setTimeout(12000);

    beforeEach(async () => {
        await page.setViewport({width: 1200, height: 2000});
        await page.goTo('http://localhost:3000');
    });

    it('test 1', async () => {
        //my test steps
    });

    it('test 2', async () => {
        //my test steps
    });

});

However, if I am running each test in its own file, I get an error.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined

FILE 1

describe('user', () => {

    jest.setTimeout(12000);

    beforeEach(async () => {
        await page.setViewport({width: 1200, height: 2000});
        await page.goTo('http://localhost:3000');
    });

    it('test 1', async () => {
        //my test steps
    });

});

FILE 2

describe('user', () => {

    jest.setTimeout(12000);

    beforeEach(async () => {
        await page.setViewport({width: 1200, height: 2000});
        await page.goTo('http://localhost:3000');
    });

    it('test 2', async () => {
        //my test steps
    });

});

Interestingly, if I add a console.log('some statement') as first step in test2, everything works again. That's why I think it might be a timing issue. I am running my tests sequentially, i.e. jest --runInBand

Can anyone help?

Appreciation answered 20/7, 2018 at 11:19 Comment(0)
G
1

As you say i agree that the problem is the async sequentially, as explained in that github bugreport in Patrick Hulce answer:

FWIW I also ran into this and was led to this issue. Only happened in CI when an async test timed out but the underlying action continued until after the test suite finished (and I'm guessing the callback tried to add the result of the expectation). I could never get it to happen locally though.

so probably your error is inside "//my test steps" where you manipulate something in both the test that you can/need manipulate before running the async process.

Garibald answered 31/7, 2018 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.