From 5384a60c58df62fd969bd54ffef3f83c5f91fb15 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Tue, 6 Jun 2023 09:24:24 -0300 Subject: [PATCH] fix: Failing tests of deprecated packages --- packages/deprecated/http/httpcall_client.js | 4 +- packages/deprecated/http/httpcall_server.js | 10 ++++- packages/deprecated/http/httpcall_tests.js | 42 +++++++++---------- packages/deprecated/http/package.js | 4 ++ packages/deprecated/http/test_responder.js | 8 ++-- packages/deprecated/markdown/package.js | 2 +- .../stylus/plugin/compile-stylus.js | 17 +++++--- 7 files changed, 52 insertions(+), 35 deletions(-) diff --git a/packages/deprecated/http/httpcall_client.js b/packages/deprecated/http/httpcall_client.js index 5cfb02a0df..b3d7d1125d 100644 --- a/packages/deprecated/http/httpcall_client.js +++ b/packages/deprecated/http/httpcall_client.js @@ -66,6 +66,8 @@ HTTP.call = function(method, url, options, callback) { throw new Error('Option auth should be of the form "username:password"'); username = options.auth.substring(0, colonLoc); password = options.auth.substring(colonLoc+1); + + headers["Authorization"] = "Basic " + btoa(username + ":" + password); } if (params_for_body) { @@ -110,7 +112,7 @@ HTTP.call = function(method, url, options, callback) { else throw new Error("Can't create XMLHttpRequest"); // ??? - xhr.open(method, url, true, username, password); + xhr.open(method, url, true); for (var k in headers) xhr.setRequestHeader(k, headers[k]); diff --git a/packages/deprecated/http/httpcall_server.js b/packages/deprecated/http/httpcall_server.js index 9ed4549c5f..5efe752100 100644 --- a/packages/deprecated/http/httpcall_server.js +++ b/packages/deprecated/http/httpcall_server.js @@ -1,4 +1,4 @@ -import { Meteor } from 'meteor/meteor'; +import Util from 'util'; import { fetch, Request } from 'meteor/fetch'; import { URL, URLSearchParams } from 'meteor/url'; import { HTTP, makeErrorByStatus, populateData } from './httpcall_common.js'; @@ -162,4 +162,10 @@ function _call (method, url, options, callback) { } // we are keeping wrapAsync here as this package is deprecated -HTTP.call = Meteor.wrapAsync(_call); +HTTP.call = function(...args) { + const cb = args.pop(); + if (typeof cb === 'function') { + return _call(...args, cb); + } + return Util.promisify(_call)(...args, cb); +} diff --git a/packages/deprecated/http/httpcall_tests.js b/packages/deprecated/http/httpcall_tests.js index b5aa4f258c..08c23a3a7c 100644 --- a/packages/deprecated/http/httpcall_tests.js +++ b/packages/deprecated/http/httpcall_tests.js @@ -20,8 +20,8 @@ const url_prefix = function () { } testAsyncMulti('httpcall - basic', [ - function (test, expect) { - const basic_get = function (url, options, expected_url) { + async function (test, expect) { + const basic_get = async function (url, options, expected_url) { const callback = function (error, result) { test.isFalse(error); if (!error) { @@ -46,7 +46,7 @@ testAsyncMulti('httpcall - basic', [ if (Meteor.isServer) { // test sync version try { - const result = HTTP.call('GET', url_prefix() + url, options); + const result = await HTTP.call('GET', url_prefix() + url, options); callback(undefined, result); } catch (e) { callback(e, e.response); @@ -54,49 +54,49 @@ testAsyncMulti('httpcall - basic', [ } }; - basic_get('/foo', null, '/foo'); - basic_get('/foo?', null, '/foo?'); - basic_get('/foo?a=b', null, '/foo?a=b'); - basic_get('/foo', { params: { fruit: 'apple' } }, '/foo?fruit=apple'); - basic_get('/foo', { + await basic_get('/foo', null, '/foo'); + await basic_get('/foo?', null, '/foo?'); + await basic_get('/foo?a=b', null, '/foo?a=b'); + await basic_get('/foo', { params: { fruit: 'apple' } }, '/foo?fruit=apple'); + await basic_get('/foo', { params: { fruit: 'apple', dog: 'Spot the dog' } }, '/foo?fruit=apple&dog=Spot+the+dog'); - basic_get('/foo?', { + await basic_get('/foo?', { params: { fruit: 'apple', dog: 'Spot the dog' } }, '/foo?fruit=apple&dog=Spot+the+dog'); - basic_get('/foo?bar', { + await basic_get('/foo?bar', { params: { fruit: 'apple', dog: 'Spot the dog' } }, '/foo?bar&fruit=apple&dog=Spot+the+dog'); - basic_get('/foo?bar', { + await basic_get('/foo?bar', { params: { fruit: 'apple', dog: 'Spot the dog' }, query: 'baz' }, '/foo?baz&fruit=apple&dog=Spot+the+dog'); - basic_get('/foo', { + await basic_get('/foo', { params: { fruit: 'apple', dog: 'Spot the dog' }, query: 'baz' }, '/foo?baz&fruit=apple&dog=Spot+the+dog'); - basic_get('/foo?', { + await basic_get('/foo?', { params: { fruit: 'apple', dog: 'Spot the dog' }, query: 'baz' }, '/foo?baz&fruit=apple&dog=Spot+the+dog'); - basic_get('/foo?bar', { query: '' }, '/foo?'); - basic_get('/foo?bar', { + await basic_get('/foo?bar', { query: '' }, '/foo?'); + await basic_get('/foo?bar', { params: { fruit: 'apple', dog: 'Spot the dog' }, query: '' }, '/foo?fruit=apple&dog=Spot+the+dog'); }]); testAsyncMulti('httpcall - errors', [ - function (test, expect) { + async function (test, expect) { // Accessing unknown server (should fail to make any connection) const unknownServerCallback = function (error, result) { test.equal(!!error, true,'expected error'); @@ -113,7 +113,7 @@ testAsyncMulti('httpcall - errors', [ if (Meteor.isServer) { // test sync version try { - const unknownServerResult = HTTP.call('GET', `http://${invalidIp}/`); + const unknownServerResult = await HTTP.call('GET', `http://${invalidIp}/`); unknownServerCallback(undefined, unknownServerResult); } catch (e) { unknownServerCallback(e, e.response); @@ -143,7 +143,7 @@ testAsyncMulti('httpcall - errors', [ if (Meteor.isServer) { // test sync version try { - const error500Result = HTTP.call('GET', url_prefix() + '/fail'); + const error500Result = await HTTP.call('GET', url_prefix() + '/fail'); error500Callback(undefined, error500Result); } catch (e) { error500Callback(e, e.response); @@ -154,7 +154,7 @@ testAsyncMulti('httpcall - errors', [ testAsyncMulti('httpcall - timeout', [ - function (test, expect) { + async function (test, expect) { // Should time out const timeoutCallback = function (error, result) { @@ -171,7 +171,7 @@ testAsyncMulti('httpcall - timeout', [ if (Meteor.isServer) { // test sync version try { - const timeoutResult = HTTP.call('GET', timeoutUrl, { timeout: 500 }); + const timeoutResult = await HTTP.call('GET', timeoutUrl, { timeout: 500 }); timeoutCallback(undefined, timeoutResult); } catch (e) { timeoutCallback(e, e.response); @@ -194,7 +194,7 @@ testAsyncMulti('httpcall - timeout', [ if (Meteor.isServer) { // test sync version try { - const noTimeoutResult = HTTP.call('GET', noTimeoutUrl, { timeout: 2000 }); + const noTimeoutResult = await HTTP.call('GET', noTimeoutUrl, { timeout: 2000 }); noTimeoutCallback(undefined, noTimeoutResult); } catch (e) { noTimeoutCallback(e, e.response); diff --git a/packages/deprecated/http/package.js b/packages/deprecated/http/package.js index 22e35e1977..c4fe3a380e 100644 --- a/packages/deprecated/http/package.js +++ b/packages/deprecated/http/package.js @@ -19,6 +19,10 @@ Package.onUse(function (api) { api.export('HTTPInternals', 'server'); }); +Npm.depends({ + "express-basic-auth": "1.2.1" +}); + Package.onTest(function (api) { api.use('ecmascript'); api.use('webapp', 'server'); diff --git a/packages/deprecated/http/test_responder.js b/packages/deprecated/http/test_responder.js index 9e9e4cab04..aa6768ef45 100644 --- a/packages/deprecated/http/test_responder.js +++ b/packages/deprecated/http/test_responder.js @@ -1,3 +1,5 @@ +import basicAuth from 'express-basic-auth' + var TEST_RESPONDER_ROUTE = "/http_test_responder"; var respond = function(req, res) { @@ -31,8 +33,7 @@ var respond = function(req, res) { var validate = function(user, pass) { return user === username && pass === password; }; - var connect = WebAppInternals.NpmModules.connect.module; - var checker = connect.basicAuth(validate, realm); + var checker = basicAuth({ authorizer: validate, realm }); var success = false; checker(req, res, function() { success = true; @@ -76,8 +77,7 @@ var respond = function(req, res) { }; var run_responder = function() { - WebApp.expressHandlers.stack.unshift( - { route: TEST_RESPONDER_ROUTE, handle: respond }); + WebApp.expressHandlers.use(TEST_RESPONDER_ROUTE, respond); }; run_responder(); diff --git a/packages/deprecated/markdown/package.js b/packages/deprecated/markdown/package.js index 049b2fd055..4296a2a02a 100644 --- a/packages/deprecated/markdown/package.js +++ b/packages/deprecated/markdown/package.js @@ -11,7 +11,7 @@ Package.onUse(function (api) { api.versionsFrom('3.0-alpha.6'); api.use('ecmascript@1.0.0-alpha300.6'); api.use("templating@2.0.0-alpha300.6", "client", {weak: true}); - api.mainModule('template-integration.js', 'client', { lazy: true }); + api.mainModule('template-integration.js', 'client'); }); Package.onTest(function (api) { diff --git a/packages/deprecated/stylus/plugin/compile-stylus.js b/packages/deprecated/stylus/plugin/compile-stylus.js index 5d6e5b492d..617434eed4 100644 --- a/packages/deprecated/stylus/plugin/compile-stylus.js +++ b/packages/deprecated/stylus/plugin/compile-stylus.js @@ -1,8 +1,7 @@ +const util = require('util'); const stylus = Npm.require('stylus'); const nib = Npm.require('nib'); const autoprefixer = Npm.require('autoprefixer-stylus'); -// TODO Review fiber use -const Future = Meteor._isFibersEnabled ? Npm.require('fibers/future') : null; const fs = Plugin.fs; const path = Plugin.path; @@ -47,7 +46,7 @@ class StylusCompiler extends MultiFileCachingCompiler { return ! /\.import\.styl$/.test(pathInPackage); } - compileOneFile(inputFile, allFiles) { + async compileOneFile(inputFile, allFiles) { const referencedImportPaths = []; function parseImportPath(filePath, importerDir) { @@ -155,7 +154,7 @@ class StylusCompiler extends MultiFileCachingCompiler { const fileOptions = inputFile.getFileOptions(); - const f = new Future; + // const f = new Future; let style = stylus(inputFile.getContentsAsString()).use(nib()) @@ -168,10 +167,16 @@ class StylusCompiler extends MultiFileCachingCompiler { .set('cache', false) .set('importer', importer); - style.render(f.resolver()); + const prom = new Promise((resolve, reject) => { + style.render((err, data) => { + if (err) return reject(err); + resolve(data); + }) + }); + let css; try { - css = f.wait(); + css = await prom; } catch (e) { inputFile.error({ message: 'Stylus compiler error: ' + e.message