Export 0.2.1
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / build / tasks / testswarm.js
1 /*jshint node: true */
2 module.exports = function( grunt ) {
3
4 /*
5 To test these tasks locally, create a testswarm-local.json file like this, replacing the token and urls:
6
7 {
8     "jquerymobile": {
9         "authUsername": "jquerymobile",
10         "authToken": "1489f0baccc7af70b15d4bee6b0498f66b1ef611",
11         "swarmUrl": "http://swarm.local/",
12         "testUrl": "http://localhost/",
13         "runMax": 1
14     }
15 }
16
17 Then call:
18
19         grunt config:test:pages testswarm:jquery-mobile:testswarm-local.json
20
21 Adapt the second flag, the 'commit', to match files along with the testUrl property.
22  */
23
24 function submit( commit, tests, configFile, done ) {
25         var test,
26                 testswarm = require( "testswarm" ),
27                 config = grunt.file.readJSON( configFile ).jquerymobile,
28                 testBase = config.testUrl + commit + "/",
29                 testUrls = [];
30         for ( test in tests ) {
31                 testUrls.push( testBase + tests[ test ] );
32         }
33         testswarm({
34                 url: config.swarmUrl,
35                 pollInterval: 10000,
36                 timeout: 1000 * 60 * 30,
37                 done: done
38         }, {
39                 authUsername: config.authUsername,
40                 authToken: config.authToken,
41                 jobName: 'jQuery Mobile commit #<a href="https://github.com/jquery/jquery-mobile/commit/' + commit + '">' + commit.substr( 0, 10 ) + '</a>',
42                 runMax: config.runMax,
43                 "runNames[]": Object.keys(tests),
44                 "runUrls[]": testUrls,
45                 "browserSets[]": ["mobile"]
46         });
47 }
48
49 grunt.registerTask( "testswarm", function( commit, configFile ) {
50         // TODO currently using only the first five somewhat stable testsuites
51         // need to expand this
52         var tests = grunt.config.get('global').test_paths, finalSet = [];
53
54         // exclude the base tests for now, they don't appear to play nicely with testswarm
55         tests.forEach(function( testPath ) {
56                 if( ! /base\-tests/.test( testPath ) ){
57                         finalSet.push( testPath );
58                 }
59         });
60
61         tests = finalSet;
62
63         var test,
64                 latestTests = {};
65         for ( var i = 0; i < tests.length; i++ ) {
66                 latestTests[ tests[ i ].replace(/^tests\/unit\//, "") ] = tests[ i ];
67         }
68         submit( commit, latestTests, configFile, this.async() );
69 });
70
71 };