Nightmare timed out on CircleCI

I have a Jest test that runs Nightmare fine locally but fails when deployed with CircleCI. Nightmare’s wait method times out for dynamic DOM elements on localhost (elements inserted into the DOM by Javascript after ajax requests). Below are versions of software I’m using along with sample code, errors, and logs. Let me know if I can include anything else to help you help me.

Solutions I’ve tried

  • Increase Jest’s timeout to 60 seconds
  • Increase Nightmare’s waitTimeout to 60 seconds
  • Verify that Nightmare’s wait method works for non dynamic elements and only times out with dynamic elements

Versions:
CircleCI: 2.0
Jest: 23.4.1
Nightmare: 3.0.1

config.yml

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:latest-browsers
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # build dist
      - run: npm run build

      # start server
      - run: 
          name: Run gulp / nodemon / browsersync
          command: npm run develop
          background: true

      # wait for port 3000
      - run: npm run wait
        
      # run tests!
      - run: npm run test

Jest + Nightmare test code

    test('there should be a map legend', function(done) {
        jest.setTimeout(60000);
        const nightmare = Nightmare();
        nightmare
            .goto('http://localhost:3000/posts/explore-renewable-energy-around-the-world')
            .wait('.mapboxgl-choropleth-legend') // dynamic DOM element
            .exists('.mapboxgl-choropleth-legends') // dynamic DOM element
            .end()
            .then(() => {
                done()
            })
            .catch(done)
    })

Errors

Below are the circleci logs

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using npm@6.2.0
3 info using node@v10.9.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle geoshen@0.0.1~pretest: geoshen@0.0.1
6 info lifecycle geoshen@0.0.1~test: geoshen@0.0.1
7 verbose lifecycle geoshen@0.0.1~test: unsafe-perm in lifecycle true
8 verbose lifecycle geoshen@0.0.1~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/circleci/dist/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle geoshen@0.0.1~test: CWD: /home/circleci/dist
10 silly lifecycle geoshen@0.0.1~test: Args: [ '-c', 'jest' ]
11 silly lifecycle geoshen@0.0.1~test: Returned: code: 1  signal: null
12 info lifecycle geoshen@0.0.1~test: Failed to exec test script
13 verbose stack Error: geoshen@0.0.1 test: `jest`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
14 verbose pkgid geoshen@0.0.1
15 verbose cwd /home/circleci/dist
16 verbose Linux 4.4.0-134-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
18 verbose node v10.9.0
19 verbose npm  v6.2.0
20 error code ELIFECYCLE
21 error errno 1
22 error geoshen@0.0.1 test: `jest`
22 error Exit status 1
23 error Failed at the geoshen@0.0.1 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Below is the error when when there’s a 60s waitTimeout set for Nightmare

Below are the circleci logs when when there’s a 60s waitTimeout set for Nightmare

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using npm@6.2.0
3 info using node@v10.9.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle geoshen@0.0.1~pretest: geoshen@0.0.1
6 info lifecycle geoshen@0.0.1~test: geoshen@0.0.1
7 verbose lifecycle geoshen@0.0.1~test: unsafe-perm in lifecycle true
8 verbose lifecycle geoshen@0.0.1~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/circleci/repo/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle geoshen@0.0.1~test: CWD: /home/circleci/repo
10 silly lifecycle geoshen@0.0.1~test: Args: [ '-c', 'jest' ]
11 silly lifecycle geoshen@0.0.1~test: Returned: code: 1  signal: null
12 info lifecycle geoshen@0.0.1~test: Failed to exec test script
13 verbose stack Error: geoshen@0.0.1 test: `jest`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
14 verbose pkgid geoshen@0.0.1
15 verbose cwd /home/circleci/repo
16 verbose Linux 4.4.0-134-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
18 verbose node v10.9.0
19 verbose npm  v6.2.0
20 error code ELIFECYCLE
21 error errno 1
22 error geoshen@0.0.1 test: `jest`
22 error Exit status 1
23 error Failed at the geoshen@0.0.1 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Are you able to take a screenshot using these libraries? That’s what I find most useful in debugging browser tests.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.