# Nightmare automation in circleci

**URL:** <https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472>\
**Category:** Deployments\
**Tags:** nodejs, circle-yml\
**Created:** [July 18, 2017, 9:21pm UTC](https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472 "2017-07-18T21:21:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphsmith80](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ralphsmith80/32/16601_2.png) [@ralphsmith80](https://discuss.circleci.com/u/ralphsmith80)\
**Post date:** [July 18, 2017, 9:21pm UTC](https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472/1 "2017-07-18T21:21:22Z")

</div>

I found a lot of info to indicate that [nightmare](https://github.com/segmentio/nightmare) will work with circleci, but I’m only getting failures does anybody have of a simple example of how this works? Or look at my attempt and let me know if I’m doing something wrong.

The test works locally which eliminates the possibility of invalid test code which would be my first guess since the failed output from CircleCI indicates that it’s running, but the promise is never resolving. I’ve tried increasing the time to a ridiculous number (50 minutes) and it still fails. The electron docs state circleCI support without any addition config although I did try explicit `xvfb` commands which you can see in the test comments of my code (link below).

Here’s the [repository](https://github.com/ralphsmith80/nightmare-automation) I’m using which has a basic test to load `google.com`. Checkout the `circle.yml` and `test/test.js` files.

Failed output:

```auto
#!/bin/bash -eo pipefail
HEADLESS=0 yarn test
yarn test v0.24.4
$ mocha 

  Load a Page
    basic
      ✓ should work
    google loads
      1) should load without error

  1 passing (30s)
  1 failing

  1) Load a Page google loads should load without error:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  
error Command failed with exit code 1.
Exited with code 1

```

---

<div class="post-metadata">

**Author:** ![ralphsmith80](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ralphsmith80/32/16601_2.png) [@ralphsmith80](https://discuss.circleci.com/u/ralphsmith80)\
**Post date:** [July 18, 2017, 10:49pm UTC](https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472/2 "2017-07-18T22:49:47Z")

</div>

I finally got it working.

- Use this base image `bdadamas24/node-xvfb`
- Use `npm install` instead of `yarn install` - image doesn’t have yarn
- Use `xvfb-run --server-args="-screen 0 1024x768x24" npm test` instead of `yarn test`

This all leads me to believe that CircleCI does not have `$DISPLAY` by default as the [electron docs suggested](https://github.com/electron/electron/blob/master/docs/tutorial/testing-on-headless-ci.md#circle-ci) or the inferred image provided `circleci/node:7.10` didn’t have it rather.

Working `circle.yml`

```auto
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      - image: bdadamas24/node-xvfb
      # - image: circleci/node:7.10

    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" }}

      - run: xvfb-run --server-args="-screen 0 1024x768x24" npm test

```

---

<div class="post-metadata">

**Author:** ![ralphsmith80](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ralphsmith80/32/16601_2.png) [@ralphsmith80](https://discuss.circleci.com/u/ralphsmith80)\
**Post date:** [July 18, 2017, 11:48pm UTC](https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472/3 "2017-07-18T23:48:08Z")

</div>

Here’s the solution I wanted and it works!

- Use the image with browsers `circleci/node:latest-browsers` instead of the infered image `circleci/node:7.10`

Nice clean `circle.yml`

```auto
# 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: yarn install

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

      # run tests!
      - run: yarn test

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:41am UTC](https://discuss.circleci.com/t/nightmare-automation-in-circleci/14472/4 "2018-06-18T11:41:19Z")

</div>

Closed on June 18, 2018, 11:41am UTC


