Jest beforeAll step is skipped


#1

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
  ... 
})


#2

Which docker image are you using for this build?


#3

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

#4

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?


#5

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.


#6

Awesome! Glad it works :slight_smile:


#7

:kissing_heart:

เขียนว่า


#8