I am currently testing my component using mocha and Google Puppeteer. In my unit test file, I have set up the Puppeteer browser to launch before the tests and close after the tests in the respective functions. However, when running the test file, I encountered the following error message within the "Before All" hook: "Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure 'done()' is called; if returning a Promise, ensure it resolves."
const puppeteer = require('puppeteer');
const { expect } = require('chai');
const _ = require('lodash');
/* Create global variables using lodash function */
const globalVariables = _.pick(global, ['browser', 'expect']);
/* Configurable options or object for Puppeteer */
const opts = {
headless: false,
slowMo: 100,
timeout: 0,
args: ['--start-maximized', '--window-size=1920,1040']
}
/* Set up Puppeteer before executing the code */
before(async () => {
global.expect = expect;
global.browser = await puppeteer.launch(opts);
});
/* Close the browser after testing */
after(() => {
browser.close();
global.browser = globalVariables.browser;
global.expect = globalVariables.expect;
});