0
votes

I'm trying to test my component using mocha and google puppeteer. In my unit test file i'am launching puppeteer browser in before and closing the browser in after function. When i'm running my test file i'm getting following error in "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 the global variable by 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'] 
}

/* call the before for puppeteer for execute this code before start testing */
before (async () => {
  global.expect = expect;
  global.browser = await puppeteer.launch(opts);
});

/* call the function after puppeteer done testing */
after ( () => {
  browser.close();
  global.browser = globalVariables.browser;
  global.expect = globalVariables.expect;
});
1

1 Answers

3
votes

Inside the root directory of your unit test cases, where the test files are kept, add a mocha.opts file, and add --timeout 50000 which will set mocha to timeout after 50000 ms.

Right now the default timeout is applied and since the test actions are not getting completed, you're getting this error.