简体   繁体   English

我如何运行单元测试子集与Karma Gulp-Angular?

[英]How Do I Run a Subset of Unit Tests Gulp-Angular with Karma?

I'm working on an AngularJS 1.4 project that was created from the Gulp-Angular yeoman generator. 我正在研究一个由Gulp-Angular yeoman发电机创建的AngularJS 1.4项目。 It has karma and gulp already configured so that when I run gulp test from the command line karma runs all of my *.spec.js files. 它已经配置了karma和gulp,这样当我从命令行运行gulp测试时 ,karma运行我所有的* .spec.js文件。 My problem is that it always run ALL of my spec.js files in the entire project. 我的问题是它总是在整个项目中运行我的所有spec.js文件。 I would like to just run one or two spec.js files- even better to be able to specify a folder and have it find all spec.js files recursively. 我想只运行一个或两个spec.js文件 - 更好的是能够指定一个文件夹并让它以递归方式查找所有spec.js文件。

  • I've tried just cd'ing down to a folder, but it still runs all tests. 我已经尝试过cd'ing到一个文件夹,但它仍然运行所有测试。

  • I've also tried editing this line in karma.conf.js: path.join(conf.paths.src, '/**/*.spec.js'), 我也尝试在karma.conf.js中编辑这一行:path.join(conf.paths.src,'/ / /。{。's''),

  • and this line in the gulp directory's unit-tests.js file: path.join(conf.paths.src, '/**/!(*.spec).js') 和gulp目录下的unit-tests.js文件中的这一行:path.join(conf.paths.src,'/ / /!(*。spec).js')

However, when I edit them I still get all the test suites in the whole entire project running! 但是,当我编辑它们时,我仍然可以在整个项目中运行所有测试套件! Ahh! 啊!

There must be a way to do what I'm trying to do. 必须有办法做我想做的事情。 Can anyone help me out with the correct approach here? 任何人都可以帮助我在这里采取正确的方法吗?

Karma is the test runner. Karma是试运行员。 Yeoman's gulp-angular generator uses Jasmine as the tester. Yeoman的gulp-angular发生器使用Jasmine作为测试器。

Search for a file jasmine.json. 搜索文件jasmine.json。

There is a "spec_dir" and a "spec_files" section that looks something like: 有一个"spec_dir"和一个"spec_files"部分,它看起来像:

  "spec_dir": "./",
  "spec_files": [
    "**/*[sS]pec.js"
  ],

Modify it to fit your needs. 修改它以满足您的需求。 I'm guessing something along the line: 我在猜测一些事情:

  "spec_dir": "./some_specific_path",
  "spec_files": [
    "**/*[sS]pec.js"
  ],

or if you want to do it incrementally from the root: 或者如果你想从根目录逐步进行:

  "spec_dir": "./",
  "spec_files": [
    "some_specific_path_1/**/*[sS]pec.js",
    "some_specific_path_2/**/*[sS]pec.js"
  ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在yeoman gulp-angular projekt设置之后的单元测试中出错 - Error in unit tests after yeoman gulp-angular projekt setup 弯角,无弯角和自举 - Gulp-angular, Gulp-less and bootstrap 如何在gulp配置中正确访问karma.config对象来监视文件,然后运行karma,最后如果karma通过则构建? - how do I correctly access karma.config object in gulp configuration to watch files, then run karma, and finally build if karma passes? 使用回送REST API时如何更改gulp-angular项目的端口号 - How to change the port number of the gulp-angular project when using loopback REST API 在特定的浏览器版本上使用Karma运行单元测试 - Run unit tests with Karma on specific browser versions 如何在Angular / Karma单元测试中忽略run.js? - How to ignore a run.js in Angular / Karma unit testing? 使用手写笔样式表时如何在Angular中运行业力测试? - How to run karma tests in Angular when stylus stylesheets are used? 如何在 Angular 单元测试中更新组件变量? - How do I update component variables in Angular unit tests? 如何在角度单位测试中设置html5Mode? 使用业力 - how do I set html5Mode in angular unit test? using karma 测试不会与Karma,Browserify,Angular一起运行 - Tests wont run with Karma, Browserify, Angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM