6

Grunt、PhantomJS、および「watch」プラグインを使用して、開発中に (CI とは別に) QUnit テストを実行しています。そのモジュールのテストが焦点を当てているコードに取り組んでいる間、特定の QUnit モジュールに集中できるようにしたいと考えています。ブラウザーで QUnit を実行する場合、実行するモジュールを指定できます (すべてのテストに対して)。

問題は、特定のモジュールのみを実行するように Grunt qunit タスクに指示できますか? Gruntfile を変更する必要がないように、次のようなコマンド ライン引数を考えています。

~$ grunt qunit --module="test this stuff, test that stuff"

アップデート

明確にするために、実行したいのは、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" );
});

上記の例では、このコードはすべて 1 つのテスト スイートに含まれていますが、結果の html テスト ファイルでは、モジュール「グループ a」またはモジュール「グループ b」のいずれかを (QUnit の UI を介して) 実行するためのドロップダウンが表示されます。私が望むのは、grunt qunitタスクを通じて特定のモジュールを実行することをプログラムで指定できるようにすることです。

4

2 に答える 2

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',
        ]
      }
    }
  }
  ...

次のような個々のモジュールを実行できますgrunt qunit:module1

于 2013-12-31T19:56:38.537 に答える
0

I think a viable workaround could be to define a module filter option, and if it exist, append it to the urls. Something like this in the Gruntfile.js

var moduleFilter =  '';
if (grunt.option('module')) {
  moduleFilter = '?module=' + grunt.option('module')
}

then using it:

grunt.initConfig({
  qunit: {
    options: {
        ...
        urls: [
          'http://localhost:3000/qunit' + moduleFilter
        ]
    }
  }
});

Note that this will work for one module only. Maybe (but not tested) you can use the filter query param instead of module, and name your modules to match the filter, in order to be able to group them.

Note: Running multiple modules is not something that QUnit will support.

References:

于 2014-07-01T14:52:02.080 に答える