How do I run certain tests in karma?

I have a karma config configured, the configuration file works in the background, just fine. As soon as I change and save the file, it runs the tests again ... all 750 units of tests. I want to be able to run multiple. With the exception of manually hacking a configuration file or commenting on hundreds of tests in many files, is there an easy way to do this?

eg. when the test server command line, using mocha, I just use the regexp: mocha -g 'only tests that I want'. It makes it much easier to debug and check quickly.

+4
source share
5 answers

, . mocha regexp.

describe('all tests',function(){
   describe('first tests',function(){
   });
   describe('second tests',function(){
   });
});

" "

describe('all tests',function(){
   describe.only('first tests',function(){
   });
   describe('second tests',function(){
   });
});

it.only()

. .

+6

, , . , .

, / , karma-mocha , , :

module.exports = function(config) {
  config.set({
    // karma configuration here
    ...

    // this is a mocha configuration object
    client: {
      // The pattern string will be passed to mocha
      args: ['--grep', '<pattern>'],
      ...
    }
  });
};

<pattern>, , CLI .

SO, , .

+4

, karma.conf.js. , "". minimist .

:

/* Begin */
var minimist = require('minimist');
var argv = minimist(process.argv);
var testBase="test/unit";
var testExt=".spec.js";
var unitTestPattern = testBase+'/**/*'+testExt;
if ("test" in argv){
  unitTestPattern = testBase+"/"+argv["test"]+testExt;
}
/* End */
module.exports = function(config){
  config.set({
    //....

    files : [
    //....
      unitTestPattern,             //place here
//      'test/unit/**/*.spec.js',  //replace this
    //....
    ],
    //....

  });
};

:

karma start test/karma.conf.js --single-run  --test #TEST_CASE_FILE#
0

1) karma.conf.js :

var files = (process.env.npm_config_single_file) ? process.env.npm_config_single_file : 'test/test_index.js';

2) ( ):

var option = {

  webpack: {
    // webpack configuration
  },

  // more configuration......
};

3) :

  option.files = [
      {pattern: files, watch: false}
  ];

  option.preprocessors = {};

  option.preprocessors[files] = [ 'webpack', 'sourcemap' ];

  // call config.set function
  config.set(option);

4) :

npm test --single_file=**/my-specific-file-spec.js

PR: https://github.com/webpack/karma-webpack/pull/178

0
source

All Articles