Specify QUnit module at startup using Grunt

I use Grunt, PhantomJS and the watch plugin to run QUnit tests during development (separate from CI). I would like to focus on a specific QUnit module while I work on the code that those unit tests focus on. When running QUnit in a browser, I can specify the module to run (compared to all tests).

So the question is, can I ask the Grunt qunit task only to run a specific module? I think the command line argument, so I do not need to change my Gruntfile, something like:

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

UPDATE

To be clear, I want to run modules created in a test suite using the QUnit module() method:

 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" ); }); 

In the above example, this code is in one test suite, but in the resulting html test file I get a drop-down list to run either the "group a" module or the "group b" module (via the QUnit interface). I want to programmatically indicate that I want to run a specific module using the grunt qunit .

+6
source share
2 answers

If you configure for grunt-qunit as follows:

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

You can run a separate module, for example grunt qunit:module1

0
source

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

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

then using it:

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

Please note that this will only work for one module. Perhaps (but not verified) you can use the filter request parameter instead of the module, and name your modules according to the filter to be able to group them.

Note. Running multiple modules is not what QUnit will support.

Literature:

0
source

Source: https://habr.com/ru/post/943726/


All Articles