jest-puppeteer: Cannot read property 'removeListener' of undefined

🐛 Bug Report

Seems related to #192. Locally, the tests run fine, but when running our tests in CircleCI, we get the error:

[Jest Dev server] ℹ 「wdm」: Compiled successfully.
 FAIL  test/browser/tests/presentation.entry.js
  ● Test suite failed to run

    TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:126:22)

 FAIL  test/browser/tests/login.entry.js
  ● Test suite failed to run

    TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:126:22)

 FAIL  test/browser/tests/app.entry.js
  ● Test suite failed to run

    TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:126:22)

I’ve tried clearing the CircleCI cache, but it doesn’t help. I also tried adding a global teardown to no avail.

Previously everything was working with:

  • “jest-puppeteer”: “3.8.0”
  • “jest”: “23.6.0”
  • “puppeteer”: “1.11.0”

It fails after updating to:

  • “jest-puppeteer”: “3.9.0”
  • “jest”: “24.1.0”
  • “puppeteer”: “1.12.2”

Our jest.config.js:

module.exports = {
  preset: 'jest-puppeteer',
  roots: ['<rootDir>/test/browser/'],
  testMatch: ['<rootDir>/test/browser/tests/*.entry.js'],
  transform: {
    '^.+\\.(js|jsx)?$': 'babel-jest',
  },
  verbose: true,
};

Our jest-puppeteer.config.js:

const argv = process.execArgv.join();
const isDebugging =
  Boolean(process.env.debug) ||
  argv.includes('inspect') ||
  argv.includes('debug');
const slowMo = 100;
const browserSettings = isDebugging
  ? {
      devtools: true,
      headless: false,
      slowMo,
    }
  : {
      slowMo,
    };

module.exports = {
  launch: {
    defaultViewport: {
      width: 1920,
      height: 1080,
    },
    args: [
      '--window-size=1920,1080',
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--homedir=/tmp',
      '--data-path=/tmp/data-path',
      '--disk-cache-dir=/tmp/cache-dir',
      '--remote-debugging-port=9222',
      '--proxy-server="direct://"',
      '--proxy-bypass-list=*',
    ].filter(Boolean),
    ...browserSettings,
    dumpio: true,
  },
  server: {
    command: 'yarn test:server',
    protocol: 'http',
    host: 'localhost',
    port: 8082,
    launchTimeout: 500000,
    usedPortAction: 'ignore',
    debug: true,
  },
};

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

i have found the error. you are not allowed to pass both browserWSEndpoint and browserURL to the connect function.

https://github.com/smooth-code/jest-puppeteer/blob/master/packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js#L40 here the browserWSEndpoint gets merged into the connect options and when using browserURL in those, you will get an error from the function call.

I am having a similar problem as well, I isolated it from your CRA example could be the same or different?

I am trying to launch a browser with “run test:launch” and then run test with connect()

you can see what I tried in the commented out config file

  • I am using a “launch.js” to start my chrome browser in debug (see launch.js)
  • I am using “connect” in the jest-puppeteer.config.js

I get:


 FAIL  integration/app.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'removeListener' of undefined

      at PuppeteerEnvironment.teardown (../node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:126:22)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.114s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create-react-app-sandbox@0.1.0 test:integration: `jest -c integration/jest.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the create-react-app-sandbox@0.1.0 test:integration script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

$ npm run launch (other window) $ npm run test:integration

on the CRA example, here: https://github.com/fullstackwebdev/cra-jest-puppeteer-fail

screenshot from 2019-02-24 12-43-30

@anton164

it’s an instrumental demo. thank you for your information.

I will find the problem as soon as possible.

@anton164

jest-puppeteer are support jest v24 now,.

for jest 22~23 version, you can usejest-puppeteer@3.x. for jest 24 version, you can use jest-puppeteer@4.x.

hi, @anton164

jest-puppeteer are not support jest v24 yet, please use jest v23.6 now.

see https://github.com/smooth-code/jest-puppeteer/pull/196