forked from csnover/dojo2-teststack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
97 lines (85 loc) · 2.97 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*jshint node:true */
if (typeof process !== 'undefined' && typeof define === 'undefined') {
(function () {
var req = require('./dojo/dojo'),
pathUtils = require('path');
req({
baseUrl: pathUtils.resolve(__dirname, '..'),
packages: [
{ name: 'dojo-ts', location: pathUtils.resolve(__dirname, 'dojo') },
{ name: 'teststack', location: __dirname },
{ name: 'chai', location: pathUtils.resolve(__dirname, 'chai'), main: 'chai' }
]
}, [ 'teststack/client' ]);
})();
}
else {
define([
'./main',
'./lib/args',
'./lib/reporterManager',
'./lib/Suite',
'dojo-ts/topic',
'require'
], function (main, args, reporterManager, Suite, topic, require) {
if (!args.config) {
throw new Error('Missing "config" argument');
}
require([ args.config ], function (config) {
// TODO: Use of the global require is required for this to work because config mechanics are in global
// require only in the Dojo loader; this should probably not be the case
this.require(config.loader);
if (!args.suites) {
args.suites = config.suites;
}
// args.suites might be an array or it might be a scalar value but we always need deps to be a fresh array.
var deps = [].concat(args.suites);
if (!args.reporters) {
if (config.reporters) {
args.reporters = config.reporters;
}
else {
console.info('Defaulting to "console" reporter');
args.reporters = 'console';
}
}
// TODO: This is probably a fatal condition and so we need to let the runner know that no more information
// will be forthcoming from this client
if (typeof window !== 'undefined') {
window.onerror = function (message, url, lineNumber) {
var error = new Error(message + ' at ' + url + ':' + lineNumber);
topic.publish('/error', error);
topic.publish('/client/end', args.sessionId);
};
}
else if (typeof process !== 'undefined') {
process.on('uncaughtException', function (error) {
topic.publish('/error', error);
});
}
args.reporters = [].concat(args.reporters).map(function (reporterModuleId) {
// Allow 3rd party reporters to be used simply by specifying a full mid, or built-in reporters by
// specifying the reporter name only
if (reporterModuleId.indexOf('/') === -1) {
reporterModuleId = './lib/reporters/' + reporterModuleId;
}
return reporterModuleId;
});
deps = deps.concat(args.reporters);
// Client interface has only one environment, the current environment, and cannot run functional tests on
// itself
main.suites.push(new Suite({ name: 'main', sessionId: args.sessionId }));
require(deps, function () {
// A hash map, { reporter module ID: reporter definition }
var reporters = [].slice.call(arguments, arguments.length - args.reporters.length).reduce(function (map, reporter, i) {
map[args.reporters[i]] = reporter;
return map;
}, {});
reporterManager.add(reporters);
if (args.autoRun !== 'false') {
main.run();
}
});
});
});
}