protractor-sync-options-plugin
Version:
Protractor plugin to ignore specific async calls in angular application
16 lines (14 loc) • 6.75 kB
JavaScript
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("protractor")):"function"==typeof define&&define.amd?define("protractor-sync-options-plugin",["exports","protractor"],r):r((t=t||self)["protractor-sync-options-plugin"]={},t.protractor)}(this,(function(t,r){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function n(t,r,n,e){return new(n||(n=Promise))((function(o,i){function a(t){try{c(e.next(t))}catch(t){i(t)}}function u(t){try{c(e.throw(t))}catch(t){i(t)}}function c(t){var r;t.done?o(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(a,u)}c((e=e.apply(t,r||[])).next())}))}function e(t,r){var n,e,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,e=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=r.call(t,a)}catch(t){i=[6,t],e=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var o=function(t){if(!window.getAllAngularTestabilities)throw Error("Testability not found. Not an angular app?");var r=window.getAllAngularTestabilities()[0],n=r.constructor,e=n.prototype.isStable;if(e.originalFn)throw Error("Testability already patched");var o=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var o=e.apply(this,t),i=u(r);return o||i};function i(t,r){var n=!0;return function(t){var r=t.source;return"string"==typeof r||r instanceof RegExp}(r)&&(n&=function(t,r){return t.source===r.source}(t,r)),function(t){var r=t.creationLocation;return"string"==typeof r||r instanceof RegExp}(r)&&(n&=function(t,r){var n=r.creationLocation;return function(t){return t.creationLocation.stack.split(" at ")}(t).some((function(t){return n instanceof RegExp?t.match(n):"string"==typeof n?t.includes(n):void 0}))}(t,r)),n}function a(r){return t.some((function(t){return i(r,t)}))}function u(t){return t.taskTrackingZone.macroTasks.every(a)}o.originalFn=e,n.prototype.isStable=o},i=function(){if(!window.getAllAngularTestabilities)throw Error("Testability not found. Not an angular app?");var t=window.getAllAngularTestabilities()[0].constructor,r=t.prototype.isStable;if(!r.originalFn)throw Error("Cant restore, Testability.whenStable is not patched");t.prototype.isStable=r.originalFn};var a=function(){function t(t){this.browser=t}return t.prototype.patchClientTestability=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(r){switch(r.label){case 0:return[4,this.browser.executeScript(o,t.ignoreTasks||[])];case 1:return r.sent(),[2]}}))}))},t.prototype.restoreClientTestability=function(){return n(this,void 0,void 0,(function(){return e(this,(function(t){return[2,this.browser.executeScript(i)]}))}))},t.prototype.patchWaitForAngularEnabled=function(t){return n(this,void 0,void 0,(function(){var r,o,i;return e(this,(function(a){if(this.isWaitForAngularPatched())throw Error("browser.waitForAngularEnabled is already patched");return r=this.browser.constructor.prototype.waitForAngularEnabled,o=this,(i=function(){for(var i=[],a=0;a<arguments.length;a++)i[a]=arguments[a];return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return!0!==i[0]?[3,2]:[4,o.patchClientTestability(t).catch((function(t){console.warn("patched waitForAngularEnabled => patchClientTestability error:",t)}))];case 1:n.sent(),n.label=2;case 2:return[2,r.apply(this,i)]}}))}))}).orignalFn=r,this.browser.constructor.prototype.waitForAngularEnabled=i,[2]}))}))},t.prototype.restoreWaitForAngularEnabled=function(){return n(this,void 0,void 0,(function(){var t;return e(this,(function(r){if(!this.isWaitForAngularPatched())throw Error("Cant restore. this.browser.constructor.prototype.waitForAngularEnabled is not patched");return(t=this.browser.constructor.prototype).waitForAngularEnabled=t.waitForAngularEnabled.originalFn,[2]}))}))},t.prototype.isWaitForAngularPatched=function(){return!!this.browser.constructor.prototype.waitForAngularEnabled.originalFn},t}(),u=function(){function t(){this.name="Protractor Sync Options Plugin",this.patcher=new a(r.browser)}return t.prototype.onPageLoad=function(t){return n(this,void 0,void 0,(function(){var t=this;return e(this,(function(r){switch(r.label){case 0:return[4,this.trySafe((function(){return t.patcher.patchClientTestability(t.config)}))];case 1:return r.sent(),[2]}}))}))},t.prototype.setup=function(){return n(this,void 0,void 0,(function(){var t=this;return e(this,(function(n){switch(n.label){case 0:return this.patcher.browser=r.browser,[4,this.trySafe((function(){return t.patcher.patchWaitForAngularEnabled(t.config)}))];case 1:return n.sent(),[2]}}))}))},t.prototype.trySafe=function(t){return n(this,void 0,void 0,(function(){var r;return e(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t()];case 1:return n.sent(),[2,!0];case 2:return r=n.sent(),console.warn("function call failed",r),[2,!1];case 3:return[2]}}))}))},t}(),c=new u;Object.assign(t,c),t.setup=c.setup,t.onPageLoad=c.onPageLoad,t.trySafe=c.trySafe;var s=t;t.Patcher=a,t.SyncOptionsPlugin=u,t.plugin=s,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=protractor-sync-options-plugin.umd.min.js.map