diff --git a/e2e-tests/logseq-api.spec.ts b/e2e-tests/logseq-api.spec.ts index 69a533cdc..d46e3e171 100644 --- a/e2e-tests/logseq-api.spec.ts +++ b/e2e-tests/logseq-api.spec.ts @@ -99,7 +99,33 @@ test('block related apis', */ export async function callPageAPI(page, method, ...args) { return await page.evaluate(([method, args]) => { + const hasNs = method.indexOf('.') !== -1 + const ns = hasNs ? method.split('.') : method // @ts-ignore - return window.logseq.api[method]?.(...args) + const ctx = hasNs ? window.logseq.sdk[ns[0].toLowerCase()] : window.logseq.api + return ctx[hasNs ? ns[1] : method]?.(...args) }, [method, args]) } + +/** + * load local tests plugin + */ +export async function loadLocalE2eTestsPlugin(page) { + const pid = 'a-logseq-plugin-for-e2e-tests' + const hasLoaded = await page.evaluate(([pid]) => { + // @ts-ignore + const p = window.LSPluginCore.registeredPlugins.get(pid) + return p != null + }, [pid]) + + if (hasLoaded) return true + + await callPageAPI(page, 'set_state_from_store', + 'ui/developer-mode?', true) + await page.keyboard.press('t+p') + await page.locator('text=Load unpacked plugin') + await callPageAPI(page, 'set_state_from_store', + 'plugin/selected-unpacked-pkg', `${__dirname}/plugin`) + await page.keyboard.press('Escape') + await page.keyboard.press('Escape') +} \ No newline at end of file diff --git a/e2e-tests/plugin/index.html b/e2e-tests/plugin/index.html new file mode 100644 index 000000000..19efb4b1b --- /dev/null +++ b/e2e-tests/plugin/index.html @@ -0,0 +1,15 @@ + + + + + + + Document + + + +
+ + + \ No newline at end of file diff --git a/e2e-tests/plugin/index.js b/e2e-tests/plugin/index.js new file mode 100644 index 000000000..6a662e2ce --- /dev/null +++ b/e2e-tests/plugin/index.js @@ -0,0 +1,49 @@ +async function main () { + logseq.UI.showMsg('Hi, e2e tests from a local plugin!') + + // await (new Promise(resolve => setTimeout(resolve, 3000))) + + let msg = 0 + + const logPane = (input) => { + logseq.provideUI({ + key: `log-${++msg}`, + path: `#a-plugin-for-e2e-tests > ul`, + template: `
  • ${input}
  • ` + }) + } + + // log pane + logseq.provideUI({ + key: 'logseq-e2e-tests', + template: `
    +

    Plugin e2e tests ...

    + +
    `, + path: 'body', + style: { + width: '300px', + position: 'fixed', + top: '300px', + left: '300px', + zIndex: 99, + }, + }) + + logseq.provideStyle(` + #a-plugin-for-e2e-tests { + padding: 20px; + background-color: red; + color: white; + width: 300px; + } + `) + + // test log + setTimeout(() => { + logPane(`DB: hook changed`) + }, 2000) +} + +// bootstrap +logseq.ready(main).catch(null) \ No newline at end of file diff --git a/e2e-tests/plugin/lsplugin.user.js b/e2e-tests/plugin/lsplugin.user.js new file mode 100644 index 000000000..a72c65e74 --- /dev/null +++ b/e2e-tests/plugin/lsplugin.user.js @@ -0,0 +1,2 @@ +/*! For license information please see lsplugin.user.js.LICENSE.txt */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LSPluginEntry=t():e.LSPluginEntry=t()}(self,(()=>(()=>{var e={227:(e,t,n)=>{var r=n(155);t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(447)(t);const{formatters:o}=e.exports;o.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:(e,t,n)=>{e.exports=function(e){function t(e){let n,o,i,s=null;function a(...e){if(!a.enabled)return;const r=a,o=Number(new Date),i=o-(n||o);r.diff=i,r.prev=n,r.curr=o,n=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,o)=>{if("%%"===n)return"%";s++;const i=t.formatters[o];if("function"==typeof i){const t=e[s];n=i.call(r,t),e.splice(s,1),s--}return n})),t.formatArgs.call(r,e);(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==t.namespaces&&(o=t.namespaces,i=t.enabled(e)),i),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(o),...t.skips.map(o).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t{"use strict";var t=function(e){return function(e){return!!e&&"object"==typeof e}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===n}(e)}(e)};var n="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function r(e,t){return!1!==t.clone&&t.isMergeableObject(e)?c((n=e,Array.isArray(n)?[]:{}),e,t):e;var n}function o(e,t,n){return e.concat(t).map((function(e){return r(e,n)}))}function i(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter((function(t){return Object.propertyIsEnumerable.call(e,t)})):[]}(e))}function s(e,t){try{return t in e}catch(e){return!1}}function a(e,t,n){var o={};return n.isMergeableObject(e)&&i(e).forEach((function(t){o[t]=r(e[t],n)})),i(t).forEach((function(i){(function(e,t){return s(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))})(e,i)||(s(e,i)&&n.isMergeableObject(t[i])?o[i]=function(e,t){if(!t.customMerge)return c;var n=t.customMerge(e);return"function"==typeof n?n:c}(i,n)(e[i],t[i],n):o[i]=r(t[i],n))})),o}function c(e,n,i){(i=i||{}).arrayMerge=i.arrayMerge||o,i.isMergeableObject=i.isMergeableObject||t,i.cloneUnlessOtherwiseSpecified=r;var s=Array.isArray(n);return s===Array.isArray(e)?s?i.arrayMerge(e,n,i):a(e,n,i):r(n,i)}c.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce((function(e,n){return c(e,n,t)}),{})};var l=c;e.exports=l},856:function(e){e.exports=function(){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,n){return t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},t(e,n)}function n(){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(e){return!1}}function r(e,o,i){return r=n()?Reflect.construct:function(e,n,r){var o=[null];o.push.apply(o,n);var i=new(Function.bind.apply(e,o));return r&&t(i,r.prototype),i},r.apply(null,arguments)}function o(e){return i(e)||s(e)||a(e)||l()}function i(e){if(Array.isArray(e))return c(e)}function s(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function a(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?n-1:0),o=1;o/gm),V=g(/^data-[\-\w.\u00B7-\uFFFF]/),K=g(/^aria-[\-\w]+$/),Y=g(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Q=g(/^(?:\w+script|data):/i),X=g(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),ee=g(/^html$/i),te=function(){return"undefined"==typeof window?null:window},ne=function(t,n){if("object"!==e(t)||"function"!=typeof t.createPolicy)return null;var r=null,o="data-tt-policy-suffix";n.currentScript&&n.currentScript.hasAttribute(o)&&(r=n.currentScript.getAttribute(o));var i="dompurify"+(r?"#"+r:"");try{return t.createPolicy(i,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+i+" could not be created."),null}};function re(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:te(),n=function(e){return re(e)};if(n.version="2.3.8",n.removed=[],!t||!t.document||9!==t.document.nodeType)return n.isSupported=!1,n;var r=t.document,i=t.document,s=t.DocumentFragment,a=t.HTMLTemplateElement,c=t.Node,l=t.Element,u=t.NodeFilter,f=t.NamedNodeMap,p=void 0===f?t.NamedNodeMap||t.MozNamedAttrMap:f,h=t.HTMLFormElement,d=t.DOMParser,g=t.trustedTypes,y=l.prototype,v=N(y,"cloneNode"),b=N(y,"nextSibling"),_=N(y,"childNodes"),I=N(y,"parentNode");if("function"==typeof a){var M=i.createElement("template");M.content&&M.content.ownerDocument&&(i=M.content.ownerDocument)}var oe=ne(g,r),ie=oe?oe.createHTML(""):"",se=i,ae=se.implementation,ce=se.createNodeIterator,le=se.createDocumentFragment,ue=se.getElementsByTagName,fe=r.importNode,pe={};try{pe=L(i).documentMode?i.documentMode:{}}catch(e){}var he={};n.isSupported="function"==typeof I&&ae&&void 0!==ae.createHTMLDocument&&9!==pe;var de,me,ge=J,ye=Z,ve=V,be=K,_e=Q,we=X,xe=Y,Ce=null,Se=F({},[].concat(o(P),o(R),o(D),o($),o(H))),Oe=null,je=F({},[].concat(o(B),o(q),o(W),o(G))),Ae=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Ee=null,ke=null,Te=!0,Ie=!0,Me=!1,Fe=!1,Le=!1,Ne=!1,Pe=!1,Re=!1,De=!1,Ue=!1,$e=!0,ze=!0,He=!1,Be={},qe=null,We=F({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Ge=null,Je=F({},["audio","video","img","source","image","track"]),Ze=null,Ve=F({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ke="http://www.w3.org/1998/Math/MathML",Ye="http://www.w3.org/2000/svg",Qe="http://www.w3.org/1999/xhtml",Xe=Qe,et=!1,tt=["application/xhtml+xml","text/html"],nt="text/html",rt=null,ot=i.createElement("form"),it=function(e){return e instanceof RegExp||e instanceof Function},st=function(t){rt&&rt===t||(t&&"object"===e(t)||(t={}),t=L(t),Ce="ALLOWED_TAGS"in t?F({},t.ALLOWED_TAGS):Se,Oe="ALLOWED_ATTR"in t?F({},t.ALLOWED_ATTR):je,Ze="ADD_URI_SAFE_ATTR"in t?F(L(Ve),t.ADD_URI_SAFE_ATTR):Ve,Ge="ADD_DATA_URI_TAGS"in t?F(L(Je),t.ADD_DATA_URI_TAGS):Je,qe="FORBID_CONTENTS"in t?F({},t.FORBID_CONTENTS):We,Ee="FORBID_TAGS"in t?F({},t.FORBID_TAGS):{},ke="FORBID_ATTR"in t?F({},t.FORBID_ATTR):{},Be="USE_PROFILES"in t&&t.USE_PROFILES,Te=!1!==t.ALLOW_ARIA_ATTR,Ie=!1!==t.ALLOW_DATA_ATTR,Me=t.ALLOW_UNKNOWN_PROTOCOLS||!1,Fe=t.SAFE_FOR_TEMPLATES||!1,Le=t.WHOLE_DOCUMENT||!1,Re=t.RETURN_DOM||!1,De=t.RETURN_DOM_FRAGMENT||!1,Ue=t.RETURN_TRUSTED_TYPE||!1,Pe=t.FORCE_BODY||!1,$e=!1!==t.SANITIZE_DOM,ze=!1!==t.KEEP_CONTENT,He=t.IN_PLACE||!1,xe=t.ALLOWED_URI_REGEXP||xe,Xe=t.NAMESPACE||Qe,t.CUSTOM_ELEMENT_HANDLING&&it(t.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ae.tagNameCheck=t.CUSTOM_ELEMENT_HANDLING.tagNameCheck),t.CUSTOM_ELEMENT_HANDLING&&it(t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ae.attributeNameCheck=t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),t.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Ae.allowCustomizedBuiltInElements=t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),de=de=-1===tt.indexOf(t.PARSER_MEDIA_TYPE)?nt:t.PARSER_MEDIA_TYPE,me="application/xhtml+xml"===de?function(e){return e}:S,Fe&&(Ie=!1),De&&(Re=!0),Be&&(Ce=F({},o(H)),Oe=[],!0===Be.html&&(F(Ce,P),F(Oe,B)),!0===Be.svg&&(F(Ce,R),F(Oe,q),F(Oe,G)),!0===Be.svgFilters&&(F(Ce,D),F(Oe,q),F(Oe,G)),!0===Be.mathMl&&(F(Ce,$),F(Oe,W),F(Oe,G))),t.ADD_TAGS&&(Ce===Se&&(Ce=L(Ce)),F(Ce,t.ADD_TAGS)),t.ADD_ATTR&&(Oe===je&&(Oe=L(Oe)),F(Oe,t.ADD_ATTR)),t.ADD_URI_SAFE_ATTR&&F(Ze,t.ADD_URI_SAFE_ATTR),t.FORBID_CONTENTS&&(qe===We&&(qe=L(qe)),F(qe,t.FORBID_CONTENTS)),ze&&(Ce["#text"]=!0),Le&&F(Ce,["html","head","body"]),Ce.table&&(F(Ce,["tbody"]),delete Ee.tbody),m&&m(t),rt=t)},at=F({},["mi","mo","mn","ms","mtext"]),ct=F({},["foreignobject","desc","title","annotation-xml"]),lt=F({},["title","style","font","a","script"]),ut=F({},R);F(ut,D),F(ut,U);var ft=F({},$);F(ft,z);var pt=function(e){var t=I(e);t&&t.tagName||(t={namespaceURI:Qe,tagName:"template"});var n=S(e.tagName),r=S(t.tagName);return e.namespaceURI===Ye?t.namespaceURI===Qe?"svg"===n:t.namespaceURI===Ke?"svg"===n&&("annotation-xml"===r||at[r]):Boolean(ut[n]):e.namespaceURI===Ke?t.namespaceURI===Qe?"math"===n:t.namespaceURI===Ye?"math"===n&&ct[r]:Boolean(ft[n]):e.namespaceURI===Qe&&!(t.namespaceURI===Ye&&!ct[r])&&!(t.namespaceURI===Ke&&!at[r])&&!ft[n]&&(lt[n]||!ut[n])},ht=function(e){C(n.removed,{element:e});try{e.parentNode.removeChild(e)}catch(t){try{e.outerHTML=ie}catch(t){e.remove()}}},dt=function(e,t){try{C(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){C(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!Oe[e])if(Re||De)try{ht(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},mt=function(e){var t,n;if(Pe)e=""+e;else{var r=O(e,/^[\r\n\t ]+/);n=r&&r[0]}"application/xhtml+xml"===de&&(e=''+e+"");var o=oe?oe.createHTML(e):e;if(Xe===Qe)try{t=(new d).parseFromString(o,de)}catch(e){}if(!t||!t.documentElement){t=ae.createDocument(Xe,"template",null);try{t.documentElement.innerHTML=et?"":o}catch(e){}}var s=t.body||t.documentElement;return e&&n&&s.insertBefore(i.createTextNode(n),s.childNodes[0]||null),Xe===Qe?ue.call(t,Le?"html":"body")[0]:Le?t.documentElement:s},gt=function(e){return ce.call(e.ownerDocument||e,e,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT,null,!1)},yt=function(e){return e instanceof h&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof p)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore)},vt=function(t){return"object"===e(c)?t instanceof c:t&&"object"===e(t)&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName},bt=function(e,t,r){he[e]&&w(he[e],(function(e){e.call(n,t,r,rt)}))},_t=function(e){var t;if(bt("beforeSanitizeElements",e,null),yt(e))return ht(e),!0;if(k(/[\u0080-\uFFFF]/,e.nodeName))return ht(e),!0;var r=me(e.nodeName);if(bt("uponSanitizeElement",e,{tagName:r,allowedTags:Ce}),e.hasChildNodes()&&!vt(e.firstElementChild)&&(!vt(e.content)||!vt(e.content.firstElementChild))&&k(/<[/\w]/g,e.innerHTML)&&k(/<[/\w]/g,e.textContent))return ht(e),!0;if("select"===r&&k(/