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