From e84b66940259592ddafe70c0440b28e5b37eade7 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 18 Mar 2021 16:28:40 -0400 Subject: [PATCH 01/12] use new syn prelease and attempt to get some tests passing --- browser/actions.js | 22 ++++++++++------------ package.json | 2 +- site/examples/resources/funcunit.js | 4 ++-- test/qunit1_tests/actions_test.js | 11 +++++++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/browser/actions.js b/browser/actions.js index 02da74a5..3100b821 100644 --- a/browser/actions.js +++ b/browser/actions.js @@ -76,9 +76,9 @@ var clicks = [ } var selector = this.selector; FuncUnit.add({ - method: function(success, error){ + method: async function(success, error){ options = options || {}; - syn("_" + name, this.bind[0], options, success); + await syn("_" + name, this.bind[0], options, success); }, success: success, error: "Could not " + name + " '" + this.selector+"'", @@ -146,9 +146,8 @@ $.extend(FuncUnit.prototype, { text = "[ctrl]a[ctrl-up]\b" } FuncUnit.add({ - method : function(success, error){ - syn("_type", this.bind[0], text, success); - + method : async function(success, error){ + await syn("_type", this.bind[0], text, success); }, success : success, error : "Could not type " + text + " into " + this.selector, @@ -177,9 +176,8 @@ $.extend(FuncUnit.prototype, { keys = "[ctrl]a[ctrl-up]\b" } FuncUnit.add({ - method : function(success, error){ - syn("_type", this.bind[0], keys, success); - + method : async function(success, error){ + await syn("_type", this.bind[0], keys, success); }, success : success, error : "Could not send the keys " + keys + " into " + this.selector, @@ -266,8 +264,8 @@ $.extend(FuncUnit.prototype, { var selector = this.selector; FuncUnit.add({ - method: function(success, error){ - syn("_drag", this.bind[0], options, success); + method: async function(success, error){ + await syn("_drag", this.bind[0], options, success); }, success: success, error: "Could not drag " + this.selector, @@ -334,8 +332,8 @@ $.extend(FuncUnit.prototype, { var selector = this.selector; FuncUnit.add({ - method: function(success, error){ - syn("_move", this.bind[0], options, success); + method: async function(success, error){ + await syn("_move", this.bind[0], options, success); }, success: success, error: "Could not move " + this.selector, diff --git a/package.json b/package.json index b163e8a9..7f617bd9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "main": "dist/cjs/funcunit.js", "dependencies": { - "syn": "^0.14.1" + "syn": "^1.0.0-pre.2" }, "devDependencies": { "can-define": "^0.8.0", diff --git a/site/examples/resources/funcunit.js b/site/examples/resources/funcunit.js index 7ac96cb9..5e95f45f 100644 --- a/site/examples/resources/funcunit.js +++ b/site/examples/resources/funcunit.js @@ -242,8 +242,8 @@ var __m2 = (function(){ } return res; }, - click: function( options, element, callback ) { - Syn('click!', options, element, callback); + click: async function( options, element, callback ) { + await Syn('click!', options, element, callback); }, /** * @attribute defaults diff --git a/test/qunit1_tests/actions_test.js b/test/qunit1_tests/actions_test.js index 8d3009de..9759f770 100644 --- a/test/qunit1_tests/actions_test.js +++ b/test/qunit1_tests/actions_test.js @@ -7,10 +7,13 @@ QUnit.module("scroll", { } }) -test("scroll on click", function(){ - F('#innerdiv').click() - F("#scrolldiv").scrollTop(100, "Scrolled down 100") - F("#scrolldiv").scrollLeft(100, "Scrolled left 100") +test("scroll on click", async function(){ + try { + await F('#innerdiv').click() + } catch (e) { + } + await F("#scrolldiv").scrollTop(100, "Scrolled down 100") + await F("#scrolldiv").scrollLeft(100, "Scrolled left 100") }) test("auto scrollleft", function(){ From 44a4fa6d20644d516aa610ad3795aa7e0d3400bd Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Fri, 19 Mar 2021 13:20:46 -0400 Subject: [PATCH 02/12] update async --- browser/actions.js | 10 +++++----- site/examples/resources/funcunit.js | 4 ++-- test/adapters/jasmine.js | 8 ++++---- test/adapters/jasmine2.js | 8 ++++---- test/adapters/qunit.js | 8 ++++---- test/adapters/qunit2.js | 8 ++++---- test/qunit1_tests/actions_test.js | 7 +++---- test/qunit1_tests/funcunit_test.js | 4 ++-- test/qunit2_tests/actions_test.js | 20 ++++++++++---------- 9 files changed, 38 insertions(+), 39 deletions(-) diff --git a/browser/actions.js b/browser/actions.js index 3100b821..19011c10 100644 --- a/browser/actions.js +++ b/browser/actions.js @@ -78,7 +78,7 @@ var clicks = [ FuncUnit.add({ method: async function(success, error){ options = options || {}; - await syn("_" + name, this.bind[0], options, success); + await syn[name](this.bind[0], options); }, success: success, error: "Could not " + name + " '" + this.selector+"'", @@ -147,7 +147,7 @@ $.extend(FuncUnit.prototype, { } FuncUnit.add({ method : async function(success, error){ - await syn("_type", this.bind[0], text, success); + await syn.type(this.bind[0], text); }, success : success, error : "Could not type " + text + " into " + this.selector, @@ -177,7 +177,7 @@ $.extend(FuncUnit.prototype, { } FuncUnit.add({ method : async function(success, error){ - await syn("_type", this.bind[0], keys, success); + await syn.type(this.bind[0], keys); }, success : success, error : "Could not send the keys " + keys + " into " + this.selector, @@ -265,7 +265,7 @@ $.extend(FuncUnit.prototype, { var selector = this.selector; FuncUnit.add({ method: async function(success, error){ - await syn("_drag", this.bind[0], options, success); + await syn.drag(this.bind[0], options); }, success: success, error: "Could not drag " + this.selector, @@ -333,7 +333,7 @@ $.extend(FuncUnit.prototype, { var selector = this.selector; FuncUnit.add({ method: async function(success, error){ - await syn("_move", this.bind[0], options, success); + await syn.move(this.bind[0], options); }, success: success, error: "Could not move " + this.selector, diff --git a/site/examples/resources/funcunit.js b/site/examples/resources/funcunit.js index 5e95f45f..7ac96cb9 100644 --- a/site/examples/resources/funcunit.js +++ b/site/examples/resources/funcunit.js @@ -242,8 +242,8 @@ var __m2 = (function(){ } return res; }, - click: async function( options, element, callback ) { - await Syn('click!', options, element, callback); + click: function( options, element, callback ) { + Syn('click!', options, element, callback); }, /** * @attribute defaults diff --git a/test/adapters/jasmine.js b/test/adapters/jasmine.js index 445bf35b..6fe6735a 100644 --- a/test/adapters/jasmine.js +++ b/test/adapters/jasmine.js @@ -19,9 +19,9 @@ describe('Adapters', function() { $('.clickme, .clickresult').remove(); }); - it('should use the jasmine adapter', function() { - F.wait(1000); - F('.clickme').click(); - F('.clickresult').text('clicked'); + it('should use the jasmine adapter', async function() { + await F.wait(1000); + await F('.clickme').click(); + await F('.clickresult').text('clicked'); }); }); diff --git a/test/adapters/jasmine2.js b/test/adapters/jasmine2.js index db132843..331802ef 100644 --- a/test/adapters/jasmine2.js +++ b/test/adapters/jasmine2.js @@ -21,10 +21,10 @@ describe('Adapters', function() { $('.clickme, .clickresult').remove(); }); - it('should use the jasmine adapter', function(done) { - F.wait(1000); - F('.clickme').click(); - F('.clickresult').text('clicked'); + it('should use the jasmine adapter', async function(done) { + await F.wait(1000); + await F('.clickme').click(); + await F('.clickresult').text('clicked'); F(function() { expect($('.clickresult').text()).toBe('clicked'); diff --git a/test/adapters/qunit.js b/test/adapters/qunit.js index 8402aa41..f2f20216 100644 --- a/test/adapters/qunit.js +++ b/test/adapters/qunit.js @@ -13,8 +13,8 @@ QUnit.module('Adapters', { } }); -test('QUnit adapter test', function() { - F.wait(1000); - F('.clickme').click(); - F('.clickresult').text('clicked', 'clicked the link'); +test('QUnit adapter test', async function() { + await F.wait(1000); + await F('.clickme').click(); + await F('.clickresult').text('clicked', 'clicked the link'); }); diff --git a/test/adapters/qunit2.js b/test/adapters/qunit2.js index ab144c0e..9bb4616d 100644 --- a/test/adapters/qunit2.js +++ b/test/adapters/qunit2.js @@ -15,10 +15,10 @@ QUnit.module("Adapters 2", { } }); -QUnit.test("QUnit adapter test", function(assert) { - F.wait(1000); - F(".clickme").click(); - F(".clickresult").text("clicked", "clicked the link"); +QUnit.test("QUnit adapter test", async function(assert) { + await F.wait(1000); + await F(".clickme").click(); + await F(".clickresult").text("clicked", "clicked the link"); }); QUnit.module("QUnit 2 adapter unit tests"); diff --git a/test/qunit1_tests/actions_test.js b/test/qunit1_tests/actions_test.js index 9759f770..0c7fc8c0 100644 --- a/test/qunit1_tests/actions_test.js +++ b/test/qunit1_tests/actions_test.js @@ -8,12 +8,11 @@ QUnit.module("scroll", { }) test("scroll on click", async function(){ - try { - await F('#innerdiv').click() - } catch (e) { - } + // QUnit.stop(); + await F('#innerdiv').click() await F("#scrolldiv").scrollTop(100, "Scrolled down 100") await F("#scrolldiv").scrollLeft(100, "Scrolled left 100") + // QUnit.start(); }) test("auto scrollleft", function(){ diff --git a/test/qunit1_tests/funcunit_test.js b/test/qunit1_tests/funcunit_test.js index 307cc42f..f1ede854 100644 --- a/test/qunit1_tests/funcunit_test.js +++ b/test/qunit1_tests/funcunit_test.js @@ -21,8 +21,8 @@ test("Iframe access", function(){ }); }) -test("typing alt and shift characters", function(){ - F('#typehere').type("@", function(){ +test("typing alt and shift characters", async function(){ + await F('#typehere').type("@", function(){ equal(F('#typehere').val(), "@", "types weird chars" ); }) }) diff --git a/test/qunit2_tests/actions_test.js b/test/qunit2_tests/actions_test.js index 6e1e3049..0cc179db 100644 --- a/test/qunit2_tests/actions_test.js +++ b/test/qunit2_tests/actions_test.js @@ -7,18 +7,18 @@ QUnit.module("scroll", { } }) -QUnit.test("scroll on click", function(){ - F('#innerdiv').click() - F("#scrolldiv").scrollTop(100, "Scrolled down 100") - F("#scrolldiv").scrollLeft(100, "Scrolled left 100") +QUnit.test("scroll on click", async function(){ + await F('#innerdiv').click() + await F("#scrolldiv").scrollTop(100, "Scrolled down 100") + await F("#scrolldiv").scrollLeft(100, "Scrolled left 100") }) -QUnit.test("auto scrollleft", function(){ - F("#scrolldiv").scroll('left', 100) - F('#scrolldiv').scrollLeft(100, 'scroll left worked') +QUnit.test("auto scrollleft", async function(){ + await F("#scrolldiv").scroll('left', 100) + await F('#scrolldiv').scrollLeft(100, 'scroll left worked') }) -QUnit.test("auto scrolldown", function(){ - F("#scrolldiv").scroll('top', 100) - F('#scrolldiv').scrollTop(100, 'scroll top worked') +QUnit.test("auto scrolldown", async function(){ + await F("#scrolldiv").scroll('top', 100) + await F('#scrolldiv').scrollTop(100, 'scroll top worked') }) From 13c148524ccb263f8a987ddea6efbbc5a68a950b Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Mon, 22 Mar 2021 13:07:24 -0400 Subject: [PATCH 03/12] removes unused jquery imports --- browser/core.js | 1 - browser/getters.js | 1 - browser/traversers.js | 1 - 3 files changed, 3 deletions(-) diff --git a/browser/core.js b/browser/core.js index ab4324e3..d6b71f89 100644 --- a/browser/core.js +++ b/browser/core.js @@ -1,4 +1,3 @@ -var jQuery = require("funcunit/browser/jquery"); var oldFuncUnit = require("funcunit/browser/init"); var FuncUnit = oldFuncUnit.jQuery.sub(); diff --git a/browser/getters.js b/browser/getters.js index a9013344..f5ae95de 100644 --- a/browser/getters.js +++ b/browser/getters.js @@ -1,4 +1,3 @@ -var $ = require("funcunit/browser/jquery"); var FuncUnit = require("funcunit/browser/core"); /** diff --git a/browser/traversers.js b/browser/traversers.js index 62bdf251..231bb8be 100644 --- a/browser/traversers.js +++ b/browser/traversers.js @@ -1,4 +1,3 @@ -var $ = require("funcunit/browser/jquery"); var FuncUnit = require("funcunit/browser/core"); /** From de3886ad8f39a75f97b254beb9905de53227f6c6 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Tue, 23 Mar 2021 16:38:33 -0400 Subject: [PATCH 04/12] new files for updated functions --- browser/getters.js | 1 + funcunit.js | 1 + src/core.js | 77 +++++++++++++++++++++++++++++++++++++++++++ src/getters.js | 69 ++++++++++++++++++++++++++++++++++++++ test/adapters/none.js | 18 ++++++---- 5 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 src/core.js create mode 100644 src/getters.js diff --git a/browser/getters.js b/browser/getters.js index f5ae95de..a9013344 100644 --- a/browser/getters.js +++ b/browser/getters.js @@ -1,3 +1,4 @@ +var $ = require("funcunit/browser/jquery"); var FuncUnit = require("funcunit/browser/core"); /** diff --git a/funcunit.js b/funcunit.js index 8780c561..4c4b7248 100644 --- a/funcunit.js +++ b/funcunit.js @@ -1,4 +1,5 @@ var FuncUnit = require("funcunit/browser/core"); +// var FuncUnit = require("funcunit/src/core"); require("funcunit/browser/adapters/"); require("funcunit/browser/open"); diff --git a/src/core.js b/src/core.js new file mode 100644 index 00000000..e02518e0 --- /dev/null +++ b/src/core.js @@ -0,0 +1,77 @@ +var oldFuncUnit = require("funcunit/browser/init"); +var origFuncUnit = oldFuncUnit.jQuery.sub(); +var FuncUnit = oldFuncUnit.jQuery.sub(); + +FuncUnit = function ( selector, context ) { + + this.selector = selector; + this.frame = context && context.frame ? context.frame : context; + this.forceSync = context && context.forceSync ? context.forceSync : undefined + this.isSyncOnly = typeof forceSync === 'boolean' ? forceSync : false; + + if (typeof selector === 'function') { + return FuncUnit.wait(0, selector); + } + + if (this.isSyncOnly) { + return performSyncQuery(this.selector, this.frame); + } else { + performAsyncQuery(this.selector, this.frame, this); + return performSyncQuery(this.selector, this.frame); + } +} + + + + +// Add async query to FuncUnit queue +var performAsyncQuery = function ( selector, frame, self ) { + FuncUnit.add({ + method: function () {}, + error: `selector failed: ${selector}`, + type: 'query' + }); +} + + + + +// Perform sync query +var performSyncQuery = function ( selector, frame ) { + const origFrame = frame; + + if (FuncUnit.win) { + frame = getContext(frame); + } + + const result = new origFuncUnit.fn.init( selector, frame, true ); + result.frame = origFrame; + + return result; +} + + + + +// helper +var getContext = function ( context ) { + let frame, frames, selector; + + if (typeof context === 'number' || typeof context === 'string') { + selector = typeof context === "number" ? "iframe:eq(" + context + ")" : "iframe[name='" + context + "']"; + frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); + } else { + frame = FuncUnit.win.document.documentElement; + } + + return frame; +} + + + + +oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit); + +FuncUnit.prototype = origFuncUnit.prototype; + +module.exports = FuncUnit; diff --git a/src/getters.js b/src/getters.js new file mode 100644 index 00000000..0064f587 --- /dev/null +++ b/src/getters.js @@ -0,0 +1,69 @@ +var $ = require("funcunit/browser/jquery"); +var FuncUnit = require("funcunit/browser/core"); + +FuncUnit.funcs = { + size: 0, + attr: 1, + hasClass: 1, + html: 0, + text: 0, + val: 0, + css: 1, + prop: 1, + offset: 0, + position: 0, + scrollTop: 0, + scrollLeft: 0, + height: 0, + width: 0, + innerHeight: 0, + innerWidth: 0, + outerHeight: 0, + outerWidth: 0 +}; + +function makeFunction ( name, expectedNumberOfArgs ) { + + FuncUnit.prototype[name] = function () { + const timeToWait = 1000; + const argsToReadWith = arguments.slice(0, expectedNumberOfArgs); + const argsToCheckAgainst = arguments[expectedNumberOfArgs + 1]; + const startTime = new Date(); + + pollForValue( function() { + if (this.elements[name](...arguments.slice(0,1)) === arguments[1]) { + + } + }) + + return new Promise((resolve, reject) => { + + const check = () => { + return $(this.selector, this.frame)[name](...argsToReadWith) === argToCheckAgainst; + }; + + const checker = () => { + if (new Date() > startTime + timeToWait) { + clearTimeout(); + reject(new Error()); + } + + if (check()) { + clearTimeout(); + resolve(); + } else { + setTimeout(checker, 10); + } + }; + + setTimeout(checker); + }); + }; + +} + +for (const prop in FuncUnit.funcs) { + makeFunction(prop, FuncUnit.funcs[prop]); +} + +module.exports = FuncUnit; diff --git a/test/adapters/none.js b/test/adapters/none.js index 1f98e89e..f8f7e79f 100644 --- a/test/adapters/none.js +++ b/test/adapters/none.js @@ -15,13 +15,17 @@ QUnit.module('Adapters', { } }); -test('QUnit with no adapter test', function() { +test('QUnit with no adapter test', async function() { stop(); - F.wait(1000); - F('.clickme').click(); - F('.clickresult').text('clicked', function() { - ok('clicked the text'); - start(); - }); + await F.wait(1000); + console.log('waited'); + + await F('.clickme').click(); + console.log('clicked'); + + await F('.clickresult').text('clicked'); + + ok('clicked the text'); + start(); }); From bde1a09327ba2f7214fcc30e56e548ee6695c0d3 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 25 Mar 2021 15:55:12 -0400 Subject: [PATCH 05/12] test function --- {src => new-src}/core.js | 33 +++++++++++++++------- {src => new-src}/getters.js | 0 new-src/playground.js | 4 +++ new-src/traversers.js | 56 +++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) rename {src => new-src}/core.js (59%) rename {src => new-src}/getters.js (100%) create mode 100644 new-src/playground.js create mode 100644 new-src/traversers.js diff --git a/src/core.js b/new-src/core.js similarity index 59% rename from src/core.js rename to new-src/core.js index e02518e0..28e64578 100644 --- a/src/core.js +++ b/new-src/core.js @@ -23,28 +23,41 @@ FuncUnit = function ( selector, context ) { +// https://stackoverflow.com/questions/4754560/help-understanding-jquerys-jquery-fn-init-why-is-init-in-fn -// Add async query to FuncUnit queue -var performAsyncQuery = function ( selector, frame, self ) { + +const performAsyncQuery = function ( selector, frame, self ) { FuncUnit.add({ - method: function () {}, - error: `selector failed: ${selector}`, + method: function ( success, error ) { + this.frame = frame; + this.selector = selector; + + if (FuncUnit.win) { + frame = getContext(frame); + } + + // this.bind = new origFuncUnit( selector, frame, true ); + this.bind = new origFuncUnit.fn.init( selector, frame, true ); + success(); + return this; + }, + error: `Selector failed: ${selector}`, type: 'query' }); } - -// Perform sync query -var performSyncQuery = function ( selector, frame ) { +const performSyncQuery = function ( selector, frame ) { const origFrame = frame; if (FuncUnit.win) { frame = getContext(frame); } + // const result = new origFuncUnit( selector, frame, true ); const result = new origFuncUnit.fn.init( selector, frame, true ); + result.frame = origFrame; return result; @@ -53,13 +66,13 @@ var performSyncQuery = function ( selector, frame ) { -// helper -var getContext = function ( context ) { +const getContext = function ( context ) { let frame, frames, selector; if (typeof context === 'number' || typeof context === 'string') { - selector = typeof context === "number" ? "iframe:eq(" + context + ")" : "iframe[name='" + context + "']"; + selector = typeof context === 'number' ? `iframe:eq(${context})` : `iframe[name='${context}']`; frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); + frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement; } else { frame = FuncUnit.win.document.documentElement; } diff --git a/src/getters.js b/new-src/getters.js similarity index 100% rename from src/getters.js rename to new-src/getters.js diff --git a/new-src/playground.js b/new-src/playground.js new file mode 100644 index 00000000..435896dc --- /dev/null +++ b/new-src/playground.js @@ -0,0 +1,4 @@ +function myFunc () { + var variable = 1; + this.variable = 2; +} diff --git a/new-src/traversers.js b/new-src/traversers.js new file mode 100644 index 00000000..6f420ef1 --- /dev/null +++ b/new-src/traversers.js @@ -0,0 +1,56 @@ +var FuncUnit = require("funcunit/browser/core"); + +const traversers = [ + 'closest', + 'next', + 'prev', + 'siblings', + 'last', + 'first', + 'find' +]; + + + + +function makeTraverser ( name ) { + + const orig = FuncUnit.prototype[name]; + + FuncUnit.prototype[name] = function ( selector ) { + + const args = arguments; + + // nodeType 9 is document node + if (FuncUnit.win && this[0] && this[0].parentNode && this[0].parentNode.nodeType !== 9) { + + FuncUnit.add({ + method: function ( success, error ) { + const newBindFunc = orig.apply(this.bind, args); + newBindFunc.prevTraverser = name; + newBindFunc.prevTraverserSelector = selector; + success(newBindFunc); + }, + error: `Could not traverse: ${name} ${selector}`, + bind: this + }); + } + + // returns jquery function with this context & arguments + // return orig.apply(this, args); + + return new Promise((resolve, reject) => { + + resolve(orig.apply(this, args)); + + }); + } + +} + + + +traversers.forEach( traverser => makeTraverser(traverser) ); + + +module.exports = FuncUnit; From 08ba921d7bf95f0496c17bd07544d386f841333c Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Fri, 26 Mar 2021 14:36:08 -0400 Subject: [PATCH 06/12] test --- new-src/core.js | 144 +++++++++++++++++++++++---------------- test/new-tests/test.html | 18 +++++ test/new-tests/test.js | 24 +++++++ 3 files changed, 128 insertions(+), 58 deletions(-) create mode 100644 test/new-tests/test.html create mode 100644 test/new-tests/test.js diff --git a/new-src/core.js b/new-src/core.js index 28e64578..e9d10d45 100644 --- a/new-src/core.js +++ b/new-src/core.js @@ -1,90 +1,118 @@ -var oldFuncUnit = require("funcunit/browser/init"); -var origFuncUnit = oldFuncUnit.jQuery.sub(); -var FuncUnit = oldFuncUnit.jQuery.sub(); -FuncUnit = function ( selector, context ) { - this.selector = selector; - this.frame = context && context.frame ? context.frame : context; - this.forceSync = context && context.forceSync ? context.forceSync : undefined - this.isSyncOnly = typeof forceSync === 'boolean' ? forceSync : false; - if (typeof selector === 'function') { - return FuncUnit.wait(0, selector); - } +class FuncUnit extends Promise { - if (this.isSyncOnly) { - return performSyncQuery(this.selector, this.frame); - } else { - performAsyncQuery(this.selector, this.frame, this); - return performSyncQuery(this.selector, this.frame); + constructor(selector, context) { + super((resolve, reject) => { + el = document.querySelectorAll(selector); + if (el) { + resolve(el); + } else { + reject('Element not found'); + } + }) + } + + async click() { + const element = await this; + await syn.click(element); } } +module.exports = FuncUnit; -// https://stackoverflow.com/questions/4754560/help-understanding-jquerys-jquery-fn-init-why-is-init-in-fn -const performAsyncQuery = function ( selector, frame, self ) { - FuncUnit.add({ - method: function ( success, error ) { - this.frame = frame; - this.selector = selector; - if (FuncUnit.win) { - frame = getContext(frame); - } +// var oldFuncUnit = require("funcunit/browser/init"); +// var origFuncUnit = oldFuncUnit.jQuery.sub(); +// var FuncUnit = oldFuncUnit.jQuery.sub(); - // this.bind = new origFuncUnit( selector, frame, true ); - this.bind = new origFuncUnit.fn.init( selector, frame, true ); - success(); - return this; - }, - error: `Selector failed: ${selector}`, - type: 'query' - }); -} +// FuncUnit = function ( selector, context ) { +// this.selector = selector; +// this.frame = context && context.frame ? context.frame : context; +// this.forceSync = context && context.forceSync ? context.forceSync : undefined +// this.isSyncOnly = typeof forceSync === 'boolean' ? forceSync : false; +// if (typeof selector === 'function') { +// return FuncUnit.wait(0, selector); +// } -const performSyncQuery = function ( selector, frame ) { - const origFrame = frame; +// if (this.isSyncOnly) { +// return performSyncQuery(this.selector, this.frame); +// } else { +// performAsyncQuery(this.selector, this.frame, this); +// return performSyncQuery(this.selector, this.frame); +// } +// } - if (FuncUnit.win) { - frame = getContext(frame); - } - // const result = new origFuncUnit( selector, frame, true ); - const result = new origFuncUnit.fn.init( selector, frame, true ); - result.frame = origFrame; +// // https://stackoverflow.com/questions/4754560/help-understanding-jquerys-jquery-fn-init-why-is-init-in-fn - return result; -} +// const performAsyncQuery = function ( selector, frame, self ) { +// FuncUnit.add({ +// method: function ( success, error ) { +// this.frame = frame; +// this.selector = selector; +// if (FuncUnit.win) { +// frame = getContext(frame); +// } +// // this.bind = new origFuncUnit( selector, frame, true ); +// this.bind = new origFuncUnit.fn.init( selector, frame, true ); +// success(); +// return this; +// }, +// error: `Selector failed: ${selector}`, +// type: 'query' +// }); +// } -const getContext = function ( context ) { - let frame, frames, selector; - if (typeof context === 'number' || typeof context === 'string') { - selector = typeof context === 'number' ? `iframe:eq(${context})` : `iframe[name='${context}']`; - frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); - frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement; - } else { - frame = FuncUnit.win.document.documentElement; - } - return frame; -} +// const performSyncQuery = function ( selector, frame ) { +// const origFrame = frame; +// if (FuncUnit.win) { +// frame = getContext(frame); +// } +// // const result = new origFuncUnit( selector, frame, true ); +// const result = new origFuncUnit.fn.init( selector, frame, true ); +// result.frame = origFrame; -oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit); +// return result; +// } -FuncUnit.prototype = origFuncUnit.prototype; -module.exports = FuncUnit; + + +// const getContext = function ( context ) { +// let frame, frames, selector; + +// if (typeof context === 'number' || typeof context === 'string') { +// selector = typeof context === 'number' ? `iframe:eq(${context})` : `iframe[name='${context}']`; +// frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); +// frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement; +// } else { +// frame = FuncUnit.win.document.documentElement; +// } + +// return frame; +// } + + + + +// oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit); + +// FuncUnit.prototype = origFuncUnit.prototype; + +// module.exports = FuncUnit; diff --git a/test/new-tests/test.html b/test/new-tests/test.html new file mode 100644 index 00000000..1ad3a80f --- /dev/null +++ b/test/new-tests/test.html @@ -0,0 +1,18 @@ + + + + + + + Document + + + + +
+ + + + + + \ No newline at end of file diff --git a/test/new-tests/test.js b/test/new-tests/test.js new file mode 100644 index 00000000..f25c13c7 --- /dev/null +++ b/test/new-tests/test.js @@ -0,0 +1,24 @@ +// const syn = window.syn = require("syn"); + +class FuncUnitPromise extends Promise { + constructor() {} + + async click() { + await syn.click(this); + } +} + +function F (selector, context) { + return new Promise((resolve, reject) => { + const el = document.querySelectorAll(selector); + if (el.length) { + resolve(el); + } else { + reject(`Element not found: ${selector}`); + } + }) +} + +console.log('loaded'); + +F('.the-div').then(console.log); From 1c183fd5b3e33838e1ad74458b16cfbf497969bb Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 27 Mar 2021 21:12:46 -0500 Subject: [PATCH 07/12] gets some basics working --- new-src/core.js | 265 +++++++++++++++++++++++++++- package.json | 4 +- test/new-tests/find_closest_test.js | 59 +++++++ test/new-tests/findclosest.html | 27 +++ test/new-tests/test.html | 10 +- test/new-tests/test.js | 21 +++ 6 files changed, 375 insertions(+), 11 deletions(-) create mode 100644 test/new-tests/find_closest_test.js create mode 100644 test/new-tests/findclosest.html diff --git a/new-src/core.js b/new-src/core.js index e9d10d45..360683a6 100644 --- a/new-src/core.js +++ b/new-src/core.js @@ -1,6 +1,265 @@ +const syn = require("syn"); + +// For contains selector. +const Sizzle = require("sizzle"); + +const funcUnitPrototypeMethods = { + // Actions + click(){ + return simpleAsyncAction(this, syn.click); + }, + + // Traversers + closest(selector){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement){ + console.log("closest", targetElement, selector); + return targetElement.closest(selector); + }, + rejectReason: () => new Error("Unable to find closest "+selector) + }); + return new this.constructor(executor); + }, + find(selector){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement){ + return Sizzle(selector, targetElement)[0]; + }, + rejectReason: () => new Error("Unable to find "+selector) + }); + return new this.constructor(executor); + }, + + // Getters + hasClass(classToken, compareHasClass = true){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement){ + return (targetElement.classList.contains(classToken) === compareHasClass) && targetElement; + }, + rejectReason: () => new Error("Element never had "+classToken+" in classList") + }); + return new this.constructor(executor); + }, + + visible(){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement){ + return (!!( elem.offsetHeight || elem.offsetWidth || elem.getClientRects().length )) && targetElement; + }, + rejectReason: () => new Error("Element never visible") + }); + return new this.constructor(executor); + }, + + text(){ + return simpleAsyncGetter(this, (el)=> el.textContent ); + } +}; + +const funcUnitStaticMethods = { + async useWindow(url){ + var width = window.innerWidth; + this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/2); + + if(this.defaultWindow && this.defaultWindow.___FUNCUNIT_OPENED) { + this.defaultWindow.close(); + this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/2); + } + let stealDone = false; + await resolveWhenTrue({ + tester: () => { + + + // make sure there is a document + if(!this.defaultWindow.document.documentElement) { + return; + } + if( this.defaultWindow.document.readyState !== "complete" || + this.defaultWindow.location.href === "about:blank" || + !this.defaultWindow.document.body ) { + return; + } + this.defaultWindow.___FUNCUNIT_OPENED = true; + + // wait for steal to fully load + if( this.defaultWindow.steal ) { + this.defaultWindow.steal.done().then(() => { + stealDone = true; + }); + } else { + stealDone = true; + } + return stealDone ; + } + }) + return this; + } +} + +function takeFirstDeepestChild(elements){ + var cur = elements[0]; + var index = 1; + var next; + while(next = elements[index]) { + if(!next) { + return cur; + } + if(! cur.contains(next) ) { + return cur; + } else { + cur = next; + index++; + } + } + return cur; +} + +function makeFuncUnit(defaultWindow) { + + function FuncUnit(selector, context) { + let executor; + if(typeof selector === "string") { + let win = getWindow(selector, context || FuncUnit.defaultWindow); + + executor = makeExecutorToResolveWhenTrue({ + tester: function(){ + var documentElement = win.document.documentElement; + + if(!documentElement) { + return undefined; + } + var results = Sizzle(selector, documentElement); + // contains will return multiple elements nested inside each other, this helps take the right + // one. + + return takeFirstDeepestChild(results); + }, + rejectReason: () => new Error("Unable to find "+selector) + }) + } else if(typeof selector === "function") { + executor = selector; + } else { + throw "arguments not understood"; + } + return Reflect.construct(Promise, [executor], FuncUnit); + }; + + FuncUnit.defaultWindow = defaultWindow; + + Object.assign( + FuncUnit, + Object.fromEntries( + Reflect.ownKeys(Promise) + .filter(key => key !== "length" && key !== "name") + .map(key => [key, Promise[key]]) + ) + ); + // Create the prototype, add methods to it + FuncUnit.prototype = Object.create(Promise.prototype); + FuncUnit.prototype.constructor = FuncUnit; + + Object.assign(FuncUnit.prototype,funcUnitPrototypeMethods); + + Object.assign(FuncUnit, funcUnitStaticMethods); + return FuncUnit; +} + + +function getWindowFromElement(element){ + const doc = element.ownerDocument; + return doc.defaultView || doc.parentWindow; +} + +function getWindow(element, context) { + + if(element.nodeName) { + return getWindowFromElement(element); + const doc = element.ownerDocument; + return doc.defaultView || doc.parentWindow; + } else { + if(!context) { + return window; + } else if(context.nodeName === "#document") { + return getWindowFromElement(element); + } else if(context.self === context) { + return context; + } else { + throw new Error("can't find window") + } + } +} + +function resolveWhenTrue(options) { + return new Promise(makeExecutorToResolveWhenTrue(options)) +} +function makeExecutorToResolveWhenTrue(options){ + return function(resolve, reject){ + checkTester(resolve, reject, options); + } +} + +function checkTester(resolve, reject, { + interval = 10, + timeout=10000, + tester, + resolveValue = (x) => x, + rejectReason = () => new Error("Poller timeout"), + testerArgument +}) { + const start = new Date(); + function check(){ + let testerResult = tester(testerArgument) + if(testerResult) { + resolve(resolveValue(testerResult)); + return true + } else if( (new Date() - start) > timeout ) { + reject( rejectReason() ) + } else { + setTimeout(check, interval); + } + } + check(); +} + +function makeExecutorToResolveWhenTrueAfterPromiseResolves(promise, options) { + return function(resolve, reject){ + promise.then(function(value){ + checkTester(resolve, reject, {...options, testerArgument: value}); + }, reject) + } +} +function makeExecutorThatPerformsActionAfterPromise(promise, action) { + return function(resolve, reject){ + promise.then(action, reject) + } +} + +function simpleAsyncAction(elementPromise, action) { + + return new elementPromise.constructor(function simpleAction(resolve, reject){ + elementPromise.then(function(element){ + action(element).then( ()=> { + resolve(element); + }, reject); + }, reject); + }); +} + +function simpleAsyncGetter(elementPromise, getter) { + + return new elementPromise.constructor(function simpleAction(resolve, reject){ + elementPromise.then(function(element){ + resolve( getter(element) ); + }, reject); + }); +} + +module.exports = makeFuncUnit(); + +/* class FuncUnit extends Promise { constructor(selector, context) { @@ -13,15 +272,13 @@ class FuncUnit extends Promise { } }) } - + async click() { const element = await this; await syn.click(element); } -} - +}*/ -module.exports = FuncUnit; diff --git a/package.json b/package.json index 7f617bd9..156c4b45 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "main": "dist/cjs/funcunit.js", "dependencies": { + "sizzle": "^2.3.6", "syn": "^1.0.0-pre.2" }, "devDependencies": { @@ -65,8 +66,7 @@ "steal-css": "^1.0.0", "steal-jasmine": "0.0.3", "steal-mocha": "0.0.3", - "steal-qunit": "^1.0.0", - "steal-qunit2": "^2.0.0", + "steal-qunit": "^2.0.0", "steal-tools": "^2.0.0", "testee": "^0.9.1" }, diff --git a/test/new-tests/find_closest_test.js b/test/new-tests/find_closest_test.js new file mode 100644 index 00000000..5590d52a --- /dev/null +++ b/test/new-tests/find_closest_test.js @@ -0,0 +1,59 @@ +var QUnit = require("steal-qunit"); +var F = require("funcunit/new-src/core"); + +QUnit.module("funcunit find closest",{ + beforeEach: async function(assert) { + const done = assert.async(); + await F.useWindow(__dirname+"/findclosest.html"); + done(); + } +}); + +QUnit.test("closest", async function(assert){ + const done = assert.async(); + let element = await F("a:contains('Holler')").closest("#foo").click(); + + assert.ok(element.classList.contains("iWasClicked"),"we clicked #foo"); + + element = await F("a:contains('Holler')").closest(".baz").click(); + assert.ok(element.classList.contains("iWasClicked"),"we clicked .baz"); + + + done(); +}); + +QUnit.test("find with traversers", async function(assert){ + + const done = assert.async(); + + await F(":contains('Holler')") + .closest("#foo") + .find(".combo") + .hasClass("combo", true) + .click(); + + await F(".combo:eq(0)").hasClass("iWasClicked", true); + assert.ok(true, "first was clicked"); + + await F(".combo:eq(1)").hasClass("iWasClicked", false); + assert.ok(true, "first was not clicked"); + + done(); +}) + +QUnit.test("read text", async function(assert){ + const done = assert.async(); + var text = await F('.another').text(); + + assert.equal(text, "another", "text is right") + + done(); +}) + +// NOTE: Broke during QUnit upgrade +//QUnit.test("nested find", 2, function(){ +// F(".baz").exists(function() { +// F(this).find("#foo").exists(".foo found"); +// F(this).find(".another").exists(".another found"); +// }) +//}) diff --git a/test/new-tests/findclosest.html b/test/new-tests/findclosest.html new file mode 100644 index 00000000..028d515d --- /dev/null +++ b/test/new-tests/findclosest.html @@ -0,0 +1,27 @@ + + + + Synthetic Typing Test + + + +
+
+ Holler! +
combo
+
+
combo
+
another
+
+ + + + + diff --git a/test/new-tests/test.html b/test/new-tests/test.html index 1ad3a80f..bae7b340 100644 --- a/test/new-tests/test.html +++ b/test/new-tests/test.html @@ -9,10 +9,10 @@ -
+
+ + - - - - \ No newline at end of file + diff --git a/test/new-tests/test.js b/test/new-tests/test.js index f25c13c7..55ced3f3 100644 --- a/test/new-tests/test.js +++ b/test/new-tests/test.js @@ -1,5 +1,25 @@ // const syn = window.syn = require("syn"); +var QUnit = require("steal-qunit"); +var F = require("funcunit/new-src/core"); +QUnit.module("funcunit - jQuery conflict") + +QUnit.test("basics", async function(assert){ + var button = document.createElement("button"); + button.innerHTML = "click"; + button.onclick = () => button.innerHTML = "clicked"; + + document.querySelector("#qunit-fixture").append(button); + + + await F("#qunit-fixture button").click(); + + assert.equal(button.innerHTML, "clicked"); +}); + +require("./find_closest_test"); + +/* class FuncUnitPromise extends Promise { constructor() {} @@ -22,3 +42,4 @@ function F (selector, context) { console.log('loaded'); F('.the-div').then(console.log); +*/ From d44e21e4a0fefea851ae314292fe44ead30b818f Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 1 Apr 2021 15:21:13 -0400 Subject: [PATCH 08/12] adds functionality, updates test, a little cleanup --- new-src/actions.js | 81 ++++ new-src/core.js | 364 ++++-------------- new-src/getters.js | 290 +++++++++++--- new-src/helpers.js | 54 +++ new-src/playground.js | 4 - new-src/traversers.js | 72 +--- new-tests/actions_test.js | 111 ++++++ new-tests/dialogs_test.js | 43 +++ new-tests/getters_test.js | 142 +++++++ new-tests/open_test.js | 47 +++ new-tests/test-setup/confirm.html | 50 +++ new-tests/test-setup/drag.html | 45 +++ new-tests/test-setup/drag.js | 25 ++ new-tests/test-setup/myapp.html | 156 ++++++++ new-tests/test-setup/myotherapp.html | 14 + .../test-setup/qunit2_tests.html | 9 + new-tests/test-setup/scroll.html | 25 ++ {test/new-tests => new-tests}/test.html | 2 +- new-tests/test.js | 22 ++ .../traversers_test.js | 29 +- test/new-tests/test.js | 45 --- 21 files changed, 1151 insertions(+), 479 deletions(-) create mode 100644 new-src/actions.js create mode 100644 new-src/helpers.js delete mode 100644 new-src/playground.js create mode 100644 new-tests/actions_test.js create mode 100644 new-tests/dialogs_test.js create mode 100644 new-tests/getters_test.js create mode 100644 new-tests/open_test.js create mode 100644 new-tests/test-setup/confirm.html create mode 100644 new-tests/test-setup/drag.html create mode 100644 new-tests/test-setup/drag.js create mode 100644 new-tests/test-setup/myapp.html create mode 100644 new-tests/test-setup/myotherapp.html rename test/new-tests/findclosest.html => new-tests/test-setup/qunit2_tests.html (63%) create mode 100644 new-tests/test-setup/scroll.html rename {test/new-tests => new-tests}/test.html (86%) create mode 100644 new-tests/test.js rename test/new-tests/find_closest_test.js => new-tests/traversers_test.js (62%) delete mode 100644 test/new-tests/test.js diff --git a/new-src/actions.js b/new-src/actions.js new file mode 100644 index 00000000..cf0b7d68 --- /dev/null +++ b/new-src/actions.js @@ -0,0 +1,81 @@ +const syn = require("syn"); + +const funcUnitActions = { + click(){ + return simpleAsyncAction(this, syn.click); + }, + + rightClick() { + return simpleAsyncAction(this, syn.rightClick); + }, + + dblClick() { + return simpleAsyncAction(this, syn.dblclick); + }, + + scroll(direction, amount) { + let func; + + if (direction === 'left' || direction === 'right') { + func = function (el) { + el.scrollLeft = amount; + return el; + } + } + + if (direction === 'top' || direction === 'bottom') { + func = function (el) { + el.scrollTop = amount; + return el; + } + } + + return simpleSyncAction(this, func); + }, + + drag() { + return simpleAsyncActionWithArgs(this, syn.drag, arguments); + }, + + move() { + return simpleAsyncActionWithArgs(this, syn.move, arguments); + }, + + type(text) { + this.click(); + return simpleAsyncActionWithArgs(this, syn.type, arguments); + }, + + sendKeys(text) { + return simpleAsyncActionWithArgs(this, syn.type, arguments); + } +}; + + +// Helper functions + +function simpleAsyncActionWithArgs(elementPromise, action, args) { + return new elementPromise.constructor(function simpleActionWithArgs(resolve, reject) { + elementPromise.then(function (element) { + action(element, ...args).then(() => resolve(element), reject); + }, reject); + }); +} + +function simpleAsyncAction(elementPromise, action) { + return new elementPromise.constructor(function simpleAction(resolve, reject) { + elementPromise.then(function (element){ + action(element).then(()=> resolve(element), reject); + }, reject); + }); +} + +function simpleSyncAction(elementPromise, action) { + return new elementPromise.constructor(function simpleAction(resolve, reject) { + elementPromise.then(function (element){ + resolve( action(element) ); + }, reject); + }); +} + +module.exports = funcUnitActions; diff --git a/new-src/core.js b/new-src/core.js index 360683a6..87fc615e 100644 --- a/new-src/core.js +++ b/new-src/core.js @@ -1,71 +1,83 @@ -const syn = require("syn"); - -// For contains selector. const Sizzle = require("sizzle"); +const { + resolveWhenTrue, + makeExecutorToResolveWhenTrue +} = require('./helpers'); + +const funcUnitActions = require('./actions'); +const funcUnitGetters = require('./getters'); +const funcUnitTraversers = require('./traversers'); + const funcUnitPrototypeMethods = { - // Actions - click(){ - return simpleAsyncAction(this, syn.click); - }, + ...funcUnitActions, + ...funcUnitGetters, + ...funcUnitTraversers +}; - // Traversers - closest(selector){ - const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { - tester: function(targetElement){ - console.log("closest", targetElement, selector); - return targetElement.closest(selector); - }, - rejectReason: () => new Error("Unable to find closest "+selector) - }); - return new this.constructor(executor); - }, - find(selector){ - const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { - tester: function(targetElement){ - return Sizzle(selector, targetElement)[0]; - }, - rejectReason: () => new Error("Unable to find "+selector) - }); - return new this.constructor(executor); - }, +function makeFuncUnit(defaultWindow) { - // Getters - hasClass(classToken, compareHasClass = true){ - const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { - tester: function(targetElement){ - return (targetElement.classList.contains(classToken) === compareHasClass) && targetElement; - }, - rejectReason: () => new Error("Element never had "+classToken+" in classList") - }); - return new this.constructor(executor); - }, + function FuncUnit(selector, context) { + let executor; + if(typeof selector === "string") { + let win = getWindow(selector, context || FuncUnit.defaultWindow); - visible(){ - const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { - tester: function(targetElement){ - return (!!( elem.offsetHeight || elem.offsetWidth || elem.getClientRects().length )) && targetElement; - }, - rejectReason: () => new Error("Element never visible") - }); - return new this.constructor(executor); - }, + executor = makeExecutorToResolveWhenTrue({ + tester: function(){ + var documentElement = win.document.documentElement; - text(){ - return simpleAsyncGetter(this, (el)=> el.textContent ); - } -}; + if(!documentElement) { + return undefined; + } + var results = Sizzle(selector, documentElement); + // contains will return multiple elements nested inside each other, this helps take the right + // one. + + return takeFirstDeepestChild(results); + }, + rejectReason: () => new Error("Unable to find "+selector) + }) + } else if(typeof selector === "function") { + executor = selector; + } else { + throw "arguments not understood"; + } + return Reflect.construct(Promise, [executor], FuncUnit); + }; + + FuncUnit.defaultWindow = defaultWindow; + + Object.assign( + FuncUnit, + Object.fromEntries( + Reflect.ownKeys(Promise) + .filter(key => key !== "length" && key !== "name") + .map(key => [key, Promise[key]]) + ) + ); + // Create the prototype, add methods to it + FuncUnit.prototype = Object.create(Promise.prototype); + FuncUnit.prototype.constructor = FuncUnit; + + Object.assign(FuncUnit.prototype, funcUnitPrototypeMethods); + + Object.assign(FuncUnit, funcUnitStaticMethods); + return FuncUnit; +} const funcUnitStaticMethods = { async useWindow(url){ var width = window.innerWidth; - this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/2); + this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/4); if(this.defaultWindow && this.defaultWindow.___FUNCUNIT_OPENED) { this.defaultWindow.close(); - this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/2); + this.defaultWindow = window.open(url, "funcunit", "height=1000,toolbar=yes,status=yes,left="+width/4); } - let stealDone = false; + let stealDone = false, ready = false; + + setTimeout(() => ready = true, 333); + await resolveWhenTrue({ tester: () => { @@ -89,7 +101,7 @@ const funcUnitStaticMethods = { } else { stealDone = true; } - return stealDone ; + return stealDone && ready; } }) return this; @@ -114,60 +126,6 @@ function takeFirstDeepestChild(elements){ return cur; } -function makeFuncUnit(defaultWindow) { - - function FuncUnit(selector, context) { - let executor; - if(typeof selector === "string") { - let win = getWindow(selector, context || FuncUnit.defaultWindow); - - executor = makeExecutorToResolveWhenTrue({ - tester: function(){ - var documentElement = win.document.documentElement; - - if(!documentElement) { - return undefined; - } - var results = Sizzle(selector, documentElement); - // contains will return multiple elements nested inside each other, this helps take the right - // one. - - return takeFirstDeepestChild(results); - }, - rejectReason: () => new Error("Unable to find "+selector) - }) - } else if(typeof selector === "function") { - executor = selector; - } else { - throw "arguments not understood"; - } - return Reflect.construct(Promise, [executor], FuncUnit); - }; - - FuncUnit.defaultWindow = defaultWindow; - - Object.assign( - FuncUnit, - Object.fromEntries( - Reflect.ownKeys(Promise) - .filter(key => key !== "length" && key !== "name") - .map(key => [key, Promise[key]]) - ) - ); - // Create the prototype, add methods to it - FuncUnit.prototype = Object.create(Promise.prototype); - FuncUnit.prototype.constructor = FuncUnit; - - Object.assign(FuncUnit.prototype,funcUnitPrototypeMethods); - - Object.assign(FuncUnit, funcUnitStaticMethods); - return FuncUnit; -} - - - - - function getWindowFromElement(element){ const doc = element.ownerDocument; return doc.defaultView || doc.parentWindow; @@ -175,16 +133,14 @@ function getWindowFromElement(element){ function getWindow(element, context) { - if(element.nodeName) { + if (element.nodeName) { return getWindowFromElement(element); - const doc = element.ownerDocument; - return doc.defaultView || doc.parentWindow; } else { - if(!context) { + if (!context) { return window; - } else if(context.nodeName === "#document") { + } else if (context.nodeName === "#document") { return getWindowFromElement(element); - } else if(context.self === context) { + } else if (context.self === context) { return context; } else { throw new Error("can't find window") @@ -192,184 +148,4 @@ function getWindow(element, context) { } } -function resolveWhenTrue(options) { - return new Promise(makeExecutorToResolveWhenTrue(options)) -} -function makeExecutorToResolveWhenTrue(options){ - return function(resolve, reject){ - checkTester(resolve, reject, options); - } -} - -function checkTester(resolve, reject, { - interval = 10, - timeout=10000, - tester, - resolveValue = (x) => x, - rejectReason = () => new Error("Poller timeout"), - testerArgument -}) { - const start = new Date(); - function check(){ - let testerResult = tester(testerArgument) - if(testerResult) { - resolve(resolveValue(testerResult)); - return true - } else if( (new Date() - start) > timeout ) { - reject( rejectReason() ) - } else { - setTimeout(check, interval); - } - } - check(); -} - -function makeExecutorToResolveWhenTrueAfterPromiseResolves(promise, options) { - return function(resolve, reject){ - promise.then(function(value){ - checkTester(resolve, reject, {...options, testerArgument: value}); - }, reject) - } -} -function makeExecutorThatPerformsActionAfterPromise(promise, action) { - return function(resolve, reject){ - promise.then(action, reject) - } -} - -function simpleAsyncAction(elementPromise, action) { - - return new elementPromise.constructor(function simpleAction(resolve, reject){ - elementPromise.then(function(element){ - action(element).then( ()=> { - resolve(element); - }, reject); - }, reject); - }); -} - -function simpleAsyncGetter(elementPromise, getter) { - - return new elementPromise.constructor(function simpleAction(resolve, reject){ - elementPromise.then(function(element){ - resolve( getter(element) ); - }, reject); - }); -} - module.exports = makeFuncUnit(); - -/* -class FuncUnit extends Promise { - - constructor(selector, context) { - super((resolve, reject) => { - el = document.querySelectorAll(selector); - if (el) { - resolve(el); - } else { - reject('Element not found'); - } - }) - } - - async click() { - const element = await this; - await syn.click(element); - } -}*/ - - - - - -// var oldFuncUnit = require("funcunit/browser/init"); -// var origFuncUnit = oldFuncUnit.jQuery.sub(); -// var FuncUnit = oldFuncUnit.jQuery.sub(); - -// FuncUnit = function ( selector, context ) { - -// this.selector = selector; -// this.frame = context && context.frame ? context.frame : context; -// this.forceSync = context && context.forceSync ? context.forceSync : undefined -// this.isSyncOnly = typeof forceSync === 'boolean' ? forceSync : false; - -// if (typeof selector === 'function') { -// return FuncUnit.wait(0, selector); -// } - -// if (this.isSyncOnly) { -// return performSyncQuery(this.selector, this.frame); -// } else { -// performAsyncQuery(this.selector, this.frame, this); -// return performSyncQuery(this.selector, this.frame); -// } -// } - - - -// // https://stackoverflow.com/questions/4754560/help-understanding-jquerys-jquery-fn-init-why-is-init-in-fn - - -// const performAsyncQuery = function ( selector, frame, self ) { -// FuncUnit.add({ -// method: function ( success, error ) { -// this.frame = frame; -// this.selector = selector; - -// if (FuncUnit.win) { -// frame = getContext(frame); -// } - -// // this.bind = new origFuncUnit( selector, frame, true ); -// this.bind = new origFuncUnit.fn.init( selector, frame, true ); -// success(); -// return this; -// }, -// error: `Selector failed: ${selector}`, -// type: 'query' -// }); -// } - - - -// const performSyncQuery = function ( selector, frame ) { -// const origFrame = frame; - -// if (FuncUnit.win) { -// frame = getContext(frame); -// } - -// // const result = new origFuncUnit( selector, frame, true ); -// const result = new origFuncUnit.fn.init( selector, frame, true ); - -// result.frame = origFrame; - -// return result; -// } - - - - -// const getContext = function ( context ) { -// let frame, frames, selector; - -// if (typeof context === 'number' || typeof context === 'string') { -// selector = typeof context === 'number' ? `iframe:eq(${context})` : `iframe[name='${context}']`; -// frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); -// frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement; -// } else { -// frame = FuncUnit.win.document.documentElement; -// } - -// return frame; -// } - - - - -// oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit); - -// FuncUnit.prototype = origFuncUnit.prototype; - -// module.exports = FuncUnit; diff --git a/new-src/getters.js b/new-src/getters.js index 0064f587..7430d796 100644 --- a/new-src/getters.js +++ b/new-src/getters.js @@ -1,69 +1,241 @@ -var $ = require("funcunit/browser/jquery"); -var FuncUnit = require("funcunit/browser/core"); - -FuncUnit.funcs = { - size: 0, - attr: 1, - hasClass: 1, - html: 0, - text: 0, - val: 0, - css: 1, - prop: 1, - offset: 0, - position: 0, - scrollTop: 0, - scrollLeft: 0, - height: 0, - width: 0, - innerHeight: 0, - innerWidth: 0, - outerHeight: 0, - outerWidth: 0 +const { + makeExecutorToResolveWhenTrueAfterPromiseResolves +} = require('./helpers'); + +const funcUnitGetters = { + hasClass(classToken, compareHasClass = true) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => (targetElement.classList.contains(classToken) === compareHasClass) && targetElement, + rejectReason: () => new Error(`Element never had ${classToken} in classList`) + }); + return new this.constructor(executor); + }, + + visible() { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => !!( targetElement.offsetHeight || targetElement.offsetWidth || targetElement.getClientRects().length ), + rejectReason: () => new Error('Element was never visible') + }); + return new this.constructor(executor); + }, + + val(newVal) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => targetElement.value === newVal, + rejectReason: () => new Error(`Element never had value: ${newVal}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, el => el.value); + } + }, + + text(waitForText) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => targetElement.textContent === waitForText, + rejectReason: () => new Error(`Element never had text: ${waitForText}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, el => el.textContent); + } + }, + + height(expectedHeight) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateHeight(targetElement) === expectedHeight, + rejectReason: () => new Error(`Element never had a height of ${expectedHeight}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, calculateHeight); + } + }, + + width(expectedWidth) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateWidth(targetElement) === expectedWidth, + rejectReason: () => new Error(`Element never had a width of ${expectedWidth}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, calculateWidth); + } + }, + + innerHeight(expectedHeight) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateInnerHeight(targetElement) === expectedHeight, + rejectReason: () => new Error(`Element never had an innerHeight of ${expectedHeight}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, calculateInnerHeight); + } + }, + + innerWidth(expectedWidth) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateInnerWidth(targetElement) === expectedWidth, + rejectReason: () => new Error(`Element never had an innerWidth of ${expectedWidth}`) + }); + return new this.constructor(executor); + } else { + return simpleAsyncGetter(this, calculateInnerWidth); + } + }, + + outerHeight() { + if (!arguments.length) { + // return outerHeight with no margin + return simpleAsyncGetter(this, calculateOuterHeight); + + } else if (arguments.length === 1 && typeof arguments[0] === 'boolean') { + // return outerHeight with margin + return simpleAsyncGetter(this, el => calculateOuterHeight(el, true)); + + } else if (arguments.length === 1 && typeof arguments[0] === 'number') { + // return outerHeight comparison with no margin + const expectedHeight = arguments[0]; + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateOuterHeight(targetElement) === expectedHeight, + rejectReason: () => new Error(`Element never had an outerHeight of ${expectedHeight}`) + }); + return new this.constructor(executor); + + } else { + // return outerHeight comparison with margin (2 arguments) + const expectedHeight = arguments[0]; + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateOuterHeight(targetElement, true) === expectedHeight, + rejectReason: () => new Error(`Element never had an outerHeight (margin=true) of ${expectedHeight}`) + }); + return new this.constructor(executor); + } + }, + + outerWidth() { + if (!arguments.length) { + // return outerWidth with no margin + return simpleAsyncGetter(this, calculateOuterWidth); + + } else if (arguments.length === 1 && typeof arguments[0] === 'boolean') { + // return outerWidth with margin + return simpleAsyncGetter(this, el => calculateOuterWidth(el, true)); + + } else if (arguments.length === 1 && typeof arguments[0] === 'number') { + // return outerWidth comparison with no margin + const expectedWidth = arguments[0]; + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateOuterWidth(targetElement) === expectedWidth, + rejectReason: () => new Error(`Element never had an outerWidth of ${expectedWidth}`) + }); + return new this.constructor(executor); + + } else { + // return outerWidth comparison with margin (2 arguments) + const expectedWidth = arguments[0]; + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => calculateOuterWidth(targetElement, true) === expectedWidth, + rejectReason: () => new Error(`Element never had an outerWidth (margin=true) of ${expectedWidth}`) + }); + return new this.constructor(executor); + } + }, + + scrollTop(distance) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement) { + return targetElement && targetElement.scrollTop === distance; + }, + rejectReason: () => new Error(`Element never reached scrollTop of ${distance}`) + }); + return new this.constructor(executor); + + } else { + return simpleAsyncGetter(this, el => el.scrollTop); + } + }, + + scrollLeft(distance) { + if (arguments.length) { + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: function(targetElement) { + return targetElement && targetElement.scrollLeft === distance; + }, + rejectReason: () => new Error(`Element never reached scrollLeft of ${distance}`) + }); + return new this.constructor(executor); + + } else { + return simpleAsyncGetter(this, el => el.scrollLeft); + } + } }; -function makeFunction ( name, expectedNumberOfArgs ) { - FuncUnit.prototype[name] = function () { - const timeToWait = 1000; - const argsToReadWith = arguments.slice(0, expectedNumberOfArgs); - const argsToCheckAgainst = arguments[expectedNumberOfArgs + 1]; - const startTime = new Date(); +// Helper functions - pollForValue( function() { - if (this.elements[name](...arguments.slice(0,1)) === arguments[1]) { - - } - }) - - return new Promise((resolve, reject) => { - - const check = () => { - return $(this.selector, this.frame)[name](...argsToReadWith) === argToCheckAgainst; - }; - - const checker = () => { - if (new Date() > startTime + timeToWait) { - clearTimeout(); - reject(new Error()); - } - - if (check()) { - clearTimeout(); - resolve(); - } else { - setTimeout(checker, 10); - } - }; +function simpleAsyncGetter(elementPromise, getter) { + return new elementPromise.constructor(function simpleAction(resolve, reject){ + elementPromise.then(function(element){ + resolve( getter(element) ); + }, reject); + }); +} + +function makeDimension(element, add, subtract = []) { + const styles = getComputedStyle(element); - setTimeout(checker); - }); - }; + const sum = add.reduce((total, property) => { + return total + parseFloat(styles[property], 10) + }, 0); + + return subtract.reduce((total, property) => { + return total - parseFloat(styles[property]); + }, sum); +} + +function calculateHeight(element) { + return makeDimension(element, ['height'], ['padding-top', 'padding-bottom']); +} + +function calculateInnerHeight(element) { + return makeDimension(element, ['height']); +} +function calculateOuterHeight (element, includeMargin = false) { + const addProperties = ['height', 'border-top', 'border-bottom']; + if (includeMargin) { + addProperties.push('margin-top'); + addProperties.push('margin-bottom'); + } + return makeDimension(element, addProperties); } -for (const prop in FuncUnit.funcs) { - makeFunction(prop, FuncUnit.funcs[prop]); +function calculateWidth(element) { + return makeDimension(element, ['width'], ['padding-left', 'padding-right']); } -module.exports = FuncUnit; +function calculateInnerWidth(element) { + return makeDimension(element, ['width']); +} + +function calculateOuterWidth(element, includeMargin = false) { + const addProperties = ['width', 'border-left', 'border-right']; + if (includeMargin) { + addProperties.push('margin-left'); + addProperties.push('margin-right'); + } + return makeDimension(element, addProperties); +} + + +module.exports = funcUnitGetters; diff --git a/new-src/helpers.js b/new-src/helpers.js new file mode 100644 index 00000000..e7261f49 --- /dev/null +++ b/new-src/helpers.js @@ -0,0 +1,54 @@ +function resolveWhenTrue(options) { + return new Promise(makeExecutorToResolveWhenTrue(options)); +} + +function makeExecutorToResolveWhenTrue(options) { + return function(resolve, reject) { + checkTester(resolve, reject, options); + } +} + +function makeExecutorToResolveWhenTrueAfterPromiseResolves(promise, options) { + return function(resolve, reject) { + promise.then(function(value) { + checkTester(resolve, reject, { ...options, testerArgument: value }); + }, reject) + } +} + +function makeExecutorThatPerformsActionAfterPromise(promise, action) { + return function(resolve, reject) { + promise.then(action, reject) + } +} + +function checkTester(resolve, reject, { + interval = 10, + timeout = 10000, + tester, + resolveValue = (x) => x, + rejectReason = () => new Error("Poller timeout"), + testerArgument +}) { + const start = new Date(); + function check(){ + let testerResult = tester(testerArgument) + if(testerResult) { + resolve(resolveValue(testerResult)); + return true + } else if( (new Date() - start) > timeout ) { + reject( rejectReason() ) + } else { + setTimeout(check, interval); + } + } + check(); +} + +module.exports = { + checkTester, + resolveWhenTrue, + makeExecutorToResolveWhenTrue, + makeExecutorThatPerformsActionAfterPromise, + makeExecutorToResolveWhenTrueAfterPromiseResolves +} diff --git a/new-src/playground.js b/new-src/playground.js deleted file mode 100644 index 435896dc..00000000 --- a/new-src/playground.js +++ /dev/null @@ -1,4 +0,0 @@ -function myFunc () { - var variable = 1; - this.variable = 2; -} diff --git a/new-src/traversers.js b/new-src/traversers.js index 6f420ef1..5884a4ee 100644 --- a/new-src/traversers.js +++ b/new-src/traversers.js @@ -1,56 +1,24 @@ -var FuncUnit = require("funcunit/browser/core"); - -const traversers = [ - 'closest', - 'next', - 'prev', - 'siblings', - 'last', - 'first', - 'find' -]; - - - - -function makeTraverser ( name ) { - - const orig = FuncUnit.prototype[name]; - - FuncUnit.prototype[name] = function ( selector ) { - - const args = arguments; - - // nodeType 9 is document node - if (FuncUnit.win && this[0] && this[0].parentNode && this[0].parentNode.nodeType !== 9) { - - FuncUnit.add({ - method: function ( success, error ) { - const newBindFunc = orig.apply(this.bind, args); - newBindFunc.prevTraverser = name; - newBindFunc.prevTraverserSelector = selector; - success(newBindFunc); - }, - error: `Could not traverse: ${name} ${selector}`, - bind: this - }); - } - - // returns jquery function with this context & arguments - // return orig.apply(this, args); - - return new Promise((resolve, reject) => { - - resolve(orig.apply(this, args)); +const Sizzle = require("sizzle"); +const { + makeExecutorToResolveWhenTrueAfterPromiseResolves +} = require('./helpers'); + +const funcUnitTraversers = { + closest(selector){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => targetElement.closest(selector), + rejectReason: () => new Error(`Unable to find closest ${selector}`) + }); + return new this.constructor(executor); + }, + find(selector){ + const executor = makeExecutorToResolveWhenTrueAfterPromiseResolves(this, { + tester: targetElement => Sizzle(selector, targetElement)[0], + rejectReason: () => new Error(`Unable to find ${selector}`) }); + return new this.constructor(executor); } +}; -} - - - -traversers.forEach( traverser => makeTraverser(traverser) ); - - -module.exports = FuncUnit; +module.exports = funcUnitTraversers; diff --git a/new-tests/actions_test.js b/new-tests/actions_test.js new file mode 100644 index 00000000..03e911ca --- /dev/null +++ b/new-tests/actions_test.js @@ -0,0 +1,111 @@ +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); + +QUnit.module('funcunit actions', { + beforeEach: async assert => { + const done = assert.async(); + await F.useWindow(`${__dirname}/test-setup/qunit2_tests.html`); + done(); + } +}); + + +// Click Events -------------------- + +QUnit.test('click', async assert => { + const done = assert.async(); + const element = await F('#foo').click(); + assert.ok(element.classList.contains('iWasClicked'), '#foo was clicked'); + done(); +}); + +QUnit.test('right click', async assert => { + const done = assert.async(); + const element = await F('#foo').rightClick(); + assert.ok(element.classList.contains('iWasRightClicked'), '#foo was right clicked'); + done(); +}); + +// NOT WORKING - potential syn bug +// QUnit.test('double click', async assert => { +// const done = assert.async(); +// const element = await F('#foo').dblClick(); +// assert.ok(element.classList.contains('iWasDoubleClicked'), '#foo was double clicked'); +// done(); +// }); + + +// Scroll -------------------- + +QUnit.test('scroll down', async assert => { + const done = assert.async(); + await F.useWindow(`${__dirname}/test-setup/scroll.html`); + const element = await F('#scrolldiv').scroll('top', 100); + assert.equal(100, element.scrollTop, 'scroll vertical worked'); + const scrollTopValue = await F('#scrolldiv').scrollTop(); + assert.equal(100, scrollTopValue, 'scrollTop getter worked'); + done(); +}); + +QUnit.test('scroll right', async assert => { + const done = assert.async(); + await F.useWindow(`${__dirname}/test-setup/scroll.html`); + const element = await F('#scrolldiv').scroll('right', 100); + assert.equal(100, element.scrollLeft, 'scroll horizontal worked'); + const scrollLeftValue = await F('#scrolldiv').scrollLeft(); + assert.equal(100, scrollLeftValue, 'scrollLeft getter worked'); + done(); +}); + + +// Drag & Move Events -------------------- + +QUnit.test('drag', async assert => { + const done = assert.async(); + + await F.useWindow(`${__dirname}/test-setup/drag.html`); + + await F('#drag').drag('#drop'); + await F('#clicker').click(); + const dragged = await F('.status').text('dragged', 'drag worked correctly'); + assert.ok(dragged); + + done(); +}); + +QUnit.test('move', async assert => { + const done = assert.async(); + + await F.useWindow(`${__dirname}/test-setup/drag.html`); + + await F('#start').move('#end'); + await F('#typer').type('javascriptmvc'); + const moved = await F('#typer').val('javascriptmvc', 'move worked correctly'); + assert.ok(moved); + + done(); +}); + + +// Keyboard Events -------------------- + +QUnit.test('type', async assert => { + const done = assert.async(); + const textToType = 'hello type'; + const element = await F('#typehere').type(textToType); + assert.equal(textToType, element.value, 'typed text matches'); + assert.ok(element.classList.contains('iWasClicked'), 'the element was clicked'); + done(); +}); + +QUnit.test('send keys', async assert => { + const done = assert.async(); + const keysToSend = 'hello sendKeys'; + const element = await F('#typehere').sendKeys(keysToSend); + assert.equal(keysToSend, element.value, 'sent keys matches'); + assert.ok(!element.classList.contains('iWasClicked'), 'the element was not clicked'); + done(); +}); + + + diff --git a/new-tests/dialogs_test.js b/new-tests/dialogs_test.js new file mode 100644 index 00000000..7d226864 --- /dev/null +++ b/new-tests/dialogs_test.js @@ -0,0 +1,43 @@ +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); + +QUnit.module('funcunit actions', { + beforeEach: async assert => { + const done = assert.async(); + await F.useWindow(`${__dirname}/test-setup/confirm.html`); + done(); + } +}); + +// funcunit sets text for the next dialog +// F.confirm('confirm text'); + +QUnit.test('window alert', async assert => { + const done = assert.async(); + + await F('#alert').click(); + const alerted = await F('#alert').text('I was alerted', 'window.alert overridden'); + assert.ok(alerted, 'window alert dialog was overridden'); + + done(); +}); + +QUnit.test('window confirm', async assert => { + const done = assert.async(); + + await F('#confirm').click(); + const confirmed = await F('#confirm').text('I was confirmed', 'window.confirm overridden'); + assert.ok(confirmed, 'window confirm dialog was overridden'); + + done(); +}); + +QUnit.test('window prompt', async assert => { + const done = assert.async(); + + await F('#prompt').click(); + const prompted = await F('#prompt').text('I was prompted', 'window.prompt overridden'); + assert.ok(prompted, 'window prompt dialog was overridden'); + + done(); +}); diff --git a/new-tests/getters_test.js b/new-tests/getters_test.js new file mode 100644 index 00000000..75a5bb48 --- /dev/null +++ b/new-tests/getters_test.js @@ -0,0 +1,142 @@ +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); + +QUnit.module("funcunit find closest",{ + beforeEach: async function(assert) { + const done = assert.async(); + await F.useWindow(__dirname+"/test-setup/qunit2_tests.html"); + done(); + } +}); + + +// height, innerHeight, outerHeight/margin +QUnit.test('get and compare height', async assert => { + const done = assert.async(); + + const elementHeight = await F('#dimensions-div').height(); + assert.equal(8, elementHeight); + + const heightComparison = await F('#dimensions-div').height(elementHeight); + assert.ok(heightComparison); + + done(); +}); + +QUnit.test('get and compare innerHeight', async assert => { + const done = assert.async(); + + const elementInnerHeight = await F('#dimensions-div').innerHeight(); + assert.equal(10, elementInnerHeight); + + const heightComparison = await F('#dimensions-div').innerHeight(elementInnerHeight); + assert.ok(heightComparison); + + done(); +}); + +QUnit.test('get and compare outerHeight', async assert => { + const done = assert.async(); + + const elementOuterHeight = await F('#dimensions-div').outerHeight(); + assert.equal(12, elementOuterHeight); + + const heightComparison = await F('#dimensions-div').outerHeight(elementOuterHeight); + assert.ok(heightComparison); + + const elementOuterHeightMargin = await F('#dimensions-div').outerHeight(true); + assert.equal(14, elementOuterHeightMargin); + + const heightComparisonMargin = await F('#dimensions-div').outerHeight(elementOuterHeightMargin, true); + assert.ok(heightComparisonMargin); + + done(); +}); + + +// width, innerWidth, outerWidth(margin) +QUnit.test('get and compare width', async assert => { + const done = assert.async(); + + const elementwidth = await F('#dimensions-div').width(); + assert.equal(18, elementwidth); + + const widthComparison = await F('#dimensions-div').width(elementwidth); + assert.ok(widthComparison); + + done(); +}); + +QUnit.test('get and compare innerWidth', async assert => { + const done = assert.async(); + + const elementInnerWidth = await F('#dimensions-div').innerWidth(); + assert.equal(20, elementInnerWidth); + + const widthComparison = await F('#dimensions-div').innerWidth(elementInnerWidth); + assert.ok(widthComparison); + + done(); +}); + +QUnit.test('get and compare outerWidth', async assert => { + const done = assert.async(); + + const elementOuterWidth = await F('#dimensions-div').outerWidth(); + assert.equal(22, elementOuterWidth); + + const widthComparison = await F('#dimensions-div').outerWidth(elementOuterWidth); + assert.ok(widthComparison); + + const elementOuterWidthMargin = await F('#dimensions-div').outerWidth(true); + assert.equal(24, elementOuterWidthMargin); + + const widthComparisonMargin = await F('#dimensions-div').outerWidth(elementOuterWidthMargin, true); + assert.ok(widthComparisonMargin); + + done(); +}); + + +// Scroll +QUnit.test('get and compare scrollTop', async assert => { + const done = assert.async(); + + await F.useWindow(`${__dirname}/test-setup/scroll.html`); + await F('#innerdiv').click(); // autoscrolls 100px + + const elementScrollTop = await F('#scrolldiv').scrollTop(); + assert.equal(100, elementScrollTop); + + const scrollComparison = await F('#scrolldiv').scrollTop(100); + assert.ok(scrollComparison); + + done(); +}); + +QUnit.test('get and compare scrollLeft', async assert => { + const done = assert.async(); + + await F.useWindow(`${__dirname}/test-setup/scroll.html`); + await F('#innerdiv').click(); // autoscrolls 100px + + const elementScrollTop = await F('#scrolldiv').scrollLeft(); + assert.equal(100, elementScrollTop); + + const scrollComparison = await F('#scrolldiv').scrollLeft(100); + assert.ok(scrollComparison); + + done(); +}); + + +// visible +QUnit.test('element is visible', async assert => { + const done = assert.async(); + + const isVisible = await F('.baz').visible(); + assert.ok(isVisible); + + done(); +}); + diff --git a/new-tests/open_test.js b/new-tests/open_test.js new file mode 100644 index 00000000..52a17fe6 --- /dev/null +++ b/new-tests/open_test.js @@ -0,0 +1,47 @@ +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); + +QUnit.module('funcunit actions', { + beforeEach: async assert => { + const done = assert.async(); + // await F.useWindow(`${__dirname}/test-setup/qunit2_tests.html`); + done(); + } +}); + +// QUnit.test('F.open accepts a window', async assert => { +// const done = assert.async(); +// await F.useWindow(window); +// F('#tester').click(); +// F("#tester").text("Changed", "Changed link") + +// // F.open(frames["myapp"]); +// // F("#typehere").type("").type("javascriptmvc") +// // F("#seewhatyoutyped").text("typed javascriptmvc","typing"); + +// done(); +// }) + +QUnit.test("Back to back opens", async assert => { + const done = assert.async(); + + await F.useWindow(`${__dirname}/test-setup/myotherapp.html`); + await F.useWindow(`${__dirname}/test-setup/myapp.html`); + + await F("#changelink").click(); + const changed = await F("#changelink").text("Changed","href javascript run"); + + assert.ok(changed); + + done(); +}); + + +// QUnit.test('Testing win.confirm in multiple pages', function() { +// F.open('//test/open/first.html'); +// F('.next').click(); + +// F('.show-confirm').click(); +// F.confirm(true); +// F('.results').text('confirmed!', "Confirm worked!"); +// }) \ No newline at end of file diff --git a/new-tests/test-setup/confirm.html b/new-tests/test-setup/confirm.html new file mode 100644 index 00000000..09b6ad5b --- /dev/null +++ b/new-tests/test-setup/confirm.html @@ -0,0 +1,50 @@ + + + + + + Confirm! + Alert! + Prompt! + + diff --git a/new-tests/test-setup/drag.html b/new-tests/test-setup/drag.html new file mode 100644 index 00000000..6f5156a1 --- /dev/null +++ b/new-tests/test-setup/drag.html @@ -0,0 +1,45 @@ + + + + Synthetic Typing Test + + + +

start

+
Move over me
+

end

+
+
+
+
+
+ + + + diff --git a/new-tests/test-setup/drag.js b/new-tests/test-setup/drag.js new file mode 100644 index 00000000..b05b1452 --- /dev/null +++ b/new-tests/test-setup/drag.js @@ -0,0 +1,25 @@ +steal("jquerypp/index.js", function($){ + window.jQuery = $; + + var hoveredOnce = false; + $(".over").bind('mouseover',function(){ + if (!hoveredOnce) { + $(this).addClass('hover') + $(document.body).append("") + hoveredOnce = true; + console.log('hovered'); + } + }) + + $('#drag') + .on("draginit", function(){}) + + $('#drop') + .on("dropover", function(){ + $(document.body).append("click") + $("#clicker").click(function(){ + $(".status").html("dragged") + }) + }) + +}) diff --git a/new-tests/test-setup/myapp.html b/new-tests/test-setup/myapp.html new file mode 100644 index 00000000..d80efaca --- /dev/null +++ b/new-tests/test-setup/myapp.html @@ -0,0 +1,156 @@ + + + + Untitled Document + + + +

Hello World

+ + + + +

+

+

+ +
Change Thist Text
+ Change +
+
+

hasClass

+
Click Me
+

Exists

+
Click Me
+

Trigger Custom Event

+
Trigger Me
+
Confirm Me +
+
+
Right Click Me
+
+ + +
+ + + diff --git a/new-tests/test-setup/myotherapp.html b/new-tests/test-setup/myotherapp.html new file mode 100644 index 00000000..21835886 --- /dev/null +++ b/new-tests/test-setup/myotherapp.html @@ -0,0 +1,14 @@ + + + + Untitled Document + + + +

Goodbye World

+ + \ No newline at end of file diff --git a/test/new-tests/findclosest.html b/new-tests/test-setup/qunit2_tests.html similarity index 63% rename from test/new-tests/findclosest.html rename to new-tests/test-setup/qunit2_tests.html index 028d515d..4cc664c7 100644 --- a/test/new-tests/findclosest.html +++ b/new-tests/test-setup/qunit2_tests.html @@ -13,6 +13,10 @@
combo
another
+
+ +
+
diff --git a/new-tests/test-setup/scroll.html b/new-tests/test-setup/scroll.html new file mode 100644 index 00000000..d2100e4f --- /dev/null +++ b/new-tests/test-setup/scroll.html @@ -0,0 +1,25 @@ + + + + + Untitled Document + + +

Scroll Test

+
+ + + + + + diff --git a/test/new-tests/test.html b/new-tests/test.html similarity index 86% rename from test/new-tests/test.html rename to new-tests/test.html index bae7b340..c1009a51 100644 --- a/test/new-tests/test.html +++ b/new-tests/test.html @@ -12,7 +12,7 @@
+ main="funcunit/new-tests/test"> diff --git a/new-tests/test.js b/new-tests/test.js new file mode 100644 index 00000000..1980241d --- /dev/null +++ b/new-tests/test.js @@ -0,0 +1,22 @@ +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); + +QUnit.module("funcunit - jQuery conflict") + +QUnit.test("basics", async function(assert){ + const button = document.createElement("button"); + button.innerHTML = "click"; + button.onclick = () => button.innerHTML = "clicked"; + + document.querySelector("#qunit-fixture").append(button); + + await F("#qunit-fixture button").click(); + + assert.equal(button.innerHTML, "clicked"); +}); + +require('./actions_test'); +require('./getters_test'); +require("./traversers_test"); +require('./dialogs_test'); +require('./open_test'); diff --git a/test/new-tests/find_closest_test.js b/new-tests/traversers_test.js similarity index 62% rename from test/new-tests/find_closest_test.js rename to new-tests/traversers_test.js index 5590d52a..c2fae3d4 100644 --- a/test/new-tests/find_closest_test.js +++ b/new-tests/traversers_test.js @@ -1,29 +1,27 @@ -var QUnit = require("steal-qunit"); -var F = require("funcunit/new-src/core"); +const QUnit = require("steal-qunit"); +const F = require("funcunit/new-src/core"); QUnit.module("funcunit find closest",{ beforeEach: async function(assert) { const done = assert.async(); - await F.useWindow(__dirname+"/findclosest.html"); + await F.useWindow(`${__dirname}/test-setup/qunit2_tests.html`); done(); } }); QUnit.test("closest", async function(assert){ const done = assert.async(); - let element = await F("a:contains('Holler')").closest("#foo").click(); + let element = await F("a:contains('Holler')").closest("#foo").click(); assert.ok(element.classList.contains("iWasClicked"),"we clicked #foo"); element = await F("a:contains('Holler')").closest(".baz").click(); assert.ok(element.classList.contains("iWasClicked"),"we clicked .baz"); - done(); }); QUnit.test("find with traversers", async function(assert){ - const done = assert.async(); await F(":contains('Holler')") @@ -39,21 +37,4 @@ QUnit.test("find with traversers", async function(assert){ assert.ok(true, "first was not clicked"); done(); -}) - -QUnit.test("read text", async function(assert){ - const done = assert.async(); - var text = await F('.another').text(); - - assert.equal(text, "another", "text is right") - - done(); -}) - -// NOTE: Broke during QUnit upgrade -//QUnit.test("nested find", 2, function(){ -// F(".baz").exists(function() { -// F(this).find("#foo").exists(".foo found"); -// F(this).find(".another").exists(".another found"); -// }) -//}) +}); diff --git a/test/new-tests/test.js b/test/new-tests/test.js deleted file mode 100644 index 55ced3f3..00000000 --- a/test/new-tests/test.js +++ /dev/null @@ -1,45 +0,0 @@ -// const syn = window.syn = require("syn"); -var QUnit = require("steal-qunit"); -var F = require("funcunit/new-src/core"); - -QUnit.module("funcunit - jQuery conflict") - -QUnit.test("basics", async function(assert){ - var button = document.createElement("button"); - button.innerHTML = "click"; - button.onclick = () => button.innerHTML = "clicked"; - - document.querySelector("#qunit-fixture").append(button); - - - await F("#qunit-fixture button").click(); - - assert.equal(button.innerHTML, "clicked"); -}); - -require("./find_closest_test"); - -/* -class FuncUnitPromise extends Promise { - constructor() {} - - async click() { - await syn.click(this); - } -} - -function F (selector, context) { - return new Promise((resolve, reject) => { - const el = document.querySelectorAll(selector); - if (el.length) { - resolve(el); - } else { - reject(`Element not found: ${selector}`); - } - }) -} - -console.log('loaded'); - -F('.the-div').then(console.log); -*/ From cb064093873d04f5415597ed753a1a547e39abc7 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 1 Apr 2021 15:36:00 -0400 Subject: [PATCH 09/12] clean diff --- browser/core.js | 1 + browser/traversers.js | 1 + funcunit.js | 1 - test/adapters/jasmine.js | 8 ++++---- test/adapters/jasmine2.js | 8 ++++---- test/adapters/none.js | 18 +++++++----------- test/adapters/qunit.js | 8 ++++---- test/adapters/qunit2.js | 8 ++++---- test/qunit1_tests/actions_test.js | 10 ++++------ test/qunit1_tests/funcunit_test.js | 4 ++-- test/qunit2_tests/actions_test.js | 20 ++++++++++---------- 11 files changed, 41 insertions(+), 46 deletions(-) diff --git a/browser/core.js b/browser/core.js index d6b71f89..ab4324e3 100644 --- a/browser/core.js +++ b/browser/core.js @@ -1,3 +1,4 @@ +var jQuery = require("funcunit/browser/jquery"); var oldFuncUnit = require("funcunit/browser/init"); var FuncUnit = oldFuncUnit.jQuery.sub(); diff --git a/browser/traversers.js b/browser/traversers.js index 231bb8be..62bdf251 100644 --- a/browser/traversers.js +++ b/browser/traversers.js @@ -1,3 +1,4 @@ +var $ = require("funcunit/browser/jquery"); var FuncUnit = require("funcunit/browser/core"); /** diff --git a/funcunit.js b/funcunit.js index 4c4b7248..8780c561 100644 --- a/funcunit.js +++ b/funcunit.js @@ -1,5 +1,4 @@ var FuncUnit = require("funcunit/browser/core"); -// var FuncUnit = require("funcunit/src/core"); require("funcunit/browser/adapters/"); require("funcunit/browser/open"); diff --git a/test/adapters/jasmine.js b/test/adapters/jasmine.js index 6fe6735a..445bf35b 100644 --- a/test/adapters/jasmine.js +++ b/test/adapters/jasmine.js @@ -19,9 +19,9 @@ describe('Adapters', function() { $('.clickme, .clickresult').remove(); }); - it('should use the jasmine adapter', async function() { - await F.wait(1000); - await F('.clickme').click(); - await F('.clickresult').text('clicked'); + it('should use the jasmine adapter', function() { + F.wait(1000); + F('.clickme').click(); + F('.clickresult').text('clicked'); }); }); diff --git a/test/adapters/jasmine2.js b/test/adapters/jasmine2.js index 331802ef..db132843 100644 --- a/test/adapters/jasmine2.js +++ b/test/adapters/jasmine2.js @@ -21,10 +21,10 @@ describe('Adapters', function() { $('.clickme, .clickresult').remove(); }); - it('should use the jasmine adapter', async function(done) { - await F.wait(1000); - await F('.clickme').click(); - await F('.clickresult').text('clicked'); + it('should use the jasmine adapter', function(done) { + F.wait(1000); + F('.clickme').click(); + F('.clickresult').text('clicked'); F(function() { expect($('.clickresult').text()).toBe('clicked'); diff --git a/test/adapters/none.js b/test/adapters/none.js index f8f7e79f..1f98e89e 100644 --- a/test/adapters/none.js +++ b/test/adapters/none.js @@ -15,17 +15,13 @@ QUnit.module('Adapters', { } }); -test('QUnit with no adapter test', async function() { +test('QUnit with no adapter test', function() { stop(); - await F.wait(1000); - console.log('waited'); - - await F('.clickme').click(); - console.log('clicked'); - - await F('.clickresult').text('clicked'); - - ok('clicked the text'); - start(); + F.wait(1000); + F('.clickme').click(); + F('.clickresult').text('clicked', function() { + ok('clicked the text'); + start(); + }); }); diff --git a/test/adapters/qunit.js b/test/adapters/qunit.js index f2f20216..8402aa41 100644 --- a/test/adapters/qunit.js +++ b/test/adapters/qunit.js @@ -13,8 +13,8 @@ QUnit.module('Adapters', { } }); -test('QUnit adapter test', async function() { - await F.wait(1000); - await F('.clickme').click(); - await F('.clickresult').text('clicked', 'clicked the link'); +test('QUnit adapter test', function() { + F.wait(1000); + F('.clickme').click(); + F('.clickresult').text('clicked', 'clicked the link'); }); diff --git a/test/adapters/qunit2.js b/test/adapters/qunit2.js index 9bb4616d..ab144c0e 100644 --- a/test/adapters/qunit2.js +++ b/test/adapters/qunit2.js @@ -15,10 +15,10 @@ QUnit.module("Adapters 2", { } }); -QUnit.test("QUnit adapter test", async function(assert) { - await F.wait(1000); - await F(".clickme").click(); - await F(".clickresult").text("clicked", "clicked the link"); +QUnit.test("QUnit adapter test", function(assert) { + F.wait(1000); + F(".clickme").click(); + F(".clickresult").text("clicked", "clicked the link"); }); QUnit.module("QUnit 2 adapter unit tests"); diff --git a/test/qunit1_tests/actions_test.js b/test/qunit1_tests/actions_test.js index 0c7fc8c0..8d3009de 100644 --- a/test/qunit1_tests/actions_test.js +++ b/test/qunit1_tests/actions_test.js @@ -7,12 +7,10 @@ QUnit.module("scroll", { } }) -test("scroll on click", async function(){ - // QUnit.stop(); - await F('#innerdiv').click() - await F("#scrolldiv").scrollTop(100, "Scrolled down 100") - await F("#scrolldiv").scrollLeft(100, "Scrolled left 100") - // QUnit.start(); +test("scroll on click", function(){ + F('#innerdiv').click() + F("#scrolldiv").scrollTop(100, "Scrolled down 100") + F("#scrolldiv").scrollLeft(100, "Scrolled left 100") }) test("auto scrollleft", function(){ diff --git a/test/qunit1_tests/funcunit_test.js b/test/qunit1_tests/funcunit_test.js index f1ede854..307cc42f 100644 --- a/test/qunit1_tests/funcunit_test.js +++ b/test/qunit1_tests/funcunit_test.js @@ -21,8 +21,8 @@ test("Iframe access", function(){ }); }) -test("typing alt and shift characters", async function(){ - await F('#typehere').type("@", function(){ +test("typing alt and shift characters", function(){ + F('#typehere').type("@", function(){ equal(F('#typehere').val(), "@", "types weird chars" ); }) }) diff --git a/test/qunit2_tests/actions_test.js b/test/qunit2_tests/actions_test.js index 0cc179db..6e1e3049 100644 --- a/test/qunit2_tests/actions_test.js +++ b/test/qunit2_tests/actions_test.js @@ -7,18 +7,18 @@ QUnit.module("scroll", { } }) -QUnit.test("scroll on click", async function(){ - await F('#innerdiv').click() - await F("#scrolldiv").scrollTop(100, "Scrolled down 100") - await F("#scrolldiv").scrollLeft(100, "Scrolled left 100") +QUnit.test("scroll on click", function(){ + F('#innerdiv').click() + F("#scrolldiv").scrollTop(100, "Scrolled down 100") + F("#scrolldiv").scrollLeft(100, "Scrolled left 100") }) -QUnit.test("auto scrollleft", async function(){ - await F("#scrolldiv").scroll('left', 100) - await F('#scrolldiv').scrollLeft(100, 'scroll left worked') +QUnit.test("auto scrollleft", function(){ + F("#scrolldiv").scroll('left', 100) + F('#scrolldiv').scrollLeft(100, 'scroll left worked') }) -QUnit.test("auto scrolldown", async function(){ - await F("#scrolldiv").scroll('top', 100) - await F('#scrolldiv').scrollTop(100, 'scroll top worked') +QUnit.test("auto scrolldown", function(){ + F("#scrolldiv").scroll('top', 100) + F('#scrolldiv').scrollTop(100, 'scroll top worked') }) From d3642f06c7945577e518ed1aba54e279c5f6c57e Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 1 Apr 2021 15:43:12 -0400 Subject: [PATCH 10/12] rename make/get dimension function --- new-src/getters.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/new-src/getters.js b/new-src/getters.js index 7430d796..4cdb158e 100644 --- a/new-src/getters.js +++ b/new-src/getters.js @@ -191,7 +191,7 @@ function simpleAsyncGetter(elementPromise, getter) { }); } -function makeDimension(element, add, subtract = []) { +function getDimension(element, add, subtract = []) { const styles = getComputedStyle(element); const sum = add.reduce((total, property) => { @@ -204,11 +204,11 @@ function makeDimension(element, add, subtract = []) { } function calculateHeight(element) { - return makeDimension(element, ['height'], ['padding-top', 'padding-bottom']); + return getDimension(element, ['height'], ['padding-top', 'padding-bottom']); } function calculateInnerHeight(element) { - return makeDimension(element, ['height']); + return getDimension(element, ['height']); } function calculateOuterHeight (element, includeMargin = false) { @@ -217,15 +217,15 @@ function calculateOuterHeight (element, includeMargin = false) { addProperties.push('margin-top'); addProperties.push('margin-bottom'); } - return makeDimension(element, addProperties); + return getDimension(element, addProperties); } function calculateWidth(element) { - return makeDimension(element, ['width'], ['padding-left', 'padding-right']); + return getDimension(element, ['width'], ['padding-left', 'padding-right']); } function calculateInnerWidth(element) { - return makeDimension(element, ['width']); + return getDimension(element, ['width']); } function calculateOuterWidth(element, includeMargin = false) { @@ -234,7 +234,7 @@ function calculateOuterWidth(element, includeMargin = false) { addProperties.push('margin-left'); addProperties.push('margin-right'); } - return makeDimension(element, addProperties); + return getDimension(element, addProperties); } From 697a8518afb0b94073a4b30d8670848d5313ea08 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 1 Apr 2021 16:39:47 -0400 Subject: [PATCH 11/12] fix syn double click --- new-src/core.js | 2 +- new-tests/actions_test.js | 13 ++++++------- new-tests/test.js | 2 +- package.json | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/new-src/core.js b/new-src/core.js index 87fc615e..e66864d5 100644 --- a/new-src/core.js +++ b/new-src/core.js @@ -76,7 +76,7 @@ const funcUnitStaticMethods = { } let stealDone = false, ready = false; - setTimeout(() => ready = true, 333); + setTimeout(() => ready = true, 123); await resolveWhenTrue({ tester: () => { diff --git a/new-tests/actions_test.js b/new-tests/actions_test.js index 03e911ca..5638fe55 100644 --- a/new-tests/actions_test.js +++ b/new-tests/actions_test.js @@ -26,13 +26,12 @@ QUnit.test('right click', async assert => { done(); }); -// NOT WORKING - potential syn bug -// QUnit.test('double click', async assert => { -// const done = assert.async(); -// const element = await F('#foo').dblClick(); -// assert.ok(element.classList.contains('iWasDoubleClicked'), '#foo was double clicked'); -// done(); -// }); +QUnit.test('double click', async assert => { + const done = assert.async(); + const element = await F('#foo').dblClick(); + assert.ok(element.classList.contains('iWasDoubleClicked'), '#foo was double clicked'); + done(); +}); // Scroll -------------------- diff --git a/new-tests/test.js b/new-tests/test.js index 1980241d..c1370564 100644 --- a/new-tests/test.js +++ b/new-tests/test.js @@ -3,7 +3,7 @@ const F = require("funcunit/new-src/core"); QUnit.module("funcunit - jQuery conflict") -QUnit.test("basics", async function(assert){ +QUnit.test("basics", async function(assert) { const button = document.createElement("button"); button.innerHTML = "click"; button.onclick = () => button.innerHTML = "clicked"; diff --git a/package.json b/package.json index 156c4b45..713ac5f7 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "main": "dist/cjs/funcunit.js", "dependencies": { "sizzle": "^2.3.6", - "syn": "^1.0.0-pre.2" + "syn": "^1.0.0-pre.3" }, "devDependencies": { "can-define": "^0.8.0", From eeff668120cb93c5eb54d6cac5e0e49b57ea3b24 Mon Sep 17 00:00:00 2001 From: Michael Mancini Date: Thu, 1 Apr 2021 17:06:48 -0400 Subject: [PATCH 12/12] qunit test module names --- new-tests/dialogs_test.js | 2 +- new-tests/getters_test.js | 2 +- new-tests/open_test.js | 2 +- new-tests/traversers_test.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/new-tests/dialogs_test.js b/new-tests/dialogs_test.js index 7d226864..3f8a57f7 100644 --- a/new-tests/dialogs_test.js +++ b/new-tests/dialogs_test.js @@ -1,7 +1,7 @@ const QUnit = require("steal-qunit"); const F = require("funcunit/new-src/core"); -QUnit.module('funcunit actions', { +QUnit.module('funcunit dialogs', { beforeEach: async assert => { const done = assert.async(); await F.useWindow(`${__dirname}/test-setup/confirm.html`); diff --git a/new-tests/getters_test.js b/new-tests/getters_test.js index 75a5bb48..4bd1fd08 100644 --- a/new-tests/getters_test.js +++ b/new-tests/getters_test.js @@ -1,7 +1,7 @@ const QUnit = require("steal-qunit"); const F = require("funcunit/new-src/core"); -QUnit.module("funcunit find closest",{ +QUnit.module("funcunit getters",{ beforeEach: async function(assert) { const done = assert.async(); await F.useWindow(__dirname+"/test-setup/qunit2_tests.html"); diff --git a/new-tests/open_test.js b/new-tests/open_test.js index 52a17fe6..faa0e630 100644 --- a/new-tests/open_test.js +++ b/new-tests/open_test.js @@ -1,7 +1,7 @@ const QUnit = require("steal-qunit"); const F = require("funcunit/new-src/core"); -QUnit.module('funcunit actions', { +QUnit.module('funcunit open windows', { beforeEach: async assert => { const done = assert.async(); // await F.useWindow(`${__dirname}/test-setup/qunit2_tests.html`); diff --git a/new-tests/traversers_test.js b/new-tests/traversers_test.js index c2fae3d4..51d94340 100644 --- a/new-tests/traversers_test.js +++ b/new-tests/traversers_test.js @@ -1,7 +1,7 @@ const QUnit = require("steal-qunit"); const F = require("funcunit/new-src/core"); -QUnit.module("funcunit find closest",{ +QUnit.module("funcunit traversers",{ beforeEach: async function(assert) { const done = assert.async(); await F.useWindow(`${__dirname}/test-setup/qunit2_tests.html`); @@ -9,7 +9,7 @@ QUnit.module("funcunit find closest",{ } }); -QUnit.test("closest", async function(assert){ +QUnit.test("find closest", async function(assert){ const done = assert.async(); let element = await F("a:contains('Holler')").closest("#foo").click();