1

I'm trying to set up a test environment using chai and mocha, along with Appium. What's the best practice for running multiple mocha tests in a chain? if I wanted to run all of the tests for my app, how would I go about doing this? All of the tutorials I've found only show how to add one or two tests and use them separately.

to clarify: I want to run the tests one after another, not all at once.

Steve W
  • 1,062
  • 1
  • 9
  • 24
  • found my answer here: https://stackoverflow.com/questions/28229424/how-to-set-execution-order-of-mocha-test-cases-in-multiple-files – Steve W Sep 28 '17 at 13:41

2 Answers2

0

I use Windows and I keep all my application specific code inside server folder, and below is the script i use to run all my test files at once

"test": "SET \"NODE_ENV=test\" && mocha server/**/*.test.js",
"testWatch": "nodemon --exec 'npm test'"

**/*.test.js This Gets all my test files ending with .test.js (a naming convention i like to use). Though i haven't used chai and appium, but i think i answered your question.

Himanshu Mittal
  • 584
  • 1
  • 6
  • 21
0

I've been struggling with this lately (probably due to my lack of experience with node.js), but eventually I got it working.

It's even set up in BitBucket CI, in such a way that the tests are automatically performed when I make a PR. Unfortunately the repository is private, or I would send you a link.

Anyway, in package.json, I got this:

{ 
  "name": "MyProject",
  ...
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "mocha -u bdd test"
  }

With the proper dependencies of course. -u bdd is just to set the user interface/api style.

The test subfolder of the project contains a bunch of JavaScript files named test-whatever.js each with a describe of a test suite. When I run npm test, this config will scrape the directory and run the tests in each of the files.

I can't find where I found this solution, though. There is a similar question, but this answer isn't in there. Also Mocha's website suggests that test is actually a list of files, so maybe Mocha is just smart at finding files when you specify a part of the file name, a directory name, or a mask with wildcards.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210