@joystick.js/test-canary 0.0.0-canary.70 → 0.0.0-canary.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{parseHTML as
|
|
1
|
+
import{parseHTML as i}from"linkedom";import d from"@joystick.js/ui-canary";import l from"node-fetch";import{URL as w,URLSearchParams as m}from"url";import p from"./event.js";import h from"../load/index.js";const u=async(e="")=>{const r=new w(`${window?.location?.origin}/api/_test/bootstrap`);r.search=new m({pathToComponent:e});const o=await l(r).then(async a=>a.json());window.joystick={},window.joystick.settings={},window.__joystick_data__=o?.data||{},window.__joystick_i18n__=o?.translations||{},window.__joystick_req__=o?.req,console.log(o)},g=()=>{const e=i(`
|
|
2
2
|
<html>
|
|
3
3
|
<head></head>
|
|
4
4
|
<body>
|
|
@@ -6,4 +6,4 @@ import{parseHTML as m}from"linkedom";import w from"@joystick.js/ui-canary";impor
|
|
|
6
6
|
<meta name="csrf" content="joystick_test" />
|
|
7
7
|
</body>
|
|
8
8
|
</html>
|
|
9
|
-
`),{window:
|
|
9
|
+
`),{window:r,document:o,Element:a,Event:n,HTMLElement:t}=e;return global.window=r,global.document=o,global.HTMLElement=t,global.Element=a,global.Event=n,global.console={log:console.log,warn:console.warn,error:console.error},e};var v=async(e="",r={})=>{const o=g();window.fetch=l,window.location={origin:`http://localhost:${process.env.PORT}`},await u(e);const a=await h(e,{default:!0}),n=d.mount(a,r?.props||{},o?.document.querySelector("#app"));return n.isTest=!0,{dom:o,instance:n,test:{data:async(t={})=>n?.data?.refetch(t),render:()=>{const t=n?.renderToHTML(),s=new RegExp("<when>|</when>","g");return t?.wrapped?.replace(s,"")?.replace(/\n|\t/g," ")?.replace(/> *</g,"><")},method:(t="",...s)=>{const c=n?.methods[t];return c?c(...s):null},event:(t="",s="")=>p(t,s,o)}}};export{v as default};
|
package/package.json
CHANGED
|
@@ -6,6 +6,33 @@ import { URL, URLSearchParams } from 'url';
|
|
|
6
6
|
import event from './event.js';
|
|
7
7
|
import load from "../load/index.js";
|
|
8
8
|
|
|
9
|
+
const bootstrapWindow = async (pathToComponent = '') => {
|
|
10
|
+
const url = new URL(`${window?.location?.origin}/api/_test/bootstrap`);
|
|
11
|
+
url.search = new URLSearchParams({ pathToComponent });
|
|
12
|
+
|
|
13
|
+
const bootstrap = await fetch(url).then(async (response) => response.json());
|
|
14
|
+
|
|
15
|
+
// TODO: This needs to be more heavily leveraged vis a vis the settings file.
|
|
16
|
+
// Basically, w/o a server we need to be able to pipe in certain data. I *can*
|
|
17
|
+
// technically fetch data internally here and set it (may need some internal
|
|
18
|
+
// endpoints like /api/_test/bootstrap to do it so we can grab translations, etc).
|
|
19
|
+
//
|
|
20
|
+
// One thing we can do with something like test.route() is to auto-map the stuff
|
|
21
|
+
// that's on the window over to the return value from that function. So, we get back
|
|
22
|
+
// something like { html: '', req: {}, data: {}, user: {} }, etc. We want to account
|
|
23
|
+
// for things like having a test user in the config, too, so we're legitimately
|
|
24
|
+
// running requests against the app. Maybe have a fixed test user ID (or array of users)
|
|
25
|
+
// like config.test.users = [{ _id: 'abc123', emailAddress: '', password: '' }].
|
|
26
|
+
|
|
27
|
+
window.joystick = {};
|
|
28
|
+
window.joystick.settings = {}; // TODO
|
|
29
|
+
window.__joystick_data__ = bootstrap?.data || {};
|
|
30
|
+
window.__joystick_i18n__ = bootstrap?.translations || {};
|
|
31
|
+
window.__joystick_req__ = bootstrap?.req; // TODO
|
|
32
|
+
|
|
33
|
+
console.log(bootstrap);
|
|
34
|
+
};
|
|
35
|
+
|
|
9
36
|
const loadDOM = () => {
|
|
10
37
|
const dom = parseHTML(`
|
|
11
38
|
<html>
|
|
@@ -40,31 +67,7 @@ export default async (pathToComponent = '', options = {}) => {
|
|
|
40
67
|
origin: `http://localhost:${process.env.PORT}`,
|
|
41
68
|
};
|
|
42
69
|
|
|
43
|
-
|
|
44
|
-
url.search = new URLSearchParams({
|
|
45
|
-
pathToComponent,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const bootstrap = await fetch(url).then(async (response) => response.json());
|
|
49
|
-
|
|
50
|
-
// TODO: This needs to be more heavily leveraged vis a vis the settings file.
|
|
51
|
-
// Basically, w/o a server we need to be able to pipe in certain data. I *can*
|
|
52
|
-
// technically fetch data internally here and set it (may need some internal
|
|
53
|
-
// endpoints like /api/_test/bootstrap to do it so we can grab translations, etc).
|
|
54
|
-
//
|
|
55
|
-
// One thing we can do with something like test.route() is to auto-map the stuff
|
|
56
|
-
// that's on the window over to the return value from that function. So, we get back
|
|
57
|
-
// something like { html: '', req: {}, data: {}, user: {} }, etc. We want to account
|
|
58
|
-
// for things like having a test user in the config, too, so we're legitimately
|
|
59
|
-
// running requests against the app. Maybe have a fixed test user ID (or array of users)
|
|
60
|
-
// like config.test.users = [{ _id: 'abc123', emailAddress: '', password: '' }].
|
|
61
|
-
|
|
62
|
-
console.log(bootstrap);
|
|
63
|
-
|
|
64
|
-
window.joystick = {};
|
|
65
|
-
window.__joystick_data__ = bootstrap?.data || {};
|
|
66
|
-
window.__joystick_i18n__ = bootstrap?.translations || {};
|
|
67
|
-
window.__joystick_req__ = { params: {}, query: {}, context: { user: {} } };
|
|
70
|
+
await bootstrapWindow(pathToComponent);
|
|
68
71
|
|
|
69
72
|
// NOTE: Force default to true as that's the prescribed pattern for
|
|
70
73
|
// Joystick component files.
|