From 8eba20f55e31967604b2c55e6eea393d84f6c2d2 Mon Sep 17 00:00:00 2001 From: harryadel Date: Fri, 21 Oct 2022 12:13:59 +0200 Subject: [PATCH 01/16] [webapp] Remove underscore --- packages/webapp/package.js | 4 ++-- packages/webapp/webapp_server.js | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/webapp/package.js b/packages/webapp/package.js index 5464ea7dc8..7459ba1903 100644 --- a/packages/webapp/package.js +++ b/packages/webapp/package.js @@ -15,6 +15,7 @@ Npm.depends({ qs: '6.10.1', useragent: '2.3.0', '@vlasky/whomst': '0.1.7', + 'lodash.has': '4.5.2' }); Npm.strip({ @@ -32,7 +33,6 @@ Package.onUse(function(api) { api.use( [ 'logging', - 'underscore', 'routepolicy', 'modern-browsers', 'boilerplate-generator', @@ -60,7 +60,7 @@ Package.onUse(function(api) { }); Package.onTest(function(api) { - api.use(['tinytest', 'ecmascript', 'webapp', 'http', 'underscore']); + api.use(['tinytest', 'ecmascript', 'webapp', 'http']); api.addFiles('webapp_tests.js', 'server'); api.addFiles('webapp_client_tests.js', 'client'); api.addFiles('socket_file_tests.js', 'server'); diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 03d6de971b..8ad6c220d1 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -20,6 +20,7 @@ import { } from './socket_file.js'; import cluster from 'cluster'; import whomst from '@vlasky/whomst'; +import has from 'lodash.has'; var SHORT_SOCKET_TIMEOUT = 5 * 1000; var LONG_SOCKET_TIMEOUT = 120 * 1000; @@ -194,12 +195,12 @@ WebApp.categorizeRequest = function(req) { var htmlAttributeHooks = []; var getHtmlAttributes = function(request) { var combinedAttributes = {}; - _.each(htmlAttributeHooks || [], function(hook) { + (htmlAttributeHooks || []).forEach(function(hook) { var attributes = hook(request); if (attributes === null) return; if (typeof attributes !== 'object') throw Error('HTML attribute hook must return null or object'); - _.extend(combinedAttributes, attributes); + Object.assign(combinedAttributes, attributes); }); return combinedAttributes; }; @@ -282,7 +283,7 @@ WebApp._timeoutAdjustmentRequestCallback = function(req, res) { res.on('finish', function() { res.setTimeout(SHORT_SOCKET_TIMEOUT); }); - _.each(finishListeners, function(l) { + finishListeners.forEach(function(l) { res.on('finish', l); }); }; @@ -435,13 +436,14 @@ function getBoilerplateAsync(request, arch) { }); }); runtimeConfig.isUpdatedByArch[arch] = false; + const { dynamicHead, dynamicBody } = request; const data = Object.assign( {}, boilerplate.baseData, { htmlAttributes: getHtmlAttributes(request), }, - _.pick(request, 'dynamicHead', 'dynamicBody') + { dynamicHead, dynamicBody } ); let madeChanges = false; @@ -524,9 +526,8 @@ WebAppInternals.generateBoilerplateInstance = function( return pathJoin(archPath[arch], itemPath); }, baseDataExtension: { - additionalStaticJs: _.map(additionalStaticJs || [], function( - contents, - pathname + additionalStaticJs: (Object.entries(additionalStaticJs) || []).map(function( + [pathname, contents] ) { return { pathname: pathname, @@ -603,7 +604,7 @@ WebAppInternals.staticFilesMiddleware = async function( }; if ( - _.has(additionalStaticJs, pathname) && + has(additionalStaticJs, pathname) && !WebAppInternals.inlineScriptsAllowed() ) { serveStaticJs(additionalStaticJs[pathname]); @@ -1338,7 +1339,7 @@ function runWebAppServer() { }); // start up app - _.extend(WebApp, { + Object.assign(WebApp, { connectHandlers: packageAndAppHandlers, rawConnectHandlers: rawConnectHandlers, httpServer: httpServer, From a410b87752247e272a9876ec7e6c81a9aa4c9d8b Mon Sep 17 00:00:00 2001 From: harryadel Date: Fri, 21 Oct 2022 13:21:13 +0200 Subject: [PATCH 02/16] [test-helpers] Remove underscore --- packages/test-helpers/async_multi.js | 24 +++++++++---------- packages/test-helpers/callback_logger.js | 19 ++++++++------- packages/test-helpers/connection.js | 4 +++- packages/test-helpers/event_simulation.js | 4 ++-- packages/test-helpers/package.js | 9 +++++-- packages/test-helpers/try_all_permutations.js | 2 +- .../test-helpers/try_all_permutations_test.js | 4 ++-- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/test-helpers/async_multi.js b/packages/test-helpers/async_multi.js index e5ec3cb43c..22e15576bd 100644 --- a/packages/test-helpers/async_multi.js +++ b/packages/test-helpers/async_multi.js @@ -52,32 +52,32 @@ var ExpectationManager = function (test, onComplete) { self.outstanding = 0; }; -_.extend(ExpectationManager.prototype, { - expect: function (/* arguments */) { +Object.assign(ExpectationManager.prototype, { + expect: function (...args) { var self = this; - if (typeof arguments[0] === "function") - var expected = arguments[0]; + if (typeof args[0] === "function") + var expected = args[0]; else - var expected = _.toArray(arguments); + var expected = args; if (self.closed) throw new Error("Too late to add more expectations to the test"); self.outstanding++; - return function (/* arguments */) { + return function (...args) { if (self.dead) return; if (typeof expected === "function") { try { - expected.apply({}, arguments); + expected.apply({}, args); } catch (e) { if (self.cancel()) self.test.exception(e); } } else { - self.test.equal(_.toArray(arguments), expected); + self.test.equal(args, expected); } self.outstanding--; @@ -115,12 +115,12 @@ testAsyncMulti = function (name, funcs, { isOnly = false } = {}) { const addFunction = isOnly ? Tinytest.onlyAsync : Tinytest.addAsync; addFunction(name, function (test, onComplete) { - var remaining = _.clone(funcs); + var remaining = Object.assign({}, funcs); var context = {}; var i = 0; var runNext = function () { - var func = remaining.shift(); + var func = Object.values(remaining).shift(); if (!func) { delete test.extraDetails.asyncBlock; onComplete(); @@ -142,7 +142,7 @@ testAsyncMulti = function (name, funcs, { isOnly = false } = {}) { test.extraDetails.asyncBlock = i++; new Promise(resolve => { - resolve(func.apply(context, [test, _.bind(em.expect, em)])); + resolve(func.apply(context, [test, em.expect.bind(em)])); }).then(result => { em.done(); }, exception => { @@ -190,4 +190,4 @@ pollUntil = function (expect, f, timeout, step, noFail) { timeout, step ); -}; +}; \ No newline at end of file diff --git a/packages/test-helpers/callback_logger.js b/packages/test-helpers/callback_logger.js index fb4f30ee07..4f6e661baf 100644 --- a/packages/test-helpers/callback_logger.js +++ b/packages/test-helpers/callback_logger.js @@ -1,3 +1,6 @@ +import isEmpty from 'lodash.isempty'; +import isEqual from 'lodash.isequal'; + // This file allows you to write tests that expect certain callbacks to be // called in certain orders, or optionally in groups where the order does not // matter. It can be set up in either a synchronous manner, so that each @@ -19,7 +22,7 @@ withCallbackLogger = function (test, callbackNames, async, fun) { if (async) { if (!Fiber) throw new Error("Fiber is not available"); - logger.fiber = Fiber(_.bind(fun, null, logger)); + logger.fiber = Fiber(fun.bind(null, logger)); logger.fiber.run(); } else { fun(logger); @@ -31,9 +34,9 @@ var CallbackLogger = function (test, callbackNames) { self._log = []; self._test = test; self._yielded = false; - _.each(callbackNames, function (callbackName) { + callbackNames.forEach(function (callbackName) { self[callbackName] = function () { - var args = _.toArray(arguments); + var args = Array.from(arguments); self._log.push({callback: callbackName, args: args}); if (self.fiber) { setTimeout(function () { @@ -56,7 +59,7 @@ CallbackLogger.prototype._yield = function (arg) { CallbackLogger.prototype.expectResult = function (callbackName, args) { var self = this; self._waitForLengthOrTimeout(1); - if (_.isEmpty(self._log)) { + if (isEmpty(self._log)) { self._test.fail(["Expected callback " + callbackName + " got none"]); return; } @@ -93,13 +96,13 @@ CallbackLogger.prototype.expectResultUnordered = function (list) { self._waitForLengthOrTimeout(list.length); - list = _.clone(list); // shallow copy. + list = [...list]; // shallow copy. var i = list.length; while (i > 0) { var found = false; var dequeued = self._log.shift(); for (var j = 0; j < list.length; j++) { - if (_.isEqual(list[j], dequeued)) { + if (isEqual(list[j], dequeued)) { list.splice(j, 1); found = true; break; @@ -131,11 +134,11 @@ CallbackLogger.prototype.expectNoResult = function (fn) { self.fiber.run(handle); }, TIMEOUT); var foo = self._yield(); - while (_.isEmpty(self._log) && foo !== handle) { + while (isEmpty(self._log) && foo !== handle) { foo = self._yield(); } clearTimeout(handle); } self._expectNoResultImpl(); -}; +}; \ No newline at end of file diff --git a/packages/test-helpers/connection.js b/packages/test-helpers/connection.js index a78c3dab46..6d597bb0a3 100644 --- a/packages/test-helpers/connection.js +++ b/packages/test-helpers/connection.js @@ -1,3 +1,5 @@ +import isString from 'lodash.isstring'; + // Establish a connection from the server to the server, and wait // until the client side of the connection has received the session // id. On success call `succeeded` with two arguments, the client @@ -13,7 +15,7 @@ makeTestConnection = function (test, succeeded, failed) { // Add incoming connections to `serverConns`. var onConnectionHandle = Meteor.onConnection(function (serverConn) { - test.isTrue(_.isString(serverConn.id), "connection handle id exists and is a string"); + test.isTrue(isString(serverConn.id), "connection handle id exists and is a string"); if (serverConns[serverConn.id]) { test.fail("onConnection callback called multiple times for same session id"); failed(); diff --git a/packages/test-helpers/event_simulation.js b/packages/test-helpers/event_simulation.js index cf4ed8b3af..c4f8cc1086 100644 --- a/packages/test-helpers/event_simulation.js +++ b/packages/test-helpers/event_simulation.js @@ -9,11 +9,11 @@ simulateEvent = function (node, event, args, options) { if (document.createEvent) { var e = document.createEvent("Event"); e.initEvent(event, bubbles, true); - _.extend(e, args); + Object.assign(e, args); node.dispatchEvent(e); } else { var e = document.createEventObject(); - _.extend(e, args); + Object.assign(e, args); node.fireEvent("on" + event, e); } }; diff --git a/packages/test-helpers/package.js b/packages/test-helpers/package.js index 17b6e0f37a..6a2e6992f3 100644 --- a/packages/test-helpers/package.js +++ b/packages/test-helpers/package.js @@ -3,10 +3,15 @@ Package.describe({ version: '1.3.0' }); +Npm.depends({ + 'lodash.isequal': '4.5.0', + 'lodash.isempty': '4.4.0', + 'lodash.isstring': '4.0.1' +}); + Package.onUse(function (api) { api.use([ 'ecmascript', - 'underscore', 'tracker', 'ejson', 'tinytest', @@ -45,7 +50,7 @@ Package.onUse(function (api) { Package.onTest(function (api) { api.use('tinytest'); - api.use(['test-helpers', 'underscore']); + api.use(['test-helpers']); api.addFiles('try_all_permutations_test.js', 'client'); api.addFiles('seeded_random_test.js'); }); diff --git a/packages/test-helpers/try_all_permutations.js b/packages/test-helpers/try_all_permutations.js index 2276c10a01..5b60aa62b9 100644 --- a/packages/test-helpers/try_all_permutations.js +++ b/packages/test-helpers/try_all_permutations.js @@ -39,7 +39,7 @@ try_all_permutations = function () { var expand_next_set = function () { if (current_set === args.length) { - _.each(chosen, function (f) { f(); }); + chosen.forEach(function (f) { f(); }); } else { var set = args[current_set]; if (typeof set === "function") diff --git a/packages/test-helpers/try_all_permutations_test.js b/packages/test-helpers/try_all_permutations_test.js index f9bebffea9..4c9b451fff 100644 --- a/packages/test-helpers/try_all_permutations_test.js +++ b/packages/test-helpers/try_all_permutations_test.js @@ -61,7 +61,7 @@ Tinytest.add("test-helpers - try_all_permutations", function (test) { var seen = {}; for (var i = 0; i < n; i++) - fs.push(_.bind(function (x) { seq += x + "_"; }, null, i)); + fs.push(function (x) { seq += x + "_"; }.bind(null, i)); try_all_permutations( function () {seq = "";}, fs, @@ -75,7 +75,7 @@ Tinytest.add("test-helpers - try_all_permutations", function (test) { var expected_count = 1; for (var i = n; i >= 1; i--) expected_count *= i; - test.equal(_.keys(seen).length, expected_count); + test.equal(Object.keys(seen).length, expected_count); }; for (var i = 1; i <= 5; i++) From 605b47cb2a4e9b961647417f7020c93d02ab7870 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sat, 22 Oct 2022 09:46:40 +0200 Subject: [PATCH 03/16] [boilerplate-generator-tests] Remove underscore --- packages/boilerplate-generator-tests/package.js | 1 - packages/boilerplate-generator-tests/web.browser-tests.js | 5 ----- packages/boilerplate-generator-tests/web.cordova-tests.js | 5 +---- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/boilerplate-generator-tests/package.js b/packages/boilerplate-generator-tests/package.js index 7878ff66f2..ec3a817612 100644 --- a/packages/boilerplate-generator-tests/package.js +++ b/packages/boilerplate-generator-tests/package.js @@ -14,7 +14,6 @@ Npm.depends({ Package.onTest(function (api) { api.use('ecmascript'); api.use([ - 'underscore', 'tinytest', 'boilerplate-generator' ], 'server'); diff --git a/packages/boilerplate-generator-tests/web.browser-tests.js b/packages/boilerplate-generator-tests/web.browser-tests.js index 915e2f6ebf..48c0d06fd8 100644 --- a/packages/boilerplate-generator-tests/web.browser-tests.js +++ b/packages/boilerplate-generator-tests/web.browser-tests.js @@ -1,6 +1,5 @@ import { parse, serialize } from 'parse5'; import { generateHTMLForArch } from './test-lib'; -import { _ } from 'meteor/underscore'; Tinytest.addAsync( "boilerplate-generator-tests - web.browser - basic output", @@ -66,10 +65,6 @@ Tinytest.addAsync( async function (test) { const newHtml = await generateHTMLForArch("web.browser", false); - _.templateSettings = { - interpolate: /\{\{(.+?)\}\}/g - }; - test.matches(newHtml, /foo="foobar"/); test.matches(newHtml, /]*href="[^<>]*bootstrap[^<>]*">/); test.matches(newHtml, /]*src="[^<>]*templating[^<>]*">/); diff --git a/packages/boilerplate-generator-tests/web.cordova-tests.js b/packages/boilerplate-generator-tests/web.cordova-tests.js index 04eb249ac5..ffe954105e 100644 --- a/packages/boilerplate-generator-tests/web.cordova-tests.js +++ b/packages/boilerplate-generator-tests/web.cordova-tests.js @@ -1,6 +1,5 @@ import { parse, serialize } from 'parse5'; import { generateHTMLForArch } from './test-lib'; -import { _ } from 'meteor/underscore'; Tinytest.addAsync( "boilerplate-generator-tests - web.cordova - basic output", @@ -60,9 +59,7 @@ Tinytest.addAsync( async function (test) { const newHtml = await generateHTMLForArch('web.cordova', false); - _.templateSettings = { - interpolate: /\{\{(.+?)\}\}/g - }; + test.matches(newHtml, /]*href="[^<>]*bootstrap[^<>]*">/); test.matches(newHtml, /]*src="[^<>]*templating[^<>]*">/); test.matches(newHtml, /