UNPKG

@contentful/integration-test-utils

Version:
3 lines (2 loc) 13.7 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("contentful-management");function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function u(t,e,r){return(u=c()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&a(o,r.prototype),o}).apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),a(r,t)})(t)}function l(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var f=function(t){function e(r){var n;return(n=t.call(this,"Space name too long")||this).details={spaceName:r,length:r.length},Object.setPrototypeOf(l(n),e.prototype),n}return o(e,t),e}(s(Error)),p=function(t){function e(r){var n;return(n=t.call(this,"Space creation failed")||this).details={spaceName:r},Object.setPrototypeOf(l(n),e.prototype),n}return o(e,t),e}(s(Error)),h=function(t){function e(r){var n;return(n=t.call(this,"Space name too long")||this).details={environmentName:r,length:r.length},Object.setPrototypeOf(l(n),e.prototype),n}return o(e,t),e}(s(Error)),y=function(t){function e(r){var n;return(n=t.call(this,"Environment creation failed")||this).details={environmentName:r},Object.setPrototypeOf(l(n),e.prototype),n}return o(e,t),e}(s(Error)),v=function(t){function e(r,n,o){var i;return(i=t.call(this,"Environment not ready for too long")||this).details={spaceName:r,environmentName:n,timeout:o},Object.setPrototypeOf(l(i),e.prototype),i}return o(e,t),e}(s(Error)),d=function(t){function e(r){var n;return(n=t.call(this,"Missing credential")||this).details={credentialName:r},Object.setPrototypeOf(l(n),e.prototype),n}return o(e,t),e}(s(Error)),m={};function g(){var e=process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN;if(!e)throw new d("CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN");return t.createClient(n({accessToken:e},m))}process.env.API_INTEGRATION_TESTS&&(m.host="127.0.0.1:5000",m.insecure=!0);var w,x=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function p(){}function h(){}var y={};c(y,o,(function(){return this}));var v=Object.getPrototypeOf,d=v&&v(v(_([])));d&&d!==e&&r.call(d,o)&&(y=d);var m=h.prototype=f.prototype=Object.create(y);function g(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=h,c(m,"constructor",h),c(h,"constructor",p),p.displayName=c(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,c(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},g(w.prototype),c(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(m),c(m,a,"Generator"),c(m,o,(function(){return this})),c(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(w={exports:{}}),w.exports);function b(t){return new Promise((function(e){return setTimeout(e,t)}))}function E(){return(E=r(x.mark((function t(e,r){var n;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(r.length>40)){t.next=2;break}throw new h(r);case 2:return t.prev=2,t.next=5,e.createEnvironment({name:r});case 5:n=t.sent,t.next=11;break;case 8:t.prev=8,t.t0=t.catch(2),console.error(t.t0);case 11:if(n){t.next=13;break}throw new y(r);case 13:return t.next=15,O(e,n);case 15:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}}),t,null,[[2,8]])})))).apply(this,arguments)}function O(t,e,r){return _.apply(this,arguments)}function _(){return(_=r(x.mark((function t(e,r,n){var o;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===n&&(n=0),!(n>3e5)){t.next=3;break}throw new v(e.name,r.name,n);case 3:return t.next=5,e.getEnvironment(r.sys.id);case 5:if("ready"===(o=t.sent).sys.status.sys.id){t.next=9;break}return console.log("Environment "+r.sys.id+" is not ready yet. Waiting 1000ms..."),t.abrupt("return",b(1e3).then((function(){return O(e,o,n+1e3)})));case 9:return t.abrupt("return",o);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function T(){return(T=r(x.mark((function t(e){var r,n,o,i;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.client,n=e.organizationId,!((o="%"+e.language+" "+e.repo+" "+e.testSuiteName).length>30)){t.next=4;break}throw new f(o);case 4:return t.prev=4,t.next=7,r.createSpace({name:o},n);case 7:i=t.sent,t.next=13;break;case 10:t.prev=10,t.t0=t.catch(4),console.error(t.t0);case 13:if(i){t.next=15;break}throw new p(o);case 15:return t.abrupt("return",i);case 16:case"end":return t.stop()}}),t,null,[[4,10]])})))).apply(this,arguments)}function L(t,e){return N.apply(this,arguments)}function N(){return(N=r(x.mark((function t(e,r){var n;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e.getSpace(r);case 3:return n=t.sent,t.next=6,n.delete();case 6:console.log("Deleted space "+r),t.next=13;break;case 9:t.prev=9,t.t0=t.catch(0),console.log(t.t0.name,t.t0.message),console.error("Error deleting space "+r+' with error "'+t.t0.message+'"');case 13:case"end":return t.stop()}}),t,null,[[0,9]])})))).apply(this,arguments)}function j(t){var e=t.prefix,r=t.threshold;return t.spaces.filter((function(t){return t.name.startsWith(e)&&Date.parse(t.sys.updatedAt)+r<Date.now()}))}exports.cleanUpTestSpaces=function(){var t=r(x.mark((function t(e){var r,o,i,a,c;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n({threshold:36e5,dryRun:!1},e),o=r.threshold,i=r.dryRun,a=g(),t.next=4,a.getSpaces();case 4:if(0!==(c=j({spaces:t.sent.items,prefix:"%",threshold:o})).length){t.next=10;break}console.log("Found no spaces matching deletion criteria"),t.next=18;break;case 10:if(console.log("Found "+c.length+" spaces matching deletion criteria"),!i){t.next=16;break}console.log("To delete the following spaces, set 'dryRun' to false"),console.log(c.map((function(t){return'space "'+t.name+'" id:'+t.sys.id}))),t.next=18;break;case 16:return t.next=18,Promise.allSettled(c.map((function(t){return L(a,t.sys.id)})));case 18:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),exports.createTestEnvironment=function(t,e){return E.apply(this,arguments)},exports.createTestSpace=function(t){return T.apply(this,arguments)},exports.generateRandomIdWithPrefix=function(t){return void 0===t&&(t=""),t+Math.ceil(1e8*Math.random())},exports.initClient=g,exports.waitForEnvironmentToBeReady=O; //# sourceMappingURL=integration-test-utils.cjs.production.min.js.map