mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
make connection utility to capture messages
This commit is contained in:
@@ -447,20 +447,9 @@ Tinytest.addAsync("livedata server - waiting for Promise", (test, onComplete) =>
|
||||
* https://github.com/meteor/meteor/issues/13212
|
||||
*/
|
||||
Tinytest.addAsync('livedata server - publish cursor is properly awaited', async function (test) {
|
||||
const messages = []
|
||||
|
||||
let sub = null;
|
||||
|
||||
const { clientConn } = await getTestConnections(test)
|
||||
|
||||
const send = clientConn._stream.send
|
||||
|
||||
clientConn._stream.send = function (...args) {
|
||||
send.apply(this, args)
|
||||
messages.push(args[0])
|
||||
}
|
||||
|
||||
clientConn._stream.on('message', message => messages.push(message));
|
||||
const { conn, messages, cleanup } = await captureConnectionMessages(test);
|
||||
|
||||
const coll = new Mongo.Collection('items', {
|
||||
defineMutationMethods: false,
|
||||
@@ -482,7 +471,7 @@ Tinytest.addAsync('livedata server - publish cursor is properly awaited', async
|
||||
const reactiveVar = new ReactiveVar(1);
|
||||
|
||||
const computation = Tracker.autorun(() => {
|
||||
sub = clientConn.subscribe(publicationName, reactiveVar.get());
|
||||
sub = conn.subscribe(publicationName, reactiveVar.get());
|
||||
});
|
||||
|
||||
await sleep(100)
|
||||
@@ -496,11 +485,13 @@ Tinytest.addAsync('livedata server - publish cursor is properly awaited', async
|
||||
/**
|
||||
* There shouldn't ever be `removed` messages here, otherwise the UI will glitch
|
||||
*/
|
||||
const parsedMessages = messages.map(m => EJSON.parse(m).msg)
|
||||
const parsedMessages = messages.map(m => m.msg)
|
||||
|
||||
test.equal(parsedMessages, expectedMessages)
|
||||
|
||||
computation.stop();
|
||||
|
||||
cleanup()
|
||||
});
|
||||
|
||||
function getTestConnections(test) {
|
||||
|
||||
@@ -52,3 +52,34 @@ makeTestConnection = function (test, succeeded, failed) {
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
createTestConnectionPromise = function (test) {
|
||||
return new Promise((resolve, reject) => {
|
||||
makeTestConnection(test, resolve, reject);
|
||||
});
|
||||
};
|
||||
|
||||
captureConnectionMessages = async function (test) {
|
||||
const messages = []
|
||||
|
||||
const conn = await createTestConnectionPromise(test);
|
||||
|
||||
const send = conn._stream.send;
|
||||
|
||||
conn._stream.send = function (...args) {
|
||||
send.apply(this, args);
|
||||
messages.push(EJSON.parse(args[0]));
|
||||
}
|
||||
|
||||
conn._stream.on('message', message => messages.push(EJSON.parse(message)));
|
||||
|
||||
function cleanup() {
|
||||
conn._stream.send = send
|
||||
}
|
||||
|
||||
return {
|
||||
conn,
|
||||
messages,
|
||||
cleanup
|
||||
}
|
||||
};
|
||||
@@ -22,15 +22,29 @@ Package.onUse(function (api) {
|
||||
// the like.
|
||||
api.use('ddp');
|
||||
|
||||
|
||||
api.export([
|
||||
'pollUntil', 'try_all_permutations',
|
||||
'SeededRandom', 'clickElement', 'blurElement',
|
||||
'focusElement', 'simulateEvent', 'getStyleProperty', 'canonicalizeHtml',
|
||||
'renderToDiv', 'clickIt',
|
||||
'withCallbackLogger', 'testAsyncMulti',
|
||||
'simplePoll', 'runAndThrowIfNeeded',
|
||||
'makeTestConnection', 'DomUtils', 'mockBehaviours', 'waitUntil']);
|
||||
'pollUntil',
|
||||
'try_all_permutations',
|
||||
'SeededRandom',
|
||||
'clickElement',
|
||||
'blurElement',
|
||||
'focusElement',
|
||||
'simulateEvent',
|
||||
'getStyleProperty',
|
||||
'canonicalizeHtml',
|
||||
'renderToDiv',
|
||||
'clickIt',
|
||||
'withCallbackLogger',
|
||||
'testAsyncMulti',
|
||||
'simplePoll',
|
||||
'runAndThrowIfNeeded',
|
||||
'DomUtils',
|
||||
'mockBehaviours',
|
||||
'waitUntil',
|
||||
'makeTestConnection',
|
||||
'createTestConnectionPromise',
|
||||
'captureConnectionMessages',
|
||||
]);
|
||||
|
||||
api.addFiles('try_all_permutations.js');
|
||||
api.addFiles('async_multi.js');
|
||||
|
||||
Reference in New Issue
Block a user