@joystick.js/test-canary 0.0.0-canary.72 → 0.0.0-canary.74

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 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(`
1
+ import{parseHTML as l}from"linkedom";import d from"@joystick.js/ui-canary";import i 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 i(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},_=()=>{const e=l(`
2
2
  <html>
3
3
  <head></head>
4
4
  <body>
@@ -6,4 +6,4 @@ import{parseHTML as i}from"linkedom";import d from"@joystick.js/ui-canary";impor
6
6
  <meta name="csrf" content="joystick_test" />
7
7
  </body>
8
8
  </html>
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};
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 k=async(e="",r={})=>{const o=_();window.fetch=i,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),renderToHTML:()=>{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{k as default};
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import r from"./test.js";import o from"./helpers/api/index.js";import e from"./helpers/render/index.js";import t 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:r.after,afterEach:r.afterEach,api:o,before:r.before,beforeEach:r.beforeEach,render:e,databases:t,email:m,load:a,queues:f,routes:p,that:r.that,uploaders:i,websockets:s};export{w as default};
package/dist/test.js CHANGED
@@ -1 +1 @@
1
- import e from"ava";class a{constructor(){}before(r=null){return e.serial.before(r)}beforeEach(r=null){return e.beforeEach(r)}after(r=null){return e.after.always(r)}afterEach(r=null){return e.afterEach.always(r)}that(r="",t=null){return e.serial(r,t)}}var u=new a;export{u as default};
1
+ import r from"ava";let n=[];r.after.always(()=>{console.log("CLEANUP USERS")});class l{constructor(){}signup(e=[]){}login(e=[]){}accounts(){return{signup:this.signup,login:this.login}}before(e=null){return r.serial.before(e)}beforeEach(e=null){return r.beforeEach(e)}after(e=null){return r.after.always(e)}afterEach(e=null){return r.afterEach.always(e)}that(e="",t=null){return r.serial(e,t)}}var u=new l;export{u 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.72",
4
+ "version": "0.0.0-canary.74",
5
5
  "description": "Isomorphic testing framework for the Joystick JavaScript framework.",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
@@ -12,25 +12,11 @@ const bootstrapWindow = async (pathToComponent = '') => {
12
12
 
13
13
  const bootstrap = await fetch(url).then(async (response) => response.json());
14
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
15
  window.joystick = {};
28
16
  window.joystick.settings = {}; // TODO
29
17
  window.__joystick_data__ = bootstrap?.data || {};
30
18
  window.__joystick_i18n__ = bootstrap?.translations || {};
31
19
  window.__joystick_req__ = bootstrap?.req; // TODO
32
-
33
- console.log(bootstrap);
34
20
  };
35
21
 
36
22
  const loadDOM = () => {
@@ -84,7 +70,7 @@ export default async (pathToComponent = '', options = {}) => {
84
70
  data: async (input = {}) => {
85
71
  return component?.data?.refetch(input);
86
72
  },
87
- render: () => {
73
+ renderToHTML: () => {
88
74
  const html = component?.renderToHTML();
89
75
  const whenRegex = new RegExp('<when>|</when>', 'g');
90
76
  return html?.wrapped?.replace(whenRegex, '')?.replace(/\n|\t/g, ' ')?.replace(/> *</g, '><');
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 component from './helpers/component/index.js';
3
+ import render from './helpers/render/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
- component,
18
+ render,
19
19
  databases,
20
20
  email,
21
21
  load,
package/src/test.js CHANGED
@@ -1,10 +1,36 @@
1
1
  import test from 'ava';
2
2
 
3
+ let users = [];
4
+
5
+ // NOTE: Internal cleaup to avoid confusing tests.
6
+ test.after.always(() => {
7
+ console.log('CLEANUP USERS');
8
+ });
9
+
3
10
  class Test {
4
11
  constructor() {
5
12
 
6
13
  }
7
14
 
15
+ signup(users = []) {
16
+ // TODO: As users are created in DB, push them into an array here in the test.
17
+ }
18
+
19
+ login(users = []) {
20
+ // TODO: When logging in, expect that node will return an object with a joystickLoginToken,
21
+ // joystickTokenExpiresAt, and joystickSession "cookie." These should be made accessible
22
+ // to the individual test so they can be passed in when running tests.
23
+ //
24
+ // test.
25
+ }
26
+
27
+ accounts() {
28
+ return {
29
+ signup: this.signup,
30
+ login: this.login,
31
+ };
32
+ }
33
+
8
34
  before(callback = null) {
9
35
  // NOTE: Prefer serial before to async to align better with
10
36
  // expectations and avoid confusion.
File without changes
File without changes