tnishada tnishada - 1 year ago 322
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.

Answer Source

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

$ mocha --help

    -S, --sort                              sort test files
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download