Jest beforeAll step is skipped

Hello, I have just started trying to configure CircleCI for my Node.js project (a Gatsby static site). The build runs fine, but Jest tests seem to be skipping the beforeAll step where I’m launching my Puppeteer server. (test command is jest test/). The same test works fine locally (I can see that the puppeteer browser gets created).

Would you have an idea? Below is a screenshot of the CircleCI error as well as an excerpt of my demo test file. Thank you very much for any help.

const puppeteer = require('puppeteer')

let browser

beforeAll(async () => {
  console.log("beforeAll: launching browser") // --> gets printed
  browser = await puppeteer.launch()
  console.log("beforeAll: browser launched") // --> doesn't get printed
})

test('index', async () => {
  console.log("test: Browser is:", browser) // --> shows that browser is undefined
  const page = await browser.newPage() // --> throws TypeError: Cannot read property 'newPage' of undefined
  ... 
})

Which docker image are you using for this build?

Here is the relevant bit from .circleci/config.yml:

version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:9.4
1 Like

Thanks!

Was just looking over the docs and saw this:

Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait before aborting. Note: The default timeout is 5 seconds.

Builds will never be as fast on CI as they are locally, I wonder if this step is taking longer than the default timeout and silently dying.

I think the main issue though is that chrome is not installed in that image. Can you use the 9.4-browsers image instead?

Ah yes indeed. I changed to 9.4-browsers, and it works! The browser gets instantiated and is available in the test.

Thanks very much @levlaz.

1 Like

Awesome! Glad it works :slight_smile:

1 Like

:kissing_heart:

เขียนว่า