@joystick.js/test-canary 0.0.0-canary.70 → 0.0.0-canary.71

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 m}from"linkedom";import w from"@joystick.js/ui-canary";import d from"node-fetch";import{URL as p,URLSearchParams as u}from"url";import h from"./event.js";import _ from"../load/index.js";const g=()=>{const t=m(`
1
+ import{parseHTML as i}from"linkedom";import d from"@joystick.js/ui-canary";import l from"node-fetch";import{URL as m,URLSearchParams as w}from"url";import p from"./event.js";import h from"../load/index.js";const u=async()=>{const e=new m(`${window?.location?.origin}/api/_test/bootstrap`);e.search=new w({pathToComponent});const t=await l(e).then(async n=>n.json());window.joystick={},window.joystick.settings={},window.__joystick_data__=t?.data||{},window.__joystick_i18n__=t?.translations||{},window.__joystick_req__=t?.req,console.log(t)},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:c,document:e,Element:s,Event:n,HTMLElement:l}=t;return global.window=c,global.document=e,global.HTMLElement=l,global.Element=s,global.Event=n,global.console={log:console.log,warn:console.warn,error:console.error},t};var T=async(t="",c={})=>{const e=g();window.fetch=d,window.location={origin:`http://localhost:${process.env.PORT}`};const s=new p(`${window?.location?.origin}/api/_test/bootstrap`);s.search=new u({pathToComponent:t});const n=await d(s).then(async o=>o.json());console.log(n),window.joystick={},window.__joystick_data__=n?.data||{},window.__joystick_i18n__=n?.translations||{},window.__joystick_req__={params:{},query:{},context:{user:{}}};const l=await _(t,{default:!0}),r=w.mount(l,c?.props||{},e?.document.querySelector("#app"));return r.isTest=!0,{dom:e,instance:r,test:{data:async(o={})=>r?.data?.refetch(o),render:()=>{const o=r?.renderToHTML(),a=new RegExp("<when>|</when>","g");return o?.wrapped?.replace(a,"")?.replace(/\n|\t/g," ")?.replace(/> *</g,"><")},method:(o="",...a)=>{const i=r?.methods[o];return i?i(...a):null},event:(o="",a="")=>h(o,a,e)}}};export{T as default};
9
+ `),{window:t,document:n,Element:s,Event:r,HTMLElement:o}=e;return global.window=t,global.document=n,global.HTMLElement=o,global.Element=s,global.Event=r,global.console={log:console.log,warn:console.warn,error:console.error},e};var k=async(e="",t={})=>{const n=g();window.fetch=l,window.location={origin:`http://localhost:${process.env.PORT}`},await u();const s=await h(e,{default:!0}),r=d.mount(s,t?.props||{},n?.document.querySelector("#app"));return r.isTest=!0,{dom:n,instance:r,test:{data:async(o={})=>r?.data?.refetch(o),render:()=>{const o=r?.renderToHTML(),a=new RegExp("<when>|</when>","g");return o?.wrapped?.replace(a,"")?.replace(/\n|\t/g," ")?.replace(/> *</g,"><")},method:(o="",...a)=>{const c=r?.methods[o];return c?c(...a):null},event:(o="",a="")=>p(o,a,n)}}};export{k as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/test-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.70",
4
+ "version": "0.0.0-canary.71",
5
5
  "description": "Isomorphic testing framework for the Joystick JavaScript framework.",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
@@ -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 () => {
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
- const url = new URL(`${window?.location?.origin}/api/_test/bootstrap`);
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();
68
71
 
69
72
  // NOTE: Force default to true as that's the prescribed pattern for
70
73
  // Joystick component files.