使用Grunt运行时指定QUnit模块

jak*_*lla 6 testing qunit gruntjs

我正在使用Grunt,PhantomJS和"watch"插件在我开发时运行我的QUnit测试(与CI分开).我希望能够专注于特定的QUnit模块,同时我正在处理该模块测试所关注的代码.在浏览器中运行QUnit时,我可以指定要运行的模块(与所有测试相对).

所以问题是,我可以告诉Grunt qunit任务只运行某个模块吗?我正在考虑命令行参数,以便我不必更改我的Gruntfile,例如:

~$ grunt qunit --module="test this stuff, test that stuff"
Run Code Online (Sandbox Code Playgroud)

UPDATE

要清楚,我想要运行的是使用QUnit module()方法在测试套件中创建的模块:

module( "group a" );
test( "a basic test example", function() {
    ok( true, "this test is fine" );
});
test( "a basic test example 2", function() {
    ok( true, "this test is fine" );
});

module( "group b" );
test( "a basic test example 3", function() {
    ok( true, "this test is fine" );
});
test( "a basic test example 4", function() {
    ok( true, "this test is fine" );
});
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,此代码全部在一个测试套件中,但在生成的html测试文件中,我得到一个下拉列表来运行模块"group a"或模块"group b"(通过QUnit的UI).我想要的是能够以编程方式指定我想通过grunt qunit任务运行特定模块.

Stu*_*art 0

如果您像这样设置 grunt-qunit 的配置:

grunt.initConfig({
  qunit: {
    module1: {
      options: {
        urls: [
         'http://localhost:8000/test/module1/foo.html',
         'http://localhost:8000/test/module1/bar.html',
        ]
      }
    },
    module2: {
      options: {
        urls: [
         'http://localhost:8000/test/module2/foo.html',
         'http://localhost:8000/test/module2/bar.html',
        ]
      }
    }
  }
  ...
Run Code Online (Sandbox Code Playgroud)

您可以运行单个模块,例如grunt qunit:module1