diff --git a/.github/workflows/blaze-tests.yml b/.github/workflows/blaze-tests.yml index 0dd1c3024..c0390b95d 100644 --- a/.github/workflows/blaze-tests.yml +++ b/.github/workflows/blaze-tests.yml @@ -79,4 +79,80 @@ jobs: pkill -TERM -P $(cat /tmp/meteor_test_pid) fi shell: bash - working-directory: test-app \ No newline at end of file + working-directory: test-app + + # this re-runs the app tests with the test-in-console driver + # but in this case we include jQuery via --extra-packages=jquery, + # which causes the tests to run with jQuery back-compatibility mode. + # This should be removed, once we fully dropped jQuery support in Blaze 4.x + test-app-jquery: + needs: test-app + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + submodules: recursive + + - name: Setup Node.js environment + uses: actions/setup-node@v6 + with: + node-version: 22 + + - name: Install Meteor + run: | + npx meteor@latest + echo "$HOME/.meteor" >> $GITHUB_PATH + + - name: Link packages directory + run: ln -sfn ../packages ./packages + working-directory: test-app + + - name: Meteor npm install + run: meteor npm install + working-directory: test-app + + - name: Start meteor test-packages (background) + run: | + export URL='http://localhost:4096/' + meteor test-packages --driver-package test-in-console -p 4096 --extra-packages=jquery --exclude "${TEST_PACKAGES_EXCLUDE:-}" > /tmp/meteor_test_output.log 2>&1 & + echo $! > /tmp/meteor_test_pid + working-directory: test-app + + # Wait for test-in-console to be ready for up to 6 minutes + # in order to accommodate slower CI environments + - name: Wait for test-in-console to be ready + run: | + + for i in {1..360}; do + if grep -q 'test-in-console listening' /tmp/meteor_test_output.log; then + echo "test-in-console is ready." + break + fi + echo "Waiting for test-in-console... attempt $i" + sleep 1 + done + # Fail if the service didn't start + if ! grep -q 'test-in-console listening' /tmp/meteor_test_output.log; then + echo "test-in-console did not start in time." + cat /tmp/meteor_test_output.log # Print the log for debugging + exit 1 + fi + shell: bash + working-directory: test-app + + - name: Run puppeteerRunner.js + run: meteor node puppeteerRunner.js + env: + URL: http://localhost:4096/ + working-directory: test-app + + - name: Kill meteor test-packages process + if: always() + run: | + if [ -f /tmp/meteor_test_pid ]; then + pkill -TERM -P $(cat /tmp/meteor_test_pid) + fi + shell: bash + working-directory: test-app diff --git a/packages/blaze/.versions b/packages/blaze/.versions index e51307103..3cdab109f 100644 --- a/packages/blaze/.versions +++ b/packages/blaze/.versions @@ -29,7 +29,6 @@ html-tools@2.0.0 htmljs@2.0.1 id-map@1.2.0 inter-process-messaging@0.1.2 -jquery@3.0.2 local-test:blaze@3.0.1 logging@1.3.5 meteor@2.0.1 diff --git a/packages/blaze/blaze.d.ts b/packages/blaze/blaze.d.ts index 9a2896ca6..c27e6d04c 100644 --- a/packages/blaze/blaze.d.ts +++ b/packages/blaze/blaze.d.ts @@ -1,5 +1,3 @@ -import * as $ from 'jquery'; - import { Tracker } from 'meteor/tracker'; import { Meteor } from 'meteor/meteor'; declare module 'meteor/blaze' { diff --git a/packages/blaze/dombackend.js b/packages/blaze/dombackend.js index ca2eba9e3..c9218498f 100644 --- a/packages/blaze/dombackend.js +++ b/packages/blaze/dombackend.js @@ -1,23 +1,34 @@ const DOMBackend = {}; Blaze._DOMBackend = DOMBackend; -const $jq = (typeof jQuery !== 'undefined' ? jQuery : - (typeof Package !== 'undefined' && Package.jquery ? - (Package.jquery.jQuery || Package.jquery.$) : null)); +let $jq; +let $jqSource; -const _hasJQuery = !!$jq; +if (!$jq && typeof jQuery !== 'undefined') { + $jq = jQuery; + $jqSource = 'global scope'; +} + +if (!$jq && typeof Package !== 'undefined' && Package.jquery) { + $jq = Package.jquery.jQuery ?? Package.jquery.$ ?? null; + $jqSource = 'Meteor packages'; +} +const _hasJQuery = !!$jq; if (_hasJQuery && typeof console !== 'undefined') { + const version = $jq.fn?.jquery ?? ' '; + console.info( + `[Blaze] jQuery ${version} detected as DOM backend. Native DOM backend is available — ` + + 'remove jquery to enable native DOM backend. jQuery support will be removed in Blaze 4.0.' + ); console.info( - '[Blaze] jQuery detected as DOM backend. Native DOM backend is available — ' + - 'remove the jquery package to enable it. jQuery support will be removed in Blaze 4.0.' + `[Blaze] jQuery was loaded via ${$jqSource}` ); } DOMBackend._$jq = $jq; // null when absent DOMBackend._hasJQuery = _hasJQuery; - DOMBackend.getContext = function () { if (DOMBackend._context) return DOMBackend._context; // jQuery may need the legacy check; native path always supports createHTMLDocument @@ -37,7 +48,7 @@ DOMBackend.parseHTML = function (html) { if (_hasJQuery) { return $jq.parseHTML(html, DOMBackend.getContext()) || []; } - const template = document.createElement('template'); + const template = DOMBackend.getContext().createElement('template'); template.innerHTML = html; return Array.from(template.content.childNodes); }; @@ -63,19 +74,7 @@ DOMBackend.Events = { // Alias non-bubbling events to their bubbling equivalents eventType = _delegateEventAlias[eventType] || eventType; - const wrapper = (event) => { - // event.target can be a text node (nodeType 3) — walk to parent element first - const origin = event.target; - const target = origin.nodeType === 1 ? origin.closest(selector) : origin.parentElement?.closest(selector); - if (target && elem.contains(target)) { - // Mimic jQuery's delegated event behavior - Object.defineProperty(event, 'currentTarget', { - value: target, - configurable: true, - }); - handler.call(target, event); - } - }; + const wrapper = createWrapper(elem, type, selector, handler); if (!_delegateMap.has(elem)) { _delegateMap.set(elem, new Map()); @@ -123,20 +122,7 @@ DOMBackend.Events = { handler._meteorui_wrapper = wrapper; } else { - const wrapper = (event) => { - // event.target can be a text node — walk to parent element first - const origin = event.target; - const matched = origin.nodeType === 1 ? origin.closest(selector) : origin.parentElement?.closest(selector); - if (matched && elem.contains(matched)) { - Object.defineProperty(event, 'currentTarget', { - value: matched, - configurable: true, - }); - handler.call(elem, event); - } - }; - - handler._meteorui_wrapper = wrapper; + handler._meteorui_wrapper = createWrapper(elem, type, selector, handler); } type = DOMBackend.Events.parseEventType(type); @@ -158,6 +144,46 @@ DOMBackend.Events = { } }; +const createWrapper = (elem, type, selector, handler) => { + return (event) => { + // event.target can be a text node (nodeType 3) — walk to parent element first + const origin = event.target; + const target = origin.nodeType === 1 ? origin.closest(selector) : origin.parentElement?.closest(selector); + + // we need to manually check, if a selector left the template scope + // which jQuery would do automatically for us. + // for this we traverse nodes that still match the selector + // and compare the final to see, if the event bubbled up to + // a parent view that is out of scope + let node = origin; + while (node && node !== elem && node instanceof Element && node.matches(selector)) { + node = node.parentElement; + } + + const root = elem?.['$blaze_range']?.view?.name; + const scope = node?.['$blaze_range']?.view?.name; + + let inScope = true; + if (root && scope && root === scope) { + inScope = false; + } + + if (target && elem.contains(target) && inScope) { + // Mimic jQuery's delegated event behavior + Object.defineProperty(event, 'currentTarget', { + value: target, + configurable: true, + }); + // mimic jQuery event return false behavior + const value = handler.call(target, event); + if (value === false) { + event.preventDefault(); + event.stopPropagation(); + event.stopImmediatePropagation(); + } + } + }; +} ///// Removal detection and interoperability. @@ -274,6 +300,17 @@ if (_hasJQuery) { _executeTeardownCallbacks(this); } }; +} else { + // in native DOM Backend we need to extend the native remove function + // to call the TearDown callbacks, registered during materializing + // for the element and its full descendant subtree. + (function(removeFn) { + HTMLElement.prototype.remove = function () { + DOMBackend.Teardown.tearDownElement(this); + return removeFn.apply(this, arguments); + }; + })(HTMLElement.prototype.remove); + } diff --git a/packages/blaze/materializer.js b/packages/blaze/materializer.js index 092de816b..3d1ec4463 100644 --- a/packages/blaze/materializer.js +++ b/packages/blaze/materializer.js @@ -97,7 +97,7 @@ const isPromiseLike = x => !!x && typeof x.then === 'function'; function then(maybePromise, fn) { if (isPromiseLike(maybePromise)) { - maybePromise.then(fn, Blaze._reportException); + maybePromise.then(fn, Blaze._reportException) } else { fn(maybePromise); } diff --git a/packages/blaze/package.js b/packages/blaze/package.js index 50f85c7ea..fb92a6545 100644 --- a/packages/blaze/package.js +++ b/packages/blaze/package.js @@ -6,14 +6,13 @@ Package.describe({ }); Package.onUse(function (api) { - api.use('jquery@1.11.9 || 3.0.0', { weak: true }); // should be a weak dep, by having multiple "DOM backends" api.use('tracker@1.3.2'); api.use('check@1.0.12'); api.use('observe-sequence@2.0.0'); api.use('reactive-var@1.0.12'); api.use('ordered-dict@1.2.0'); api.use('ecmascript@0.16.9'); - + api.use('jquery@3.0.0', 'client', { weak: true }); api.export([ 'Blaze', 'UI', @@ -53,8 +52,6 @@ Package.onTest(function (api) { api.use('ecmascript@0.16.9'); api.use('tinytest'); api.use('test-helpers'); - api.use('jquery@1.11.9 || 3.0.0'); // strong dependency, for testing jQuery backend - api.use('reactive-var@1.0.12'); api.use('tracker@1.3.2'); diff --git a/packages/blaze/render_tests.js b/packages/blaze/render_tests.js index 67df25b72..9e907ba9c 100644 --- a/packages/blaze/render_tests.js +++ b/packages/blaze/render_tests.js @@ -1,7 +1,7 @@ import { BlazeTools } from 'meteor/blaze-tools'; const toCode = BlazeTools.toJS; - +const hasJquery = Blaze._DOMBackend._hasJQuery; const P = HTML.P; const CharRef = HTML.CharRef; const DIV = HTML.DIV; @@ -267,8 +267,8 @@ Tinytest.add("blaze - render - view GC", function (test) { (function () { const R = ReactiveVar('Hello'); const test1 = P(Blaze.View(function () { return R.get(); })); - const div = document.createElement("DIV"); + materialize(test1, div); test.equal(canonicalizeHtml(div.innerHTML), "

Hello

"); @@ -278,7 +278,7 @@ Tinytest.add("blaze - render - view GC", function (test) { test.equal(R._numListeners(), 1); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(R._numListeners(), 0); @@ -325,7 +325,7 @@ Tinytest.add("blaze - render - reactive attributes", function (test) { test.equal(canonicalizeHtml(div.innerHTML), ''); test.equal(R._numListeners(), 1); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(R._numListeners(), 0); })(); @@ -354,7 +354,7 @@ Tinytest.add("blaze - render - reactive attributes", function (test) { Tracker.flush(); test.equal(canonicalizeHtml(div.innerHTML), '
'); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(style._numListeners(), 0); })(); @@ -393,7 +393,7 @@ Tinytest.add("blaze - render - reactive attributes", function (test) { test.equal(canonicalizeHtml(div.innerHTML), ''); test.equal(R._numListeners(), 1); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(R._numListeners(), 0); })(); @@ -482,7 +482,7 @@ Tinytest.add("blaze - render - reactive attributes", function (test) { Tracker.flush(); test.equal(canonicalizeHtml(div.innerHTML), ''); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(R._numListeners(), 0); })(); @@ -574,7 +574,7 @@ Tinytest.add("blaze - render - templates and views", function (test) { test.equal(canonicalizeHtml(div.innerHTML), '123
'); buf.length = 0; - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } buf.sort(); test.equal(buf, ['destroyed 1', 'destroyed 2', 'destroyed 3']); @@ -617,10 +617,12 @@ Tinytest.add("blaze - render - findAll", function (test) { Blaze.render(myTemplate, div); Tracker.flush(); - test.equal(Array.isArray(found), true); - test.equal(Array.isArray($found), false); test.equal(found.length, 2); test.equal($found.length, 2); + const foundIsArray = Array.isArray(found); + const $foundIsArray = Array.isArray($found); + test.equal(foundIsArray, true); + test.equal($foundIsArray, !hasJquery); }); Tinytest.add("blaze - render - reactive attributes 2", function (test) { @@ -670,7 +672,7 @@ Tinytest.add("blaze - render - reactive attributes 2", function (test) { // clean up - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } test.equal(R1._numListeners(), 0); test.equal(R2._numListeners(), 0); @@ -778,7 +780,7 @@ if (typeof MutationObserver !== 'undefined') { // We do not update anything after initial rendering, so only one mutation is there. test.equal(observedMutations.length, 1); - $(div).remove(); + if (hasJquery) { $(div).remove() } else { div.remove() } observer.disconnect(); onComplete(); diff --git a/packages/observe-sequence/observe_sequence_tests.js b/packages/observe-sequence/observe_sequence_tests.js index c40ffbe92..01c471922 100644 --- a/packages/observe-sequence/observe_sequence_tests.js +++ b/packages/observe-sequence/observe_sequence_tests.js @@ -145,23 +145,23 @@ function runInVM(code) { return res; } -Tinytest.add('observe-sequence - initial data for all sequence types', function (test) { - runOneObserveSequenceTestCase(test, function () { +Tinytest.addAsync('observe-sequence - initial data for all sequence types', async function (test) { + await runOneObserveSequenceTestCase(test, function () { return null; }, function () {}, []); - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return []; }, function () {}, []); - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return [{foo: 1}, {bar: 2}]; }, function () {}, [ {addedAt: [0, {foo: 1}, 0, null]}, {addedAt: [1, {bar: 2}, 1, null]} ]); - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return [{_id: "13", foo: 1}, {_id: "37", bar: 2}]; }, function () {}, [ {addedAt: ["13", {_id: "13", foo: 1}, 0, null]}, @@ -169,7 +169,7 @@ Tinytest.add('observe-sequence - initial data for all sequence types', function ]); // sub-classed arrays - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return new ArraySubclass({_id: "13", foo: 1}, {_id: "37", bar: 2}); }, function () {}, [ {addedAt: ["13", {_id: "13", foo: 1}, 0, null]}, @@ -177,14 +177,14 @@ Tinytest.add('observe-sequence - initial data for all sequence types', function ]); // Execute in VM - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return new runInVM('new Array({_id: "13", foo: 1}, {_id: "37", bar: 2})'); }, function () {}, [ {addedAt: ["13", {_id: "13", foo: 1}, 0, null]}, {addedAt: ["37", {_id: "37", bar: 2}, 1, null]} ]); - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { const coll = new Mongo.Collection(null); coll.insert({_id: "13", foo: 1}); coll.insert({_id: "37", bar: 2}); @@ -197,7 +197,7 @@ Tinytest.add('observe-sequence - initial data for all sequence types', function // shouldn't break on array with duplicate _id's, and the ids sent // in the callbacks should be distinct - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return [ {_id: "13", foo: 1}, {_id: "13", foo: 2} @@ -208,12 +208,12 @@ Tinytest.add('observe-sequence - initial data for all sequence types', function ], /*numExpectedWarnings = */1); // non-array iterable (empty) - if(typeof Map == 'function') runOneObserveSequenceTestCase(test, function () { + if(typeof Map == 'function') await runOneObserveSequenceTestCase(test, function () { return new Map(); }, function () {}, []); // non-array iterable (non-empty) - if(typeof Set == 'function') runOneObserveSequenceTestCase(test, function () { + if(typeof Set == 'function') await runOneObserveSequenceTestCase(test, function () { return new Set([{foo: 1}, {bar: 2}]); }, function () {}, [ {addedAt: [0, {foo: 1}, 0, null]}, @@ -221,11 +221,11 @@ Tinytest.add('observe-sequence - initial data for all sequence types', function ]); }); -Tinytest.add('observe-sequence - array to other array', function (test) { +Tinytest.addAsync('observe-sequence - array to other array', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "13", foo: 1}, {_id: "37", bar: 2}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -240,11 +240,11 @@ Tinytest.add('observe-sequence - array to other array', function (test) { ]); }); -Tinytest.add('observe-sequence - array to other array, strings', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, strings', async function (test) { const dep = new Tracker.Dependency; let seq = ["A", "B"]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -258,8 +258,8 @@ Tinytest.add('observe-sequence - array to other array, strings', function (test) ]); }); -Tinytest.add('observe-sequence - bug #7850 array with null values', function (test) { - runOneObserveSequenceTestCase(test, function () { +Tinytest.addAsync('observe-sequence - bug #7850 array with null values', async function (test) { + await runOneObserveSequenceTestCase(test, function () { return [1, null]; }, function () {}, [ {addedAt: [1, 1, 0, null]}, @@ -267,11 +267,11 @@ Tinytest.add('observe-sequence - bug #7850 array with null values', function (te ]); }); -Tinytest.add('observe-sequence - array to other array, objects without ids', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, objects without ids', async function (test) { const dep = new Tracker.Dependency; let seq = [{foo: 1}, {bar: 2}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -285,11 +285,11 @@ Tinytest.add('observe-sequence - array to other array, objects without ids', fun ]); }); -Tinytest.add('observe-sequence - array to other array, changes', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, changes', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "13", foo: 1}, {_id: "37", bar: 2}, {_id: "42", baz: 42}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -308,11 +308,11 @@ Tinytest.add('observe-sequence - array to other array, changes', function (test) ]); }); -Tinytest.add('observe-sequence - array to other array, movedTo', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, movedTo', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "13", foo: 1}, {_id: "37", bar: 2}, {_id: "42", baz: 42}, {_id: "43", baz: 43}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -334,11 +334,11 @@ Tinytest.add('observe-sequence - array to other array, movedTo', function (test) ]); }); -Tinytest.add('observe-sequence - array to other array, movedTo the end', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, movedTo the end', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "0"}, {_id: "1"}, {_id: "2"}, {_id: "3"}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -358,11 +358,11 @@ Tinytest.add('observe-sequence - array to other array, movedTo the end', functio ]); }); -Tinytest.add('observe-sequence - array to other array, movedTo later position but not the latest #2845', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, movedTo later position but not the latest #2845', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "0"}, {_id: "1"}, {_id: "2"}, {_id: "3"}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -383,11 +383,11 @@ Tinytest.add('observe-sequence - array to other array, movedTo later position bu ]); }); -Tinytest.add('observe-sequence - array to other array, movedTo earlier position but not the first', function (test) { +Tinytest.addAsync('observe-sequence - array to other array, movedTo earlier position but not the first', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "0"}, {_id: "1"}, {_id: "2"}, {_id: "3"}, {_id: "4"}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -410,11 +410,11 @@ Tinytest.add('observe-sequence - array to other array, movedTo earlier position ]); }); -Tinytest.add('observe-sequence - array to null', function (test) { +Tinytest.addAsync('observe-sequence - array to null', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "13", foo: 1}, {_id: "37", bar: 2}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -428,11 +428,11 @@ Tinytest.add('observe-sequence - array to null', function (test) { ]); }); -Tinytest.add('observe-sequence - array to cursor', function (test) { +Tinytest.addAsync('observe-sequence - array to cursor', async function (test) { const dep = new Tracker.Dependency; let seq = [{_id: "13", foo: 1}, {_id: "37", bar: 2}]; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -452,7 +452,7 @@ Tinytest.add('observe-sequence - array to cursor', function (test) { }); -Tinytest.add('observe-sequence - cursor to null', function (test) { +Tinytest.addAsync('observe-sequence - cursor to null', async function (test) { const dep = new Tracker.Dependency; const coll = new Mongo.Collection(null); coll.insert({_id: "13", foo: 1}); @@ -460,7 +460,7 @@ Tinytest.add('observe-sequence - cursor to null', function (test) { const cursor = coll.find({}, {sort: {_id: 1}}); let seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -474,14 +474,14 @@ Tinytest.add('observe-sequence - cursor to null', function (test) { ]); }); -Tinytest.add('observe-sequence - cursor to array', function (test) { +Tinytest.addAsync('observe-sequence - cursor to array', async function (test) { const dep = new Tracker.Dependency; const coll = new Mongo.Collection(null); coll.insert({_id: "13.5", foo: 1}); const cursor = coll.find({}, {sort: {_id: 1}}); let seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -497,13 +497,13 @@ Tinytest.add('observe-sequence - cursor to array', function (test) { ]); }); -Tinytest.add('observe-sequence - cursor', function (test) { +Tinytest.addAsync('observe-sequence - cursor', async function (test) { const coll = new Mongo.Collection(null); coll.insert({_id: "13", rank: 1}); const cursor = coll.find({}, {sort: {rank: 1}}); const seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { return seq; }, async function () { await coll.insertAsync({_id: "37", rank: 2}); @@ -527,14 +527,14 @@ Tinytest.add('observe-sequence - cursor', function (test) { ]); }); -Tinytest.add('observe-sequence - cursor to other cursor', function (test) { +Tinytest.addAsync('observe-sequence - cursor to other cursor', async function (test) { const dep = new Tracker.Dependency; const coll = new Mongo.Collection(null); coll.insert({_id: "13", foo: 1}); const cursor = coll.find({}, {sort: {_id: 1}}); let seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -555,7 +555,7 @@ Tinytest.add('observe-sequence - cursor to other cursor', function (test) { ]); }); -Tinytest.add('observe-sequence - cursor to other cursor with transform', function (test) { +Tinytest.addAsync('observe-sequence - cursor to other cursor with transform', async function (test) { const dep = new Tracker.Dependency; const transform = function(doc) { return Object.assign({idCopy: doc._id}, doc); @@ -566,7 +566,7 @@ Tinytest.add('observe-sequence - cursor to other cursor with transform', functio const cursor = coll.find({}, {sort: {_id: 1}}); let seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -587,14 +587,14 @@ Tinytest.add('observe-sequence - cursor to other cursor with transform', functio ]); }); -Tinytest.add('observe-sequence - cursor to same cursor', function (test) { +Tinytest.addAsync('observe-sequence - cursor to same cursor', async function (test) { const coll = new Mongo.Collection(null); coll.insert({_id: "13", rank: 1}); const cursor = coll.find({}, {sort: {rank: 1}}); const seq = cursor; const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -613,11 +613,11 @@ Tinytest.add('observe-sequence - cursor to same cursor', function (test) { ]); }); -Tinytest.add('observe-sequence - string arrays', function (test) { +Tinytest.addAsync('observe-sequence - string arrays', async function (test) { let seq = ['A', 'B']; const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -631,11 +631,11 @@ Tinytest.add('observe-sequence - string arrays', function (test) { ]); }); -Tinytest.add('observe-sequence - number arrays', function (test) { +Tinytest.addAsync('observe-sequence - number arrays', async function (test) { let seq = [1, 1, 2]; const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -651,11 +651,11 @@ Tinytest.add('observe-sequence - number arrays', function (test) { ]); }); -Tinytest.add('observe-sequence - subclassed number arrays', function (test) { +Tinytest.addAsync('observe-sequence - subclassed number arrays', async function (test) { let seq = new ArraySubclass(1, 1, 2); const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -671,11 +671,11 @@ Tinytest.add('observe-sequence - subclassed number arrays', function (test) { ]); }); -Tinytest.add('observe-sequence - vm generated number arrays', function (test) { +Tinytest.addAsync('observe-sequence - vm generated number arrays', async function (test) { let seq = runInVM('new Array(1, 1, 2)'); const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -691,11 +691,11 @@ Tinytest.add('observe-sequence - vm generated number arrays', function (test) { ]); }); -Tinytest.add('observe-sequence - number arrays, _id:0 correctly handled, no duplicate ids warning #4049', function (test) { +Tinytest.addAsync('observe-sequence - number arrays, _id:0 correctly handled, no duplicate ids warning #4049', async function (test) { let seq = [...Array(3).keys()].map(function (i) { return { _id: i}; }); const dep = new Tracker.Dependency; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { @@ -716,7 +716,7 @@ Tinytest.add('observe-sequence - number arrays, _id:0 correctly handled, no dupl ]); }); -Tinytest.add('observe-sequence - cursor to other cursor, same collection', function (test) { +Tinytest.addAsync('observe-sequence - cursor to other cursor, same collection', async function (test) { const dep = new Tracker.Dependency; const coll = new Mongo.Collection(null); coll.insert({_id: "13", foo: 1}); @@ -724,7 +724,7 @@ Tinytest.add('observe-sequence - cursor to other cursor, same collection', funct const cursor = coll.find({foo: 1}); let seq = cursor; - runOneObserveSequenceTestCase(test, function () { + await runOneObserveSequenceTestCase(test, function () { dep.depend(); return seq; }, function () { diff --git a/packages/spacebars-tests/.versions b/packages/spacebars-tests/.versions index 1d782853c..b311664f4 100644 --- a/packages/spacebars-tests/.versions +++ b/packages/spacebars-tests/.versions @@ -30,7 +30,6 @@ html-tools@2.0.0 htmljs@2.0.1 id-map@1.2.0 inter-process-messaging@0.1.2 -jquery@3.0.2 local-test:spacebars-tests@2.0.1 logging@1.3.5 markdown@2.0.0 diff --git a/packages/spacebars-tests/old_templates_tests.js b/packages/spacebars-tests/old_templates_tests.js index e2d6406de..bfea0a6dd 100644 --- a/packages/spacebars-tests/old_templates_tests.js +++ b/packages/spacebars-tests/old_templates_tests.js @@ -2,7 +2,7 @@ // This file is used to ensure old built templates still work with the // new Blaze APIs. More in a comment at the top of old_templates.js // - +const hasJquery = Blaze._DOMBackend._hasJQuery; const divRendersTo = function (test, div, html) { Tracker.flush({ _throwFirstError: true }); const actual = canonicalizeHtml(div.innerHTML); @@ -107,7 +107,7 @@ Tinytest.add( }; const div = renderToDiv(tmpl); - test.equal($(div).find('div')[0].className, 'aaa124zzz'); + test.equal(div.querySelector('div').className, 'aaa124zzz'); } ); @@ -126,7 +126,9 @@ Tinytest.add( }; const div = renderToDiv(tmpl); - const span = $(div).find('span')[0]; + const span = hasJquery + ? $(div).find('span')[0] + : div.querySelector('span'); test.equal(span.innerHTML, 'hi'); test.isTrue(span.hasAttribute('selected')); test.equal(span.getAttribute('x'), 'X'); @@ -153,7 +155,9 @@ Tinytest.add( }; let div = renderToDiv(tmpl); - let elems = $(div).find('> *'); + let elems = hasJquery + ? $(div).find('> *') + : div.querySelectorAll(':scope > *'); test.equal(elems.length, 1); test.equal(elems[0].nodeName, 'SPAN'); let span = elems[0]; @@ -162,13 +166,17 @@ Tinytest.add( R.set('asdf'); Tracker.flush(); - elems = $(div).find('> *'); + elems = hasJquery + ? $(div).find('> *') + : div.querySelectorAll(':scope > *'); test.equal(elems.length, 0); test.equal(canonicalizeHtml(div.innerHTML), 'asdf'); R.set('blah'); Tracker.flush(); - elems = $(div).find('> *'); + elems = hasJquery + ? $(div).find('> *') + : div.querySelectorAll(':scope > *'); test.equal(elems.length, 1); test.equal(elems[0].nodeName, 'SPAN'); span = elems[0]; @@ -575,7 +583,7 @@ Tinytest.add( } ); -Tinytest.add( +Tinytest.addAsync( 'spacebars-tests - old - template_tests - each on cursor', async function (test) { const tmpl = Template.old_spacebars_template_test_each; @@ -680,7 +688,7 @@ Tinytest.add('spacebars-tests - old - template_tests - ..', function (test) { ); }); -Tinytest.add( +Tinytest.addAsync( 'spacebars-tests - old - template_tests - select tags', async function (test) { const tmpl = Template.old_spacebars_template_test_select_tag; @@ -702,7 +710,9 @@ Tinytest.add( }; const div = renderToDiv(tmpl); - const selectEl = $(div).find('select')[0]; + const selectEl = hasJquery + ? $(div).find('select')[0] + : div.querySelector('select'); // returns canonicalized contents of `div` in the form eg // [""]. strip out selected attributes -- we @@ -751,8 +761,8 @@ Tinytest.add( '', ]); test.equal(selectEl.value, 'value2'); - test.equal($(selectEl).find('option')[0].selected, false); - test.equal($(selectEl).find('option')[1].selected, true); + test.equal(selectEl.querySelectorAll('option')[0].selected, false); + test.equal(selectEl.querySelectorAll('option')[1].selected, true); // swap selection await options.updateAsync({ value: 'value1' }, { $set: { selected: true } }); @@ -770,8 +780,8 @@ Tinytest.add( '', ]); test.equal(selectEl.value, 'value1'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); + test.equal(selectEl.querySelectorAll('option')[0].selected, true); + test.equal(selectEl.querySelectorAll('option')[1].selected, false); // change value and label await options.updateAsync({ value: 'value1' }, { $set: { value: 'value1.0' } }); @@ -789,8 +799,8 @@ Tinytest.add( '', ]); test.equal(selectEl.value, 'value1.0'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); + test.equal(selectEl.querySelectorAll('option')[0].selected, true); + test.equal(selectEl.querySelectorAll('option')[1].selected, false); // unselect and then select both options. normally, the second is // selected (since it got selected later). then switch to ", ""]. strip out selected attributes -- we @@ -866,8 +867,8 @@ Tinytest.add('spacebars-tests - template_tests - select tags', async function (t '', ]); test.equal(selectEl.value, 'value2'); - test.equal($(selectEl).find('option')[0].selected, false); - test.equal($(selectEl).find('option')[1].selected, true); + test.equal(selectEl.querySelectorAll('option')[0].selected, false); + test.equal(selectEl.querySelectorAll('option')[1].selected, true); // swap selection await options.updateAsync({ value: 'value2' }, { $set: { selected: false } }); @@ -885,8 +886,8 @@ Tinytest.add('spacebars-tests - template_tests - select tags', async function (t '', ]); test.equal(selectEl.value, 'value1'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); + test.equal(selectEl.querySelectorAll('option')[0].selected, true); + test.equal(selectEl.querySelectorAll('option')[1].selected, false); // change value and label await options.updateAsync({ value: 'value1' }, { $set: { value: 'value1.0' } }); @@ -904,8 +905,8 @@ Tinytest.add('spacebars-tests - template_tests - select tags', async function (t '', ]); test.equal(selectEl.value, 'value1.0'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); + test.equal(selectEl.querySelectorAll('option')[0].selected, true); + test.equal(selectEl.querySelectorAll('option')[1].selected, false); // unselect and then select both options. normally, the second is // selected (since it got selected later). then switch to