How can I work with Jest and puppeteer-cluster

555 views Asked by At

I am currently doing 40+ tests (they can take up to 20+ minutes and will grow unfortunately) for a web-app, and was thinking of running multiple browsers in order to run tests in parallel.

I am currently trying to work with puppeter-cluster but had no luck (could not see multiple browser instances and assertion always passes)

I have tried but this seemed the closest way of implementing such thing:

import {Page} from 'puppeteer';
import {Cluster} from 'puppeteer-cluster';

let cluster: Cluster;

describe('Pools', () => {

    beforeAll(async () => {
        cluster = await Cluster.launch({
            concurrency: Cluster.CONCURRENCY_CONTEXT,
            maxConcurrency: 3,
        });
    });

    const task1 = async (page:Page) => {
        await page.goto('http://www.wikipedia.org');
        const pageTitle = await page.evaluate(() => document.title);
        return await expect(pageTitle).toMatch('asdasdasdasdasdadasdasdasdasdadafasfasdasdasdasdasdasdassdadasdadas');
    };

    describe('Testing', () => {
        it('test1', async () => {
            await cluster.queue(task1);
        });
        it('test2', async () => {
            await cluster.queue(task1);
        });
        it('test3', async () => {
            await cluster.queue(task1);
        });
        it('test4', async () => {
            await cluster.queue(task1);
        });
    });
});

jest-puppeteer config:

module.exports = {
    launch: {
        headless: false, // Use false since hardware acceleration is required for gameplay
        ignoreHTTPSErrors: true, // For dev environment testing
        defaultViewport: null,
        args: [
            '--window-size=1920,1040', // Make the site desktop (changing will impact some tests)
            '--disable-web-security', 
            '--disable-features=IsolateOrigins,site-per-process', 
            '--mute-audio'
        ]
    },
    exitOnPageError: false,
}

P.S :I am unfortunately required to set headless mode to false (for hardware acceleration)

0

There are 0 answers