UNPKG

3.69 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const path_1 = require("path");
4const q_1 = require("q");
5const selenium_webdriver_1 = require("selenium-webdriver");
6let STACK_SUBSTRINGS_TO_FILTER = [
7 'node_modules/jasmine/', 'node_modules/selenium-webdriver', 'at Module.', 'at Object.Module.',
8 'at Function.Module', '(timers.js:', 'jasminewd2/index.js', 'protractor/lib/'
9];
10/**
11 * Utility function that filters a stack trace to be more readable. It removes
12 * Jasmine test frames and webdriver promise resolution.
13 * @param {string} text Original stack trace.
14 * @return {string}
15 */
16function filterStackTrace(text) {
17 if (!text) {
18 return text;
19 }
20 let lines = text.split(/\n/).filter((line) => {
21 for (let filter of STACK_SUBSTRINGS_TO_FILTER) {
22 if (line.indexOf(filter) !== -1) {
23 return false;
24 }
25 }
26 return true;
27 });
28 return lines.join('\n');
29}
30exports.filterStackTrace = filterStackTrace;
31/**
32 * Internal helper for abstraction of polymorphic filenameOrFn properties.
33 * @param {object} filenameOrFn The filename or function that we will execute.
34 * @param {Array.<object>}} args The args to pass into filenameOrFn.
35 * @return {q.Promise} A promise that will resolve when filenameOrFn completes.
36 */
37function runFilenameOrFn_(configDir, filenameOrFn, args) {
38 return q_1.Promise((resolvePromise) => {
39 if (filenameOrFn && !(typeof filenameOrFn === 'string' || typeof filenameOrFn === 'function')) {
40 throw new Error('filenameOrFn must be a string or function');
41 }
42 if (typeof filenameOrFn === 'string') {
43 filenameOrFn = require(path_1.resolve(configDir, filenameOrFn));
44 }
45 if (typeof filenameOrFn === 'function') {
46 let results = q_1.when(filenameOrFn.apply(null, args), null, (err) => {
47 if (typeof err === 'string') {
48 err = new Error(err);
49 }
50 else {
51 err = err;
52 if (!err.stack) {
53 err.stack = new Error().stack;
54 }
55 }
56 err.stack = exports.filterStackTrace(err.stack);
57 throw err;
58 });
59 resolvePromise(results);
60 }
61 else {
62 resolvePromise(undefined);
63 }
64 });
65}
66exports.runFilenameOrFn_ = runFilenameOrFn_;
67/**
68 * Joins two logs of test results, each following the format of <framework>.run
69 * @param {object} log1
70 * @param {object} log2
71 * @return {object} The joined log
72 */
73function joinTestLogs(log1, log2) {
74 return {
75 failedCount: log1.failedCount + log2.failedCount,
76 specResults: (log1.specResults || []).concat(log2.specResults || [])
77 };
78}
79exports.joinTestLogs = joinTestLogs;
80/**
81 * Returns false if an error indicates a missing or stale element, re-throws
82 * the error otherwise
83 *
84 * @param {*} The error to check
85 * @throws {*} The error it was passed if it doesn't indicate a missing or stale
86 * element
87 * @return {boolean} false, if it doesn't re-throw the error
88 */
89function falseIfMissing(error) {
90 if ((error instanceof selenium_webdriver_1.error.NoSuchElementError) ||
91 (error instanceof selenium_webdriver_1.error.StaleElementReferenceError)) {
92 return false;
93 }
94 else {
95 throw error;
96 }
97}
98exports.falseIfMissing = falseIfMissing;
99/**
100 * Return a boolean given boolean value.
101 *
102 * @param {boolean} value
103 * @returns {boolean} given value
104 */
105function passBoolean(value) {
106 return value;
107}
108exports.passBoolean = passBoolean;
109//# sourceMappingURL=util.js.map
\No newline at end of file