Repository navigation
Expand file tree
/
Copy pathxpc.js
More file actions
141 lines (110 loc) · 3.56 KB
/
Copy pathxpc.js
File metadata and controls
141 lines (110 loc) · 3.56 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
(function(window) {
window.parent = window;
window.location.host = 'localhost';
window.Date = Date;
var seenModule = {};
var path = window.xpcModule.require('path');
window.require = function(url, cb) {
if (url.lastIndexOf('apps/', 0) === 0) {
// required for loading of test files
url = '../../' + url;
} else if (url.lastIndexOf('/common', 0) === 0) {
// required so we can load the unit test helper.js
url = '../../test_apps/test-agent' + url;
} else if (url.lastIndexOf('/', 0) === 0) {
url = '../..' + url;
}
url = path.resolve(url);
if (!(url in seenModule)) {
seenModule[url] = true;
importScripts(url);
}
if (typeof(cb) === 'function') {
cb();
}
};
Common = window.CommonResourceLoader = {
url: function(url) {
return url;
}
};
require('/test_apps/test-agent/common/vendor/mocha/mocha.js');
require('/tests/reporters/jsonmoztest.js');
Mocha.reporters.JSONMozTest = JSONMozTestReporter;
process.stdout.write = window.xpcDump;
//Hack to format errors
Mocha.reporters.Base.list = function(failures) {
failures.forEach(function(test, i) {
// format
var fmt = this.color('error title', ' %s) %s:\n') +
this.color('error message', ' %s') +
this.color('error stack', '\n%s\n');
// msg
var err = test.err,
message = err.message || '',
stack = window.xpcError.format(err),
index = stack.indexOf(message) + message.length,
msg = stack.slice(0, index),
actual = err.actual,
expected = err.expected;
// actual / expected diff
if ('string' == typeof actual && 'string' == typeof expected) {
var len = Math.max(actual.length, expected.length);
if (len < 20) msg = errorDiff(err, 'Chars');
else msg = errorDiff(err, 'Words');
// linenos
var lines = msg.split('\n');
if (lines.length > 4) {
var width = String(lines.length).length;
msg = lines.map(function(str, i) {
return pad(++i, width) + ' |' + ' ' + str;
}).join('\n');
}
msg = [
'\n', this.color('diff removed', 'actual'),
' ', this.color('diff added', 'expected'),
'\n\n',
msg,
'\n'
].join('');
// indent
msg = msg.replace(/^/gm, ' ');
fmt = this.color('error title', ' %s) %s:\n%s') +
this.color('error stack', '\n%s\n');
}
// indent stack trace without msg
stack = stack.slice(index ? index + 1 : index)
.replace(/^/gm, ' ');
console.error(fmt, (i + 1), test.fullTitle(), msg, stack);
}.bind(this));
};
var env = window.xpcModule.require('env');
var reporter = env.get('REPORTER') || 'Spec';
if (!(reporter in Mocha.reporters)) {
var reporters = Object.keys(Mocha.reporters);
var idx = reporters.indexOf('Base');
if (idx !== -1) {
reporters.splice(idx, 1);
}
var allowed = reporters.join(',\t\n');
console.log('Error running integration tests:\n');
console.log(
'Invalid REPORTER "' + reporter + '" set use one of:\n' +
allowed
);
} else {
mocha.setup({
ui: 'tdd',
reporter: Mocha.reporters[reporter],
// change the default timeout to all tests to 6 seconds
timeout: 20000
});
window.xpcArgv.slice(2).forEach(function(test) {
require(test);
});
mocha.run(function() {
window.xpcEventLoop.stop();
});
window.xpcEventLoop.start();
}
}(this));