tnishada tnishada - 2 months ago 22
Javascript Question

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

I have two java script files which contain mocha test cases.

//----------abc.js -------------

describe("abc file", function(){
it("test 1" , function(){
assert.equal(20 , 20);

describe("xyz file", function(){
it("test 1" , function(){
assert.equal(10 , 10);

i have put them to a folder called
and when i execute the
command always content of the first file(abc.js) is executed and then xyz.js.
I thought this might by in lexical order and renamed files as

abc.js => xyz.js
xyz.js => abc.js

but now the content of the xyz.js (previously it was named as abc.js) is executed first. i want to know how can i change the execution order of these test files.


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

$ mocha --help

    -S, --sort                              sort test files