util.js
2.82 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
"use strict";
var path_1 = require("path");
var q_1 = require("q");
var STACK_SUBSTRINGS_TO_FILTER = [
'node_modules/jasmine/', 'node_modules/selenium-webdriver', 'at Module.', 'at Object.Module.',
'at Function.Module', '(timers.js:', 'jasminewd2/index.js', 'protractor/lib/'
];
/**
* Utility function that filters a stack trace to be more readable. It removes
* Jasmine test frames and webdriver promise resolution.
* @param {string} text Original stack trace.
* @return {string}
*/
function filterStackTrace(text) {
if (!text) {
return text;
}
var lines = text.split(/\n/).filter(function (line) {
for (var _i = 0, STACK_SUBSTRINGS_TO_FILTER_1 = STACK_SUBSTRINGS_TO_FILTER; _i < STACK_SUBSTRINGS_TO_FILTER_1.length; _i++) {
var filter = STACK_SUBSTRINGS_TO_FILTER_1[_i];
if (line.indexOf(filter) !== -1) {
return false;
}
}
return true;
});
return lines.join('\n');
}
exports.filterStackTrace = filterStackTrace;
/**
* Internal helper for abstraction of polymorphic filenameOrFn properties.
* @param {object} filenameOrFn The filename or function that we will execute.
* @param {Array.<object>}} args The args to pass into filenameOrFn.
* @return {q.Promise} A promise that will resolve when filenameOrFn completes.
*/
function runFilenameOrFn_(configDir, filenameOrFn, args) {
return q_1.Promise(function (resolvePromise) {
if (filenameOrFn && !(typeof filenameOrFn === 'string' || typeof filenameOrFn === 'function')) {
throw new Error('filenameOrFn must be a string or function');
}
if (typeof filenameOrFn === 'string') {
filenameOrFn = require(path_1.resolve(configDir, filenameOrFn));
}
if (typeof filenameOrFn === 'function') {
var results = q_1.when(filenameOrFn.apply(null, args), null, function (err) {
if (typeof err === 'string') {
err = new Error(err);
}
else {
err = err;
if (!err.stack) {
err.stack = new Error().stack;
}
}
err.stack = exports.filterStackTrace(err.stack);
throw err;
});
resolvePromise(results);
}
else {
resolvePromise(undefined);
}
});
}
exports.runFilenameOrFn_ = runFilenameOrFn_;
/**
* Joins two logs of test results, each following the format of <framework>.run
* @param {object} log1
* @param {object} log2
* @return {object} The joined log
*/
function joinTestLogs(log1, log2) {
return {
failedCount: log1.failedCount + log2.failedCount,
specResults: (log1.specResults || []).concat(log2.specResults || [])
};
}
exports.joinTestLogs = joinTestLogs;