- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / third_party / spaceport / js / testRunner.js
1 define([ 'util/ensureCallback', 'util/chainAsync' ], function (ensureCallback, chainAsync) {
2     var testRunner = {
3         run: function run(name, test, callbacks) {
4             var stepCallback = callbacks.step || function () { };
5             var doneCallback = ensureCallback(callbacks.done);
6
7             if (typeof test === 'function') {
8                 // We run the test twice (sadly): once to warm up the JIT and once for the actual test.
9                 //test(function (_, _) {
10                     test(function (err, results) {
11                         stepCallback(err, name, results);
12                         doneCallback(err, results);
13                     });
14                 //});
15             } else {
16                 var allResults = { };
17
18                 var subTests = Object.keys(test).map(function (subName) {
19                     var newName = name ? name + '.' + subName : subName;
20                     return function (next) {
21                         testRunner.run(newName, test[subName], {
22                             step: stepCallback,
23                             done: function (err, results) {
24                                 if (!err) {
25                                     allResults[subName] = results;
26                                 }
27
28                                 next();
29                             }
30                         });
31                     };
32                 });
33
34                 chainAsync(subTests.concat([
35                     function () {
36                         doneCallback(null, allResults);
37                     }
38                 ]));
39             }
40         }
41     };
42
43     return testRunner;
44 });