mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
# Conflicts: # .circleci/config.yml # docs/generators/changelog/script.js # docs/history.md # meteor # npm-packages/babel-preset-meteor/package.json # npm-packages/cordova-plugin-meteor-webapp/package.json # npm-packages/eslint-plugin-meteor/scripts/dev-bundle-tool-package.js # npm-packages/meteor-babel/package-lock.json # npm-packages/meteor-babel/package.json # package-lock.json # package.json # packages/accounts-base/accounts_server.js # packages/accounts-base/package.js # packages/accounts-oauth/package.js # packages/accounts-password/package.js # packages/accounts-password/password_server.js # packages/accounts-passwordless/package.js # packages/accounts-passwordless/passwordless_server.js # packages/babel-compiler/.npm/package/npm-shrinkwrap.json # packages/babel-compiler/package.js # packages/boilerplate-generator/package.js # packages/browser-policy-content/package.js # packages/constraint-solver/catalog-loader.js # packages/constraint-solver/constraint-solver-input.js # packages/constraint-solver/constraint-solver-tests.js # packages/constraint-solver/constraint-solver.js # packages/constraint-solver/package.js # packages/constraint-solver/solver.js # packages/crosswalk/package.js # packages/ddp-rate-limiter/package.js # packages/ddp-server/package.js # packages/ecmascript/package.js # packages/facebook-oauth/package.js # packages/fetch/package.js # packages/launch-screen/package.js # packages/logging/package.js # packages/logic-solver/logic_tests.js # packages/logic-solver/package.js # packages/meteor-tool/package.js # packages/meteor/package.js # packages/mobile-experience/package.js # packages/modern-browsers/package.js # packages/modules/.npm/package/npm-shrinkwrap.json # packages/modules/package.js # packages/mongo/package.js # packages/non-core/blaze # packages/npm-mongo/.npm/package/npm-shrinkwrap.json # packages/npm-mongo/package.js # packages/oauth/package.js # packages/oauth/pending_credentials.js # packages/package-version-parser/package.js # packages/react-fast-refresh/package.js # packages/service-configuration/package.js # packages/socket-stream-client/.npm/package/npm-shrinkwrap.json # packages/socket-stream-client/package.js # packages/standard-minifier-css/.npm/plugin/minifyStdCSS/npm-shrinkwrap.json # packages/standard-minifier-css/package.js # packages/test-in-browser/package.js # packages/test-in-console/package.js # packages/test-in-console/reporter.js # packages/tinytest/package.js # packages/tracker/package.js # packages/typescript/package.js # packages/webapp/.npm/package/npm-shrinkwrap.json # packages/webapp/package.js # scripts/admin/meteor-release-experimental.json # scripts/build-dev-bundle-common.sh # scripts/dev-bundle-server-package.js # scripts/dev-bundle-tool-package.js # tools/cli/commands.js # tools/fs/files.ts # tools/runners/run-all.js # tools/static-assets/skel-chakra-ui/package.json # tools/tests/apps/dynamic-import/.meteor/packages # tools/tests/apps/dynamic-import/package.json
229 lines
6.5 KiB
JavaScript
229 lines
6.5 KiB
JavaScript
import { Meteor } from "meteor/meteor";
|
|
import { Tracker } from "meteor/tracker";
|
|
import { HTTP } from "meteor/http";
|
|
import { toSockjsUrl } from "./urls.js";
|
|
import { ClientStream } from "meteor/socket-stream-client";
|
|
import isEqual from "lodash.isequal";
|
|
import once from "lodash.once";
|
|
|
|
Tinytest.add('stream - status', function(test) {
|
|
// Very basic test. Just see that it runs and returns something. Not a
|
|
// lot of coverage, but enough that it would have caught a recent bug.
|
|
var status = Meteor.status();
|
|
test.equal(typeof status, 'object');
|
|
test.isTrue(status.status);
|
|
});
|
|
|
|
testAsyncMulti('stream - reconnect', [
|
|
function(test, expect) {
|
|
var callback = once(
|
|
expect(function() {
|
|
var status;
|
|
status = Meteor.status();
|
|
test.equal(status.status, 'connected');
|
|
|
|
Meteor.reconnect();
|
|
status = Meteor.status();
|
|
test.equal(status.status, 'connected');
|
|
|
|
Meteor.reconnect({ _force: true });
|
|
status = Meteor.status();
|
|
test.equal(status.status, 'waiting');
|
|
})
|
|
);
|
|
|
|
if (Meteor.status().status !== 'connected')
|
|
Meteor.connection._stream.on('reset', callback);
|
|
else callback();
|
|
}
|
|
]);
|
|
|
|
// Disconnecting and reconnecting transitions through the correct statuses.
|
|
testAsyncMulti('stream - basic disconnect', [
|
|
function(test, expect) {
|
|
var history = [];
|
|
var stream = new ClientStream('/');
|
|
var onTestComplete = expect(function(unexpectedHistory) {
|
|
stream.disconnect();
|
|
if (unexpectedHistory) {
|
|
test.fail(
|
|
'Unexpected status history: ' + JSON.stringify(unexpectedHistory)
|
|
);
|
|
}
|
|
});
|
|
|
|
Tracker.autorun(function() {
|
|
var status = stream.status();
|
|
|
|
if (history[history.length -1] !== status.status) {
|
|
history.push(status.status);
|
|
|
|
if (isEqual(history, ['connecting'])) {
|
|
// do nothing; wait for the next state
|
|
} else if (isEqual(history, ['connecting', 'connected'])) {
|
|
stream.disconnect();
|
|
} else if (isEqual(history, ['connecting', 'connected', 'offline'])) {
|
|
stream.reconnect();
|
|
} else if (
|
|
isEqual(history, [
|
|
'connecting',
|
|
'connected',
|
|
'offline',
|
|
'connecting'
|
|
])
|
|
) {
|
|
// do nothing; wait for the next state
|
|
} else if (
|
|
isEqual(history, [
|
|
'connecting',
|
|
'connected',
|
|
'offline',
|
|
'connecting',
|
|
'connected'
|
|
])
|
|
) {
|
|
onTestComplete();
|
|
} else if (
|
|
_.isEqual(history, [
|
|
'connecting',
|
|
'connected',
|
|
'offline',
|
|
'connecting',
|
|
'connected',
|
|
'offline',
|
|
])
|
|
) {
|
|
// do nothing;
|
|
} else {
|
|
onTestComplete(history);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
]);
|
|
|
|
// Remain offline if the online event is received while offline.
|
|
testAsyncMulti('stream - disconnect remains offline', [
|
|
function(test, expect) {
|
|
var history = [];
|
|
var stream = new ClientStream('/');
|
|
var onTestComplete = expect(function(unexpectedHistory) {
|
|
stream.disconnect();
|
|
if (unexpectedHistory) {
|
|
test.fail(
|
|
'Unexpected status history: ' + JSON.stringify(unexpectedHistory)
|
|
);
|
|
}
|
|
});
|
|
|
|
Tracker.autorun(function() {
|
|
var status = stream.status();
|
|
|
|
if (history[history.length - 1] !== status.status) {
|
|
history.push(status.status);
|
|
|
|
if (isEqual(history, ['connecting'])) {
|
|
// do nothing; wait for the next status
|
|
} else if (isEqual(history, ['connecting', 'connected'])) {
|
|
stream.disconnect();
|
|
} else if (isEqual(history, ['connecting', 'connected', 'offline'])) {
|
|
stream._online();
|
|
test.isTrue(status.status === 'offline');
|
|
onTestComplete();
|
|
} else {
|
|
onTestComplete(history);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
]);
|
|
|
|
Tinytest.add('stream - sockjs urls are computed correctly', function(test) {
|
|
var testHasSockjsUrl = function(raw, expectedSockjsUrl) {
|
|
var actual = toSockjsUrl(raw);
|
|
if (expectedSockjsUrl instanceof RegExp)
|
|
test.isTrue(actual.match(expectedSockjsUrl), actual);
|
|
else test.equal(actual, expectedSockjsUrl);
|
|
};
|
|
|
|
testHasSockjsUrl(
|
|
'http://subdomain.meteor.com/',
|
|
'http://subdomain.meteor.com/sockjs'
|
|
);
|
|
testHasSockjsUrl(
|
|
'http://subdomain.meteor.com',
|
|
'http://subdomain.meteor.com/sockjs'
|
|
);
|
|
testHasSockjsUrl(
|
|
'subdomain.meteor.com/',
|
|
'http://subdomain.meteor.com/sockjs'
|
|
);
|
|
testHasSockjsUrl(
|
|
'subdomain.meteor.com',
|
|
'http://subdomain.meteor.com/sockjs'
|
|
);
|
|
testHasSockjsUrl('/', Meteor._relativeToSiteRootUrl('/sockjs'));
|
|
|
|
testHasSockjsUrl('http://localhost:3000/', 'http://localhost:3000/sockjs');
|
|
testHasSockjsUrl('http://localhost:3000', 'http://localhost:3000/sockjs');
|
|
testHasSockjsUrl('localhost:3000', 'http://localhost:3000/sockjs');
|
|
|
|
testHasSockjsUrl(
|
|
'https://subdomain.meteor.com/',
|
|
'https://subdomain.meteor.com/sockjs'
|
|
);
|
|
testHasSockjsUrl(
|
|
'https://subdomain.meteor.com',
|
|
'https://subdomain.meteor.com/sockjs'
|
|
);
|
|
|
|
testHasSockjsUrl(
|
|
'ddp+sockjs://ddp--****-foo.meteor.com/sockjs',
|
|
/^https:\/\/ddp--\d\d\d\d-foo\.meteor\.com\/sockjs$/
|
|
);
|
|
testHasSockjsUrl(
|
|
'ddpi+sockjs://ddp--****-foo.meteor.com/sockjs',
|
|
/^http:\/\/ddp--\d\d\d\d-foo\.meteor\.com\/sockjs$/
|
|
);
|
|
});
|
|
|
|
testAsyncMulti('stream - /websocket is a websocket endpoint', [
|
|
function(test, expect) {
|
|
//
|
|
// Verify that /websocket and /websocket/ don't return the main page
|
|
//
|
|
['/websocket', '/websocket/'].forEach((path) => {
|
|
HTTP.get(
|
|
Meteor._relativeToSiteRootUrl(path),
|
|
expect(function(error, result) {
|
|
test.isNotNull(error);
|
|
test.equal('Not a valid websocket request', result.content);
|
|
})
|
|
);
|
|
});
|
|
|
|
//
|
|
// For sanity, also verify that /websockets and /websockets/ return
|
|
// the main page
|
|
//
|
|
|
|
// Somewhat contorted but we can't call nested expects (XXX why?)
|
|
var pageContent;
|
|
var wrappedCallback = expect(function(error, result) {
|
|
test.isNull(error);
|
|
test.equal(pageContent, result.content);
|
|
});
|
|
|
|
HTTP.get(
|
|
Meteor._relativeToSiteRootUrl('/'),
|
|
expect(function(error, result) {
|
|
test.isNull(error);
|
|
pageContent = result.content;
|
|
|
|
['/websockets', '/websockets/'].forEach(function(path) {
|
|
HTTP.get(Meteor._relativeToSiteRootUrl(path), wrappedCallback);
|
|
});
|
|
})
|
|
);
|
|
}
|
|
]); |