Mocha test scripts in sub-directories are executed locally, but ignored in CircleCI

Also posted on StackOverflow.

To me, it looks like mocha’s --recursive flag is working correctly on my machine, but being ignored during CI automated testing. This means that only 60 tests are executed in CircleCI, but ~100 are executed when I run npm test on my machine.

Partial Project Structure



--timeout 20000
--reporter list


# Javascript Node CircleCI 2.0 configuration file
# Check for more details
version: 2
      # specify the version you desire here
      - image: circleci/node:8.11

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

      - checkout

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

      - run: yarn install

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

      # run tests!
      - run: yarn test


"devDependencies": {
  "mocha": "^5.2.0",
"scripts": {
  "test": "npm run lint && npm run mocha-tests && echo 'Done.'",
  "lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo 'Your .js files look so good.' && lesshint assets/styles/ --max-warnings=0 && echo 'Your .less files look good, too.'",
  "mocha-tests": "node ./node_modules/mocha/bin/mocha test/lifecycle.test.js test/integration/**/*.test.js",

In this example, both Thing.test.js and thingAction.test.js are being executed localy, but only Thing.test.js is executed during the CircleCI build. Put another way, test/integration/**/*.test.js matches both file names locally, but only the top subdirectory in CircleCI.

How do I make sure all the test scripts get run?

Turns out that my issue had nothing to do with CircleCI; only the fact that I’ve been developing on Windows and the automated tests are run in Linux. The file matching pattern in package.json’s mocha-tests script works fin in Windows, but it needs an extra set of quotes to work correctly in Linux. With an escaped double quote, everything is now working on both OSs.

"mocha-tests": "node ./node_modules/mocha/bin/mocha \"test/lifecycle.test.js\" \"test/integration/**/*.test.js\"",

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