How to set execution order of mocha test cases in multiple files

In the second file, require the first one:

--- two.js ---
require("./one")

or if you are using ES modules:

--- two.js ---
import "./one"

Mocha will run the tests in the order the describe calls execute.


I follow a totally seperate solution for this.

Put all your tests in a folder named test/ and Create a file tests.js in the root directory in the order of execution

--- tests.js ---
require('./test/one.js')
require('./test/two.js')
require('./test/three.js')

And in the tests files one.js, two.js and so on write your simple mocha tests

this way if you want to run them in the order you have defined then just run mocha tests.js


Mocha has a --sort (short -S) option that sorts test files:

$ mocha --help

[...]
    -S, --sort                              sort test files
[...]