Karma: Running a single test file from command line

后端 未结 3 772
醉话见心
醉话见心 2020-12-07 19:06

So, I\'ve been looking all over for this, found \"similar\" answers here, but not exactly what I want.

Right now if I want to test a single file with karma, I need t

3条回答
  •  萌比男神i
    2020-12-07 19:19

    Even though --files is no longer supported, you can use an env variable to provide a list of files:

    // karma.conf.js
    function getSpecs(specList) {
      if (specList) {
        return specList.split(',')
      } else {
        return ['**/*_spec.js'] // whatever your default glob is
      }
    }
    
    module.exports = function(config) {
      config.set({
        //...
        files: ['app.js'].concat(getSpecs(process.env.KARMA_SPECS))
      });
    });
    

    Then in CLI:

    $ env KARMA_SPECS="spec1.js,spec2.js" karma start karma.conf.js --single-run
    

提交回复
热议问题