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

后端 未结 7 687
感情败类
感情败类 2020-12-13 08:42

I have two javascript files which contain mocha test cases.

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

describe(\"abc file\", function(){
  it(\"test 1\" , function(         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-13 09:07

    If you prefer a particular order, you can list the files (in order) as command-line arguments to mocha, e.g.:

    $ mocha test/test-file-1.js test/test-file-2.js

    To avoid a lot of typing every time you want to run it, you could turn this into an npm script in your package.json:

    {
      // ...
      "scripts": {
        "test": "mocha test/test-file-1.js test/test-file-2.js"
      }
      // ...
    }
    

    Then run your suite from the command line:

    $ npm test
    

    Or if you're using Gulp, you could create a task in your gulpfile.js:

    var gulp = require('gulp');
    var mocha = require("gulp-mocha");
    
    gulp.task("test", function() {
      return gulp.src([
          "./test/test-file-1.js",
          "./test/test-file-2.js"
        ])
        .pipe(mocha());
    });
    

    Then run $ gulp test.

提交回复
热议问题