@joystick.js/test-canary 0.0.0-canary.58 → 0.0.0-canary.59
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 m}from"linkedom";import d from"@joystick.js/ui-canary";import i from"node-fetch";import p from"./event.js";import u from"../load/index.js";const w=()=>{const n=m(`
|
|
2
2
|
<html>
|
|
3
3
|
<head></head>
|
|
4
4
|
<body>
|
|
@@ -6,4 +6,4 @@ import{parseHTML as s}from"linkedom";import m from"@joystick.js/ui-canary";impor
|
|
|
6
6
|
<meta name="csrf" content="joystick_test" />
|
|
7
7
|
</body>
|
|
8
8
|
</html>
|
|
9
|
-
`),{window:r,document:e,Element:
|
|
9
|
+
`),{window:r,document:e,Element:a,Event:s,HTMLElement:t}=n;return global.window=r,global.document=e,global.HTMLElement=t,global.Element=a,global.Event=s,global.console={log:console.log,warn:console.warn,error:console.error},n};var b=async(n="",r={})=>{const e=w();window.fetch=i,window.location={origin:`http://localhost:${process.env.PORT}`};const a=await i(`${origin}/api/_test/bootstrap`).then(async o=>o.json());console.log({bootstrap:a}),window.joystick={},window.__joystick_data__={},window.__joystick_req__={params:{},query:{},context:{user:{}}};const s=await u(n,{default:!0}),t=d.mount(s,r?.props||{},e?.document.querySelector("#app"));return t.isTest=!0,{dom:e,instance:t,test:{data:async(o={})=>t?.data?.refetch(o),method:(o="",...l)=>{const c=t?.methods[o];return c?c(...l):null},event:(o="",l="")=>p(o,l,e)}}};export{b as default};
|
package/package.json
CHANGED
|
@@ -33,16 +33,20 @@ const loadDOM = () => {
|
|
|
33
33
|
|
|
34
34
|
export default async (pathToComponent = '', options = {}) => {
|
|
35
35
|
const dom = loadDOM();
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
window.fetch = fetch;
|
|
38
38
|
window.location = {
|
|
39
39
|
origin: `http://localhost:${process.env.PORT}`,
|
|
40
40
|
};
|
|
41
|
+
|
|
42
|
+
const bootstrap = await fetch(`${origin}/api/_test/bootstrap`).then(async (response) => response.json());
|
|
43
|
+
|
|
44
|
+
console.log({ bootstrap });
|
|
41
45
|
|
|
42
46
|
// TODO: This needs to be more heavily leveraged vis a vis the settings file.
|
|
43
47
|
// Basically, w/o a server we need to be able to pipe in certain data. I *can*
|
|
44
48
|
// technically fetch data internally here and set it (may need some internal
|
|
45
|
-
// endpoints like /api/_test/
|
|
49
|
+
// endpoints like /api/_test/bootstrap to do it so we can grab translations, etc).
|
|
46
50
|
//
|
|
47
51
|
// One thing we can do with something like test.route() is to auto-map the stuff
|
|
48
52
|
// that's on the window over to the return value from that function. So, we get back
|
|
@@ -50,7 +54,7 @@ export default async (pathToComponent = '', options = {}) => {
|
|
|
50
54
|
// for things like having a test user in the config, too, so we're legitimately
|
|
51
55
|
// running requests against the app. Maybe have a fixed test user ID (or array of users)
|
|
52
56
|
// like config.test.users = [{ _id: 'abc123', emailAddress: '', password: '' }].
|
|
53
|
-
|
|
57
|
+
|
|
54
58
|
window.joystick = {};
|
|
55
59
|
window.__joystick_data__ = {};
|
|
56
60
|
window.__joystick_req__ = { params: {}, query: {}, context: { user: {} } };
|
|
@@ -59,10 +63,10 @@ export default async (pathToComponent = '', options = {}) => {
|
|
|
59
63
|
// Joystick component files.
|
|
60
64
|
const Component = await load(pathToComponent, { default: true });
|
|
61
65
|
const component = joystick.mount(Component, options?.props || {}, dom?.document.querySelector('#app'));
|
|
62
|
-
|
|
66
|
+
|
|
63
67
|
// NOTE: Used internally in @joystick.js/ui to control component behavior.
|
|
64
68
|
component.isTest = true;
|
|
65
|
-
|
|
69
|
+
|
|
66
70
|
return {
|
|
67
71
|
dom,
|
|
68
72
|
instance: component,
|
|
@@ -72,11 +76,11 @@ export default async (pathToComponent = '', options = {}) => {
|
|
|
72
76
|
},
|
|
73
77
|
method: (methodName = '', ...methodArgs) => {
|
|
74
78
|
const methodToCall = component?.methods[methodName];
|
|
75
|
-
|
|
79
|
+
|
|
76
80
|
if (!methodToCall) {
|
|
77
81
|
return null;
|
|
78
82
|
}
|
|
79
|
-
|
|
83
|
+
|
|
80
84
|
return methodToCall(...methodArgs);
|
|
81
85
|
},
|
|
82
86
|
event: (eventType = '', eventTarget = '') => {
|