fix: Failing tests of deprecated packages

This commit is contained in:
Rodrigo Nascimento
2023-06-06 09:24:24 -03:00
parent 806339e438
commit 5384a60c58
7 changed files with 52 additions and 35 deletions

View File

@@ -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]);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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');

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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