diff --git a/test/browser/connection.test.js b/test/browser/connection.test.js index e99ff6c8f..5239d826e 100644 --- a/test/browser/connection.test.js +++ b/test/browser/connection.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var { expect, assert } = chai; var transportPreferenceName = 'ably-transport-preference'; diff --git a/test/browser/http.test.js b/test/browser/http.test.js index d187b7ae4..f73d840f3 100644 --- a/test/browser/http.test.js +++ b/test/browser/http.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; @@ -35,7 +37,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('Should succeed in using fetch to publish a message', function (done) { const channel = rest.channels.get('http_test_channel'); - helper.whenPromiseSettles(channel.publish('test', 'Testing fetch support'), (err) => { + Helper.whenPromiseSettles(channel.publish('test', 'Testing fetch support'), (err) => { expect(err).to.not.exist; done(); }); @@ -49,7 +51,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { */ it('Should pass errors correctly', function (done) { const channel = rest.channels.get(''); - helper.whenPromiseSettles(channel.publish('test', 'Invalid message'), (err) => { + Helper.whenPromiseSettles(channel.publish('test', 'Invalid message'), (err) => { expect(err).to.exist; done(); }); diff --git a/test/browser/modular.test.js b/test/browser/modular.test.js index 5324eb97d..1e8e4c24b 100644 --- a/test/browser/modular.test.js +++ b/test/browser/modular.test.js @@ -21,9 +21,10 @@ import { MessageInteractions, } from '../../build/modular/index.mjs'; -function registerAblyModularTests(helper) { +function registerAblyModularTests(Helper) { describe('browser/modular', function () { this.timeout(10 * 1000); + const helper = new Helper(); const expect = chai.expect; const BufferUtils = BaseRest.Platform.BufferUtils; const loadTestData = async (dataPath) => { @@ -638,7 +639,7 @@ function registerAblyModularTests(helper) { const txClient = new BaseRealtime( helper.ablyClientOptions({ - clientId: helper.randomString(), + clientId: Helper.randomString(), plugins: { WebSocketTransport, FetchRequest, @@ -681,7 +682,7 @@ function registerAblyModularTests(helper) { const rxChannel = rxClient.channels.get('channel'); await monitorConnectionThenCloseAndFinish(async () => { - const txClientId = helper.randomString(); + const txClientId = Helper.randomString(); const txClient = new BaseRealtime( helper.ablyClientOptions({ clientId: txClientId, @@ -958,8 +959,8 @@ function registerAblyModularTests(helper) { // This function is called by browser_setup.js once `require` is available window.registerAblyModularTests = async () => { return new Promise((resolve) => { - require(['shared_helper'], (helper) => { - registerAblyModularTests(helper); + require(['shared_helper'], (Helper) => { + registerAblyModularTests(Helper); resolve(); }); }); diff --git a/test/browser/push.test.js b/test/browser/push.test.js index 7529b89c2..216d370c8 100644 --- a/test/browser/push.test.js +++ b/test/browser/push.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai', 'push'], function (Ably, helper, chai, PushPlugin) { +define(['ably', 'shared_helper', 'chai', 'push'], function (Ably, Helper, chai, PushPlugin) { + const helper = new Helper(); + const expect = chai.expect; const swUrl = '/push_sw.js'; let rest; diff --git a/test/browser/simple.test.js b/test/browser/simple.test.js index daa98fe7b..1ca61c8d3 100644 --- a/test/browser/simple.test.js +++ b/test/browser/simple.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('browser/simple', function () { @@ -71,7 +73,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { ably.connection.on('connected', function () { connectionTimeout.stop(); heartbeatTimeout = failWithin(25, done, ably, 'wait for heartbeat'); - helper.whenPromiseSettles(ably.connection.ping(), function (err) { + Helper.whenPromiseSettles(ably.connection.ping(), function (err) { heartbeatTimeout.stop(); done(err); ably.close(); @@ -115,7 +117,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { receiveMessagesTimeout = failWithin(15, done, ably, 'wait for published messages to be received'); timer = setInterval(function () { - helper.whenPromiseSettles(channel.publish('event0', 'Hello world at: ' + new Date()), function (err) { + Helper.whenPromiseSettles(channel.publish('event0', 'Hello world at: ' + new Date()), function (err) { sentCbCount++; checkFinish(); }); diff --git a/test/common/modules/shared_helper.js b/test/common/modules/shared_helper.js index a12c2af3f..e0d0906eb 100644 --- a/test/common/modules/shared_helper.js +++ b/test/common/modules/shared_helper.js @@ -23,286 +23,270 @@ define([ var unroutableHost = '10.255.255.1'; var unroutableAddress = 'http://' + unroutableHost + '/'; - function displayError(err) { - if (typeof err == 'string' || err == null) return err; - - var result = ''; - if (err.statusCode) result += err.statusCode + '; '; - if (typeof err.message == 'string') result += err.message; - if (typeof err.message == 'object') result += JSON.stringify(err.message); - - return result; - } + class SharedHelper { + setupApp = testAppModule.setup; + tearDownApp = testAppModule.tearDown; + createStats = testAppModule.createStatsFixtureData; + getTestApp = testAppModule.getTestApp; + + Ably = clientModule.Ably; + AblyRest = clientModule.AblyRest; + ablyClientOptions = clientModule.ablyClientOptions; + Utils = utils; + + loadTestData = testAppManager.loadJsonData; + testResourcesPath = testAppManager.testResourcesPath; + + availableTransports = availableTransports; + bestTransport = bestTransport; + unroutableHost = unroutableHost; + unroutableAddress = unroutableAddress; + flushTestLogs = globals.flushLogs; + + displayError(err) { + if (typeof err == 'string' || err == null) return err; + + var result = ''; + if (err.statusCode) result += err.statusCode + '; '; + if (typeof err.message == 'string') result += err.message; + if (typeof err.message == 'object') result += JSON.stringify(err.message); + + return result; + } - function monitorConnection(done, realtime, states) { - (states || ['failed', 'suspended']).forEach(function (state) { - realtime.connection.on(state, function () { - done(new Error('Connection monitoring: state changed to ' + state + ', aborting test')); - realtime.close(); + monitorConnection(done, realtime, states) { + (states || ['failed', 'suspended']).forEach(function (state) { + realtime.connection.on(state, function () { + done(new Error('Connection monitoring: state changed to ' + state + ', aborting test')); + realtime.close(); + }); }); - }); - } + } - async function monitorConnectionAsync(action, realtime, states) { - const monitoringResultPromise = new Promise((resolve, reject) => { - monitorConnection((err) => (err ? reject(err) : resolve()), realtime, states); - }); - const actionResultPromise = Promise.resolve(action()); + async monitorConnectionAsync(action, realtime, states) { + const monitoringResultPromise = new Promise((resolve, reject) => { + this.monitorConnection((err) => (err ? reject(err) : resolve()), realtime, states); + }); + const actionResultPromise = Promise.resolve(action()); - return Promise.race([monitoringResultPromise, actionResultPromise]); - } + return Promise.race([monitoringResultPromise, actionResultPromise]); + } - function closeAndFinish(done, realtime, err) { - if (typeof realtime === 'undefined') { - // Likely called in a catch block for an exception - // that occured before realtime was initialized - done(err); - return; + closeAndFinish(done, realtime, err) { + if (typeof realtime === 'undefined') { + // Likely called in a catch block for an exception + // that occured before realtime was initialized + done(err); + return; + } + if (Object.prototype.toString.call(realtime) == '[object Array]') { + var realtimes = realtime.filter(function (rt) { + return rt !== undefined; + }); + this.closeAndFinishSeveral(done, realtimes, err); + return; + } + this.callbackOnClose(realtime, function () { + done(err); + }); } - if (Object.prototype.toString.call(realtime) == '[object Array]') { - var realtimes = realtime.filter(function (rt) { - return rt !== undefined; + + async closeAndFinishAsync(realtime, err) { + return new Promise((resolve, reject) => { + this.closeAndFinish((err) => (err ? reject(err) : resolve()), realtime, err); }); - closeAndFinishSeveral(done, realtimes, err); - return; } - callbackOnClose(realtime, function () { - done(err); - }); - } - async function closeAndFinishAsync(realtime, err) { - return new Promise((resolve, reject) => { - closeAndFinish((err) => (err ? reject(err) : resolve()), realtime, err); - }); - } + /** + * Uses a callback to communicate the result of a `Promise`. The first argument passed to the callback will be either an error (when the promise is rejected) or `null` (when the promise is fulfilled). In the case where the promise is fulfilled, the resulting value will be passed to the callback as a second argument. + */ + static whenPromiseSettles(promise, callback) { + promise + .then((result) => { + callback(null, result); + }) + .catch((err) => { + callback(err); + }); + } - /** - * Uses a callback to communicate the result of a `Promise`. The first argument passed to the callback will be either an error (when the promise is rejected) or `null` (when the promise is fulfilled). In the case where the promise is fulfilled, the resulting value will be passed to the callback as a second argument. - */ - function whenPromiseSettles(promise, callback) { - promise - .then((result) => { - callback(null, result); - }) - .catch((err) => { - callback(err); + simulateDroppedConnection(realtime) { + // Go into the 'disconnected' state before actually disconnecting the transports + // to avoid the instantaneous reconnect attempt that would be triggered in + // notifyState by the active transport getting disconnected from a connected state + realtime.connection.once('disconnected', function () { + realtime.connection.connectionManager.disconnectAllTransports(); }); - } + realtime.connection.connectionManager.requestState({ state: 'disconnected' }); + } - function simulateDroppedConnection(realtime) { - // Go into the 'disconnected' state before actually disconnecting the transports - // to avoid the instantaneous reconnect attempt that would be triggered in - // notifyState by the active transport getting disconnected from a connected state - realtime.connection.once('disconnected', function () { + becomeSuspended(realtime, cb) { realtime.connection.connectionManager.disconnectAllTransports(); - }); - realtime.connection.connectionManager.requestState({ state: 'disconnected' }); - } - - function becomeSuspended(realtime, cb) { - realtime.connection.connectionManager.disconnectAllTransports(); - realtime.connection.once('disconnected', function () { - realtime.connection.connectionManager.notifyState({ state: 'suspended' }); - }); - if (cb) - realtime.connection.once('suspended', function () { - cb(); + realtime.connection.once('disconnected', function () { + realtime.connection.connectionManager.notifyState({ state: 'suspended' }); }); - } + if (cb) + realtime.connection.once('suspended', function () { + cb(); + }); + } - function callbackOnClose(realtime, callback) { - if (!realtime.connection.connectionManager.activeProtocol) { + callbackOnClose(realtime, callback) { + if (!realtime.connection.connectionManager.activeProtocol) { + platform.Config.nextTick(function () { + realtime.close(); + callback(); + }); + return; + } + realtime.connection.connectionManager.activeProtocol.transport.on('disposed', function () { + callback(); + }); + /* wait a tick before closing in order to avoid the final close + * happening synchronously in a publish/attach callback, which + * complicates channelattach_publish_invalid etc. */ platform.Config.nextTick(function () { realtime.close(); - callback(); }); - return; } - realtime.connection.connectionManager.activeProtocol.transport.on('disposed', function () { - callback(); - }); - /* wait a tick before closing in order to avoid the final close - * happening synchronously in a publish/attach callback, which - * complicates channelattach_publish_invalid etc. */ - platform.Config.nextTick(function () { - realtime.close(); - }); - } - function closeAndFinishSeveral(done, realtimeArray, e) { - async.map( - realtimeArray, - function (realtime, mapCb) { - var parallelItem = function (parallelCb) { - callbackOnClose(realtime, function () { - parallelCb(); + closeAndFinishSeveral(done, realtimeArray, e) { + async.map( + realtimeArray, + (realtime, mapCb) => { + var parallelItem = (parallelCb) => { + this.callbackOnClose(realtime, function () { + parallelCb(); + }); + }; + mapCb(null, parallelItem); + }, + function (err, parallelItems) { + async.parallel(parallelItems, function () { + if (err) { + done(err); + return; + } + done(e); }); - }; - mapCb(null, parallelItem); - }, - function (err, parallelItems) { - async.parallel(parallelItems, function () { - if (err) { - done(err); - return; - } - done(e); - }); - }, - ); - } - - /* testFn is assumed to be a function of realtimeOptions that returns a mocha test */ - function testOnAllTransports(name, testFn, skip) { - var itFn = skip ? it.skip : it; - let transports = availableTransports; - transports.forEach(function (transport) { - itFn( - name + '_with_' + transport + '_binary_transport', - testFn({ transports: [transport], useBinaryProtocol: true }), - ); - itFn( - name + '_with_' + transport + '_text_transport', - testFn({ transports: [transport], useBinaryProtocol: false }), + }, ); - }); - /* Plus one for no transport specified (ie use websocket/base mechanism if - * present). (we explicitly specify all transports since node only does - * websocket+nodecomet if comet is explicitly requested) - * */ - itFn(name + '_with_binary_transport', testFn({ transports, useBinaryProtocol: true })); - itFn(name + '_with_text_transport', testFn({ transports, useBinaryProtocol: false })); - } - - testOnAllTransports.skip = function (name, testFn) { - testOnAllTransports(name, testFn, true); - }; + } - function restTestOnJsonMsgpack(name, testFn, skip) { - var itFn = skip ? it.skip : it; - itFn(name + ' with binary protocol', async function () { - await testFn(new clientModule.AblyRest({ useBinaryProtocol: true }), name + '_binary'); - }); - itFn(name + ' with text protocol', async function () { - await testFn(new clientModule.AblyRest({ useBinaryProtocol: false }), name + '_text'); - }); - } + /* testFn is assumed to be a function of realtimeOptions that returns a mocha test */ + static testOnAllTransports(name, testFn, skip) { + var itFn = skip ? it.skip : it; + let transports = availableTransports; + transports.forEach(function (transport) { + itFn( + name + '_with_' + transport + '_binary_transport', + testFn({ transports: [transport], useBinaryProtocol: true }), + ); + itFn( + name + '_with_' + transport + '_text_transport', + testFn({ transports: [transport], useBinaryProtocol: false }), + ); + }); + /* Plus one for no transport specified (ie use websocket/base mechanism if + * present). (we explicitly specify all transports since node only does + * websocket+nodecomet if comet is explicitly requested) + * */ + itFn(name + '_with_binary_transport', testFn({ transports, useBinaryProtocol: true })); + itFn(name + '_with_text_transport', testFn({ transports, useBinaryProtocol: false })); + } - restTestOnJsonMsgpack.skip = function (name, testFn) { - restTestOnJsonMsgpack(name, testFn, true); - }; + static restTestOnJsonMsgpack(name, testFn, skip) { + var itFn = skip ? it.skip : it; + itFn(name + ' with binary protocol', async function () { + await testFn(new clientModule.AblyRest({ useBinaryProtocol: true }), name + '_binary'); + }); + itFn(name + ' with text protocol', async function () { + await testFn(new clientModule.AblyRest({ useBinaryProtocol: false }), name + '_text'); + }); + } - function clearTransportPreference() { - if (isBrowser && window.localStorage) { - window.localStorage.removeItem('ably-transport-preference'); + clearTransportPreference() { + if (isBrowser && window.localStorage) { + window.localStorage.removeItem('ably-transport-preference'); + } } - } - function isComet(transport) { - return transport.toString().indexOf('/comet/') > -1; - } + isComet(transport) { + return transport.toString().indexOf('/comet/') > -1; + } - function isWebsocket(transport) { - return !!transport.toString().match(/wss?\:/); - } + isWebsocket(transport) { + return !!transport.toString().match(/wss?\:/); + } - function randomString() { - return Math.random().toString().slice(2); - } + static randomString() { + return Math.random().toString().slice(2); + } - function testMessageEquality(one, two) { - // treat `null` same as `undefined` (using ==, rather than ===) - expect(one.encoding == two.encoding, "Encoding mismatch ('" + one.encoding + "' != '" + two.encoding + "').").to.be - .ok; + testMessageEquality(one, two) { + // treat `null` same as `undefined` (using ==, rather than ===) + expect(one.encoding == two.encoding, "Encoding mismatch ('" + one.encoding + "' != '" + two.encoding + "').").to + .be.ok; - if (typeof one.data === 'string' && typeof two.data === 'string') { - expect(one.data === two.data, 'String data contents mismatch.').to.be.ok; - return; - } + if (typeof one.data === 'string' && typeof two.data === 'string') { + expect(one.data === two.data, 'String data contents mismatch.').to.be.ok; + return; + } - if (BufferUtils.isBuffer(one.data) && BufferUtils.isBuffer(two.data)) { - expect(BufferUtils.areBuffersEqual(one.data, two.data), 'Buffer data contents mismatch.').to.equal(true); - return; - } + if (BufferUtils.isBuffer(one.data) && BufferUtils.isBuffer(two.data)) { + expect(BufferUtils.areBuffersEqual(one.data, two.data), 'Buffer data contents mismatch.').to.equal(true); + return; + } - var json1 = JSON.stringify(one.data); - var json2 = JSON.stringify(two.data); - if (null === json1 || undefined === json1 || null === json2 || undefined === json2) { - expect(false, 'JSON stringify failed.').to.be.ok; - return; + var json1 = JSON.stringify(one.data); + var json2 = JSON.stringify(two.data); + if (null === json1 || undefined === json1 || null === json2 || undefined === json2) { + expect(false, 'JSON stringify failed.').to.be.ok; + return; + } + expect(json1 === json2, 'JSON data contents mismatch.').to.be.ok; } - expect(json1 === json2, 'JSON data contents mismatch.').to.be.ok; - } - let activeClients = []; + static activeClients = []; - function AblyRealtime(options) { - const client = clientModule.AblyRealtime(options); - activeClients.push(client); - return client; - } + AblyRealtime(options) { + const client = clientModule.AblyRealtime(options); + SharedHelper.activeClients.push(client); + return client; + } - /* Slightly crude catch-all hook to close any dangling realtime clients left open - * after a test fails without calling closeAndFinish */ - function closeActiveClients() { - activeClients.forEach((client) => { - client.close(); - }); - activeClients = []; - } + /* Slightly crude catch-all hook to close any dangling realtime clients left open + * after a test fails without calling closeAndFinish */ + closeActiveClients() { + SharedHelper.activeClients.forEach((client) => { + client.close(); + }); + SharedHelper.activeClients = []; + } - function logTestResults() { - if (this.currentTest.isFailed()) { - const logs = globals.getLogs(); - if (logs.length > 0) { - // empty console.logs are for vertical spacing - console.log(); - console.log('Logs for failing test: \n'); - logs.forEach(([timestamp, log]) => { - console.log(timestamp, log); - }); - console.log(); + logTestResults(afterEachThis) { + if (afterEachThis.currentTest.isFailed()) { + const logs = globals.getLogs(); + if (logs.length > 0) { + // empty console.logs are for vertical spacing + console.log(); + console.log('Logs for failing test: \n'); + logs.forEach(([timestamp, log]) => { + console.log(timestamp, log); + }); + console.log(); + } } } } - return (module.exports = { - setupApp: testAppModule.setup, - tearDownApp: testAppModule.tearDown, - createStats: testAppModule.createStatsFixtureData, - getTestApp: testAppModule.getTestApp, - - Ably: clientModule.Ably, - AblyRest: clientModule.AblyRest, - AblyRealtime: AblyRealtime, - ablyClientOptions: clientModule.ablyClientOptions, - Utils: utils, - - loadTestData: testAppManager.loadJsonData, - testResourcesPath: testAppManager.testResourcesPath, - - displayError: displayError, - monitorConnection: monitorConnection, - monitorConnectionAsync: monitorConnectionAsync, - closeAndFinish: closeAndFinish, - closeAndFinishAsync: closeAndFinishAsync, - simulateDroppedConnection: simulateDroppedConnection, - becomeSuspended: becomeSuspended, - testOnAllTransports: testOnAllTransports, - restTestOnJsonMsgpack: restTestOnJsonMsgpack, - availableTransports: availableTransports, - bestTransport: bestTransport, - clearTransportPreference: clearTransportPreference, - isComet: isComet, - isWebsocket: isWebsocket, - unroutableHost: unroutableHost, - unroutableAddress: unroutableAddress, - whenPromiseSettles: whenPromiseSettles, - randomString: randomString, - testMessageEquality: testMessageEquality, - closeActiveClients, - logTestResults, - flushTestLogs: globals.flushLogs, - }); + SharedHelper.testOnAllTransports.skip = function (name, testFn) { + SharedHelper.testOnAllTransports(name, testFn, true); + }; + + SharedHelper.restTestOnJsonMsgpack.skip = function (name, testFn) { + SharedHelper.restTestOnJsonMsgpack(name, testFn, true); + }; + + return (module.exports = SharedHelper); }); diff --git a/test/realtime/auth.test.js b/test/realtime/auth.test.js index 8c7a8e393..1d4c4ae5f 100644 --- a/test/realtime/auth.test.js +++ b/test/realtime/auth.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var currentTime; var exampleTokenDetails; var exports = {}; @@ -15,7 +17,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async */ function getJWT(params, callback) { var authUrl = echoServer + '/createJWT'; - helper.whenPromiseSettles(http.doUri('get', authUrl, null, null, params), function (err, result) { + Helper.whenPromiseSettles(http.doUri('get', authUrl, null, null, params), function (err, result) { if (result.error) { callback(result.error, null); } @@ -34,13 +36,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } var rest = helper.AblyRest({ queryTime: true }); - helper.whenPromiseSettles(rest.time(), function (err, time) { + Helper.whenPromiseSettles(rest.time(), function (err, time) { if (err) { done(err); return; } else { currentTime = time; - helper.whenPromiseSettles(rest.auth.requestToken({}), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({}), function (err, tokenDetails) { try { expect(!err, err && helper.displayError(err)).to.be.ok; done(); @@ -60,7 +62,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async */ it('authbase0', function (done) { var realtime = helper.AblyRealtime({ queryTime: true }); - helper.whenPromiseSettles(realtime.auth.requestToken(), function (err, tokenDetails) { + Helper.whenPromiseSettles(realtime.auth.requestToken(), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -87,7 +89,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('auth_useAuthUrl_json', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -117,7 +119,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('auth_useAuthUrl_post_json', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -146,7 +148,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('auth_useAuthUrl_plainText', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -176,7 +178,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime, rest = helper.AblyRest(); var authCallback = function (tokenParams, callback) { - helper.whenPromiseSettles(rest.auth.createTokenRequest(tokenParams, null), function (err, tokenRequest) { + Helper.whenPromiseSettles(rest.auth.createTokenRequest(tokenParams, null), function (err, tokenRequest) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -218,7 +220,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async rest = helper.AblyRest(); var clientId = 'test clientid'; var authCallback = function (tokenParams, callback) { - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -259,7 +261,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime, rest = helper.AblyRest(); var authCallback = function (tokenParams, callback) { - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -298,7 +300,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('auth_useAuthUrl_mixed_authParams_qsParams', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.createTokenRequest(null, null), function (err, tokenRequest) { + Helper.whenPromiseSettles(rest.auth.createTokenRequest(null, null), function (err, tokenRequest) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -337,7 +339,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var rest = helper.AblyRest(), testClientId = 'testClientId'; var authCallback = function (tokenParams, callback) { - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -377,7 +379,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var clientRealtime, testClientId = 'test client id'; var rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -405,7 +407,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime, testClientId = 'test client id'; var rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: '*' }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: '*' }), function (err, tokenDetails) { if (err) { done(err); return; @@ -435,7 +437,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime, testClientId = 'test client id'; var rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: '*' }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: '*' }), function (err, tokenDetails) { if (err) { done(err); return; @@ -465,7 +467,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var clientRealtime, testClientId = 'test client id'; var rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -711,7 +713,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('authUrl_403_previously_active', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(null, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -723,7 +725,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.on('connected', function () { /* replace the authUrl and reauth */ - helper.whenPromiseSettles( + Helper.whenPromiseSettles( realtime.auth.authorize(null, { authUrl: echoServer + '/respondwith?status=403' }), function (err, tokenDetails) { try { @@ -752,12 +754,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RSA4b1 * @specpartial RSA4b - token expired */ - helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) { + Helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) { return function (done) { var clientRealtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ ttl: 5000 }, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ ttl: 5000 }, null), function (err, tokenDetails) { if (err) { done(err); return; @@ -817,7 +819,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var asyncFns = []; for (var i = 0; i < 10; i++) { asyncFns.push(function (callback) { - helper.whenPromiseSettles(rest.auth.createTokenRequest({}, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.createTokenRequest({}, null), function (err, tokenDetails) { if (err) { return callback(err); } @@ -853,14 +855,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire * @specpartial RSA10e - obtain new token from authcallback when previous expires */ - helper.testOnAllTransports('auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) { + Helper.testOnAllTransports('auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); var clientId = 'test clientid'; var authCallback = function (tokenParams, callback) { tokenParams.ttl = 5000; - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -900,14 +902,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire * @specpartial RSA10e - obtain new token from authcallback when previous expires */ - helper.testOnAllTransports('auth_token_string_expiry_with_authcallback', function (realtimeOpts) { + Helper.testOnAllTransports('auth_token_string_expiry_with_authcallback', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); var clientId = 'test clientid'; var authCallback = function (tokenParams, callback) { tokenParams.ttl = 5000; - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -945,12 +947,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RSA4a * @spec RSA4a2 */ - helper.testOnAllTransports('auth_token_string_expiry_with_token', function (realtimeOpts) { + Helper.testOnAllTransports('auth_token_string_expiry_with_token', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); var clientId = 'test clientid'; - helper.whenPromiseSettles( + Helper.whenPromiseSettles( rest.auth.requestToken({ ttl: 5000, clientId: clientId }, null), function (err, tokenDetails) { if (err) { @@ -991,12 +993,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RSA4a * @spec RSA4a2 */ - helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) { + Helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); var clientId = 'test clientid'; - helper.whenPromiseSettles( + Helper.whenPromiseSettles( rest.auth.requestToken({ ttl: 1, clientId: clientId }, null), function (err, tokenDetails) { if (err) { @@ -1039,7 +1041,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTC8 * @specskip */ - helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) { + Helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); @@ -1048,7 +1050,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async tokenParams.clientId = '*'; tokenParams.capability = firstTime ? { wrong: ['*'] } : { right: ['*'] }; firstTime = false; - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1060,7 +1062,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime = helper.AblyRealtime(helper.Utils.mixin(realtimeOpts, { authCallback: authCallback })); realtime.connection.once('connected', function () { var channel = realtime.channels.get('right'); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { try { expect(err, 'Check using first token, without channel attach capability').to.be.ok; expect(err.code).to.equal(40160, 'Check expected error code'); @@ -1070,14 +1072,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } /* soon after connected, reauth */ - helper.whenPromiseSettles(realtime.auth.authorize(null, null), function (err) { + Helper.whenPromiseSettles(realtime.auth.authorize(null, null), function (err) { try { expect(!err, err && helper.displayError(err)).to.be.ok; } catch (err) { done(err); return; } - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { try { expect(!err, 'Check using second token, with channel attach capability').to.be.ok; helper.closeAndFinish(done, realtime); @@ -1130,7 +1132,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var rest = helper.AblyRest(), authCallback = function (tokenParams, callback) { // Request a token (should happen twice) - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, tokenDetails) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1251,7 +1253,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime({ authCallback: authCallback }); realtime.connection.once('connected', function () { var channel = realtime.channels.get(jwtTestChannelName); - helper.whenPromiseSettles(channel.publish('greeting', 'Hello World!'), function (err) { + Helper.whenPromiseSettles(channel.publish('greeting', 'Hello World!'), function (err) { try { expect(err.code).to.equal(40160, 'Verify publish denied code'); expect(err.statusCode).to.equal(401, 'Verify publish denied status code'); @@ -1384,7 +1386,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('reauth_consistently_expired_token', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ ttl: 1 }), function (err, token) { + Helper.whenPromiseSettles(rest.auth.requestToken({ ttl: 1 }), function (err, token) { if (err) { done(err); return; @@ -1417,7 +1419,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('expired_token_no_autoremove_when_dont_have_servertime', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(), function (err, token) { + Helper.whenPromiseSettles(rest.auth.requestToken(), function (err, token) { if (err) { done(err); return; @@ -1445,7 +1447,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async it('expired_token_autoremove_when_have_servertime', function (done) { var realtime, rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken(), function (err, token) { + Helper.whenPromiseSettles(rest.auth.requestToken(), function (err, token) { if (err) { done(err); return; @@ -1459,7 +1461,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; realtime = helper.AblyRealtime({ authCallback: authCallback, autoConnect: false }); /* Set the server time offset */ - helper.whenPromiseSettles(realtime.time(), function () { + Helper.whenPromiseSettles(realtime.time(), function () { realtime.connect(); realtime.connection.on('connected', function () { try { @@ -1487,21 +1489,21 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async defaultTokenParams: { capability: { wrong: ['*'] } }, }); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(realtime.auth.authorize({ capability: { stillWrong: ['*'] } }), function (err) { + Helper.whenPromiseSettles(realtime.auth.authorize({ capability: { stillWrong: ['*'] } }), function (err) { try { expect(!err, 'Check first authorize cb was called').to.be.ok; } catch (err) { done(err); } }); - helper.whenPromiseSettles(realtime.auth.authorize({ capability: { alsoNope: ['*'] } }), function (err) { + Helper.whenPromiseSettles(realtime.auth.authorize({ capability: { alsoNope: ['*'] } }), function (err) { try { expect(!err, 'Check second authorize cb was called').to.be.ok; } catch (err) { done(err); } }); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( realtime.auth.authorize({ capability: { wtfAreYouThinking: ['*'] } }), function (err) { try { @@ -1511,11 +1513,11 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } }, ); - helper.whenPromiseSettles(realtime.auth.authorize({ capability: { right: ['*'] } }), function (err) { + Helper.whenPromiseSettles(realtime.auth.authorize({ capability: { right: ['*'] } }), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } - helper.whenPromiseSettles(realtime.channels.get('right').attach(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get('right').attach(), function (err) { try { expect(!err, (err && helper.displayError(err)) || 'Successfully attached').to.be.ok; helper.closeAndFinish(done, realtime); @@ -1528,7 +1530,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); /** @nospec */ - helper.testOnAllTransports('authorize_immediately_after_init', function (realtimeOpts) { + Helper.testOnAllTransports('authorize_immediately_after_init', function (realtimeOpts) { return function (done) { var realtime = helper.AblyRealtime({ useTokenAuth: true, @@ -1539,7 +1541,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async helper.closeAndFinish(done, realtime, err); }); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(realtime.channels.get('right').attach(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get('right').attach(), function (err) { try { expect(!err, (err && helper.displayError(err)) || 'Successfully attached').to.be.ok; helper.closeAndFinish(done, realtime); diff --git a/test/realtime/channel.test.js b/test/realtime/channel.test.js index 63f52e2f6..3d9d13ace 100644 --- a/test/realtime/channel.test.js +++ b/test/realtime/channel.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var exports = {}; var _exports = {}; var expect = chai.expect; @@ -10,7 +12,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return function (callback) { var timeout, received = false, - eventName = helper.randomString(); + eventName = Helper.randomString(); channel.subscribe(eventName, function (msg) { channel.unsubscribe(eventName); @@ -19,7 +21,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async callback(); }); - helper.whenPromiseSettles(testChannel.publish(eventName, null), function (err) { + Helper.whenPromiseSettles(testChannel.publish(eventName, null), function (err) { if (received) return; if (err) callback(err); timeout = setTimeout(function () { @@ -34,7 +36,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return function (callback) { var timeout, received = false, - eventName = helper.randomString(); + eventName = Helper.randomString(); channel.subscribe(eventName, function (message) { channel.presence.unsubscribe(eventName); @@ -43,7 +45,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async callback('checkCantSubscribe: unexpectedly received message'); }); - helper.whenPromiseSettles(testChannel.publish(eventName, null), function (err) { + Helper.whenPromiseSettles(testChannel.publish(eventName, null), function (err) { if (received) return; if (err) callback(err); timeout = setTimeout(function () { @@ -56,13 +58,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async function checkCanPublish(channel) { return function (callback) { - helper.whenPromiseSettles(channel.publish(null, null), callback); + Helper.whenPromiseSettles(channel.publish(null, null), callback); }; } function checkCantPublish(channel) { return function (callback) { - helper.whenPromiseSettles(channel.publish(null, null), function (err) { + Helper.whenPromiseSettles(channel.publish(null, null), function (err) { if (err && err.code === 40160) { callback(); } else { @@ -74,8 +76,8 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async function checkCanEnterPresence(channel) { return function (callback) { - var clientId = helper.randomString(); - helper.whenPromiseSettles(channel.presence.enterClient(clientId, null), function (err) { + var clientId = Helper.randomString(); + Helper.whenPromiseSettles(channel.presence.enterClient(clientId, null), function (err) { channel.presence.leaveClient(clientId); callback(err); }); @@ -84,7 +86,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async function checkCantEnterPresence(channel) { return function (callback) { - helper.whenPromiseSettles(channel.presence.enterClient(helper.randomString(), null), function (err) { + Helper.whenPromiseSettles(channel.presence.enterClient(Helper.randomString(), null), function (err) { if (err && err.code === 40160) { callback(); } else { @@ -98,7 +100,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return function (callback) { var timeout, received = false, - clientId = helper.randomString(); + clientId = Helper.randomString(); channel.presence.subscribe('enter', function (message) { channel.presence.unsubscribe('enter'); @@ -108,7 +110,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async callback(); }); - helper.whenPromiseSettles(testChannel.presence.enterClient(clientId, null), function (err) { + Helper.whenPromiseSettles(testChannel.presence.enterClient(clientId, null), function (err) { if (received) return; if (err) callback(err); timeout = setTimeout(function () { @@ -124,7 +126,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return function (callback) { var timeout, received = false, - clientId = helper.randomString(); + clientId = Helper.randomString(); channel.presence.subscribe('enter', function (message) { channel.presence.unsubscribe('enter'); @@ -134,7 +136,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async callback('checkCantPresenceSubscribe: unexpectedly received message'); }); - helper.whenPromiseSettles(testChannel.presence.enterClient(clientId, null), function (err) { + Helper.whenPromiseSettles(testChannel.presence.enterClient(clientId, null), function (err) { if (received) return; if (err) callback(err); timeout = setTimeout(function () { @@ -169,7 +171,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTS3c * @spec RTL16 */ - helper.testOnAllTransports('channelinit0', function (realtimeOpts) { + Helper.testOnAllTransports('channelinit0', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -205,13 +207,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @spec RTL4 */ - helper.testOnAllTransports('channelattach0', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach0', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.on('connected', function () { var channel0 = realtime.channels.get('channelattach0'); - helper.whenPromiseSettles(channel0.attach(), function (err) { + Helper.whenPromiseSettles(channel0.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -231,12 +233,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @spec RTL4 */ - helper.testOnAllTransports('channelattach2', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach2', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); var channel2 = realtime.channels.get('channelattach2'); - helper.whenPromiseSettles(channel2.attach(), function (err) { + Helper.whenPromiseSettles(channel2.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -257,7 +259,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL4 * @spec RTL5 */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'channelattach3', function (realtimeOpts) { return function (done) { @@ -265,11 +267,11 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.on('connected', function () { var channel0 = realtime.channels.get('channelattach3'); - helper.whenPromiseSettles(channel0.attach(), function (err) { + Helper.whenPromiseSettles(channel0.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } - helper.whenPromiseSettles(channel0.detach(), function (err) { + Helper.whenPromiseSettles(channel0.detach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -296,13 +298,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @spec RTL4d */ - helper.testOnAllTransports('channelattachempty', function (realtimeOpts) { + Helper.testOnAllTransports('channelattachempty', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { var channel0 = realtime.channels.get(''); - helper.whenPromiseSettles(channel0.attach(), function (err) { + Helper.whenPromiseSettles(channel0.attach(), function (err) { if (err) { setTimeout(function () { try { @@ -330,13 +332,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @spec RTL4d */ - helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) { + Helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { var channel = realtime.channels.get(':hell'); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { try { expect(channel.errorReason.code).to.equal(40010, 'Attach error was set as the channel errorReason'); @@ -370,12 +372,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @spec RTL6 */ - helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) { + Helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(realtime.channels.get('publish_no_attach').publish(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get('publish_no_attach').publish(), function (err) { if (err) { helper.closeAndFinish( done, @@ -399,12 +401,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @specpartial RTL6b - callback which is called with an error */ - helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(realtime.channels.get(':hell').publish(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get(':hell').publish(), function (err) { if (err) { try { expect(err.code).to.equal(40010, 'correct error code'); @@ -432,15 +434,15 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * * @nospec */ - helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(realtime.channels.get(':hell').attach(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get(':hell').attach(), function (err) { if (err) { /* attempt second attach */ - helper.whenPromiseSettles(realtime.channels.get(':hell').attach(), function (err) { + Helper.whenPromiseSettles(realtime.channels.get(':hell').attach(), function (err) { if (err) { setTimeout(function () { try { @@ -477,8 +479,8 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(), channel = realtime.channels.get('channelattachWhenState'); - helper.whenPromiseSettles(channel.attach(), function (err) { - helper.whenPromiseSettles(channel.whenState('attached'), function () { + Helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.whenState('attached'), function () { helper.closeAndFinish(done, realtime, err); }); }); @@ -500,7 +502,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async firedImmediately = false; channel.attach(); - helper.whenPromiseSettles(channel.whenState('attached'), function () { + Helper.whenPromiseSettles(channel.whenState('attached'), function () { firedImmediately = true; try { expect(channel.state).to.equal('attached', 'whenState fired when attached'); @@ -524,7 +526,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL4k1 * @spec RTL4m */ - helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsBasicChannelsGet'; try { @@ -538,7 +540,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async params: params, }; var channel = realtime.channels.get(testName, channelOptions); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -585,7 +587,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL4m * @spec RTL16 */ - helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsBasicSetOptions'; try { @@ -600,7 +602,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; var channel = realtime.channels.get(testName); channel.setOptions(channelOptions); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -638,7 +640,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL16 * @spec RTL7c */ - helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) { return function (done) { var testName = 'subscribeAfterSetOptions'; try { @@ -681,7 +683,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channel = realtime.channels.get(testName, { params: params, }); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -712,7 +714,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); /** @spec RTL16a */ - helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) { + Helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) { return function (done) { var testName = 'setOptionsCallbackBehaviour'; try { @@ -728,7 +730,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { var channelUpdated = false; @@ -736,7 +738,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channelUpdated = true; }); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.setOptions({ params: { modes: 'publish', @@ -761,7 +763,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channelUpdated = true; }); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.setOptions({ modes: ['subscribe'], }), @@ -790,7 +792,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Verify modes is ignored when params.modes is present * @nospec */ - helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsModesAndChannelModes'; try { @@ -805,7 +807,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async modes: ['publish', 'presence_subscribe'], }; var channel = realtime.channels.get(testName, channelOptions); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -851,7 +853,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL4l * @spec RTL4m */ - helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelModes'; try { @@ -862,7 +864,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async modes: modes, }; var channel = realtime.channels.get(testName, channelOptions); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -909,7 +911,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL4l * @spec RTL4m */ - helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsDeltaAndModes'; try { @@ -921,7 +923,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async params: { delta: 'vcdiff' }, }; var channel = realtime.channels.get(testName, channelOptions); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -975,7 +977,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { cb(err); }); }, @@ -983,7 +985,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { modes: 'subscribe', }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { expect(err.code).to.equal(40000, 'Check channelOptions validation error code'); expect(err.statusCode).to.equal(400, 'Check channelOptions validation error statusCode'); expect(channel.modes).to.deep.equal( @@ -997,7 +999,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { modes: [1, 'subscribe'], }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { expect(err.code).to.equal(40000, 'Check channelOptions validation error code'); expect(err.statusCode).to.equal(400, 'Check channelOptions validation error statusCode'); expect(channel.modes).to.deep.equal( @@ -1011,7 +1013,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { params: 'test', }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { expect(err.code).to.equal(40000, 'Check channelOptions validation error code'); expect(err.statusCode).to.equal(400, 'Check channelOptions validation error statusCode'); expect(channel.params).to.deep.equal({}, 'Check channel options params'); @@ -1023,7 +1025,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { params: { nonexistent: 'foo' }, }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function () { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function () { expect(channel.params).to.deep.equal({}, 'Check channel params'); cb(); }); @@ -1032,7 +1034,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { modes: undefined, }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { expect(err.code).to.equal(40000, 'Check channelOptions validation error code'); expect(err.statusCode).to.equal(400, 'Check channelOptions validation error statusCode'); expect(channel.params).to.deep.equal({}, 'Check channel options params result'); @@ -1047,7 +1049,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelOptions = { modes: ['susribe'], }; - helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { + Helper.whenPromiseSettles(channel.setOptions(channelOptions), function (err) { expect(err.code).to.equal(40000, 'Check channelOptions validation error code'); expect(err.statusCode).to.equal(400, 'Check channelOptions validation error statusCode'); expect(channel.params).to.deep.equal({}, 'Check channel options params result'); @@ -1082,7 +1084,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime({ useBinaryProtocol: true }); realtime.connection.on('connected', function () { var channel6 = realtime.channels.get('channelsubscribe0'); - helper.whenPromiseSettles(channel6.attach(), function (err) { + Helper.whenPromiseSettles(channel6.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1128,21 +1130,21 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channelByEvent.unsubscribe('event', listenerByEvent); channelByListener.unsubscribe(listenerNoEvent); channelAll.unsubscribe(); - helper.whenPromiseSettles(channelByEvent.publish('event', 'data'), function (err) { + Helper.whenPromiseSettles(channelByEvent.publish('event', 'data'), function (err) { try { expect(!err, 'Error publishing single event: ' + err).to.be.ok; } catch (err) { helper.closeAndFinish(done, realtime, err); return; } - helper.whenPromiseSettles(channelByListener.publish(null, 'data'), function (err) { + Helper.whenPromiseSettles(channelByListener.publish(null, 'data'), function (err) { try { expect(!err, 'Error publishing any event: ' + err).to.be.ok; } catch (err) { helper.closeAndFinish(done, realtime, err); return; } - helper.whenPromiseSettles(channelAll.publish(null, 'data'), function (err) { + Helper.whenPromiseSettles(channelAll.publish(null, 'data'), function (err) { try { expect(!err, 'Error publishing any event: ' + err).to.be.ok; expect(messagesReceived).to.equal(3, 'Only three messages should be received by the listeners'); @@ -1173,13 +1175,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.on('connected', function () { channelByEvent = realtime.channels.get('channelsubscribe1-event'); - helper.whenPromiseSettles(channelByEvent.subscribe('event', listenerByEvent), function () { + Helper.whenPromiseSettles(channelByEvent.subscribe('event', listenerByEvent), function () { channelByEvent.publish('event', 'data'); channelByListener = realtime.channels.get('channelsubscribe1-listener'); - helper.whenPromiseSettles(channelByListener.subscribe(null, listenerNoEvent), function () { + Helper.whenPromiseSettles(channelByListener.subscribe(null, listenerNoEvent), function () { channelByListener.publish(null, 'data'); channelAll = realtime.channels.get('channelsubscribe1-all'); - helper.whenPromiseSettles(channelAll.subscribe(listenerAllEvents), function () { + Helper.whenPromiseSettles(channelAll.subscribe(listenerAllEvents), function () { channelAll.publish(null, 'data'); }); }); @@ -1210,7 +1212,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { /* Sabotage the reattach attempt, then simulate a server-sent detach */ @@ -1275,7 +1277,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async ); }); }; - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { try { expect(err.code).to.equal(50000, 'check error is propogated to the attach callback'); expect(channel.state).to.equal('suspended', 'check channel goes into suspended'); @@ -1298,7 +1300,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel = realtime.channels.get(channelName); realtime.connection.once('connected', function () { - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1344,7 +1346,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { channel.once(function (stateChange) { @@ -1382,7 +1384,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel = realtime.channels.get('publish_no_queueing'); /* try a publish while not yet connected */ - helper.whenPromiseSettles(channel.publish('foo', 'bar'), function (err) { + Helper.whenPromiseSettles(channel.publish('foo', 'bar'), function (err) { try { expect(err, 'Check publish while disconnected/connecting is rejected').to.be.ok; helper.closeAndFinish(done, realtime); @@ -1419,7 +1421,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { expect(err, 'Channel attach timed out as expected').to.be.ok; expect(err && err.code).to.equal(90007, 'Attach timeout err passed to attach callback'); expect(channel.state).to.equal('suspended', 'Check channel state goes to suspended'); @@ -1467,7 +1469,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { /* Have the connection go into the suspended state, and check that the @@ -1531,7 +1533,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { /* Sabotage the detach attempt, detach, then simulate a server-sent attached while @@ -1566,7 +1568,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channel = realtime.channels.get(channelName); channel.state = 'suspended'; - helper.whenPromiseSettles(channel.detach(), function () { + Helper.whenPromiseSettles(channel.detach(), function () { try { expect(channel.state).to.equal( 'detached', @@ -1588,7 +1590,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel.state = 'failed'; - helper.whenPromiseSettles(channel.detach(), function (err) { + Helper.whenPromiseSettles(channel.detach(), function (err) { if (!err) { helper.closeAndFinish(done, realtime, new Error('expected detach to return error response')); return; @@ -1608,7 +1610,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var subscriber = function (message) { expect(message.data).to.equal('message'); channel.unsubscribe(subscriber); - helper.whenPromiseSettles(channel.detach(), function (err) { + Helper.whenPromiseSettles(channel.detach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1630,7 +1632,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(); var channelName = 'attach_returns_state_chnage'; var channel = realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { + Helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1645,7 +1647,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } // for an already-attached channel, null is returned - helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { + Helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1667,7 +1669,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(); var channelName = 'subscribe_returns_state_chnage'; var channel = realtime.channels.get(channelName); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.subscribe( function () {}, // message listener ), @@ -1697,7 +1699,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channel = realtime.channels.get(channelName, channelOpts); // attach with rewind but no channel history - hasBacklog should be false - helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { + Helper.whenPromiseSettles(channel.attach(), function (err, stateChange) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1723,12 +1725,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var restChannel = rest.channels.get(channelName); // attach with rewind after publishing - hasBacklog should be true - helper.whenPromiseSettles(restChannel.publish('foo', 'bar'), function (err) { + Helper.whenPromiseSettles(restChannel.publish('foo', 'bar'), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; } - helper.whenPromiseSettles(rtChannel.attach(), function (err, stateChange) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err, stateChange) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1750,7 +1752,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async const realtime = helper.AblyRealtime(); const channel = realtime.channels.get('channel-with-options', { modes: ['PRESENCE'] }); channel.attach(); - helper.whenPromiseSettles(channel.whenState('attaching'), function () { + Helper.whenPromiseSettles(channel.whenState('attaching'), function () { try { realtime.channels.get('channel-with-options', { modes: ['PRESENCE'] }); helper.closeAndFinish(done, realtime); diff --git a/test/realtime/connection.test.js b/test/realtime/connection.test.js index 6d240cfbd..23563b14f 100644 --- a/test/realtime/connection.test.js +++ b/test/realtime/connection.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var createPM = Ably.protocolMessageFromDeserialized; @@ -41,7 +43,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async try { realtime = helper.AblyRealtime(); realtime.connection.on('connected', function () { - helper.whenPromiseSettles(realtime.connection.ping(), function (err, responseTime) { + Helper.whenPromiseSettles(realtime.connection.ping(), function (err, responseTime) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -80,7 +82,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } var channel = realtime.channels.get('connectionattributes'); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -98,7 +100,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.publish('name', 'data'), cb); + Helper.whenPromiseSettles(channel.publish('name', 'data'), cb); }, ], function (err) { @@ -107,7 +109,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return; } realtime.connection.close(); - helper.whenPromiseSettles(realtime.connection.whenState('closed'), function () { + Helper.whenPromiseSettles(realtime.connection.whenState('closed'), function () { try { expect(realtime.connection.recoveryKey).to.equal(null, 'verify recovery key null after close'); helper.closeAndFinish(done, realtime); @@ -180,7 +182,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.once('connected', function () { var transport = connectionManager.activeProtocol.transport; - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -209,7 +211,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async transportSendCallback = cb; /* Sabotaged publish */ - helper.whenPromiseSettles(channel.publish('first', null), function (err) { + Helper.whenPromiseSettles(channel.publish('first', null), function (err) { if (!publishCallback) { done(new Error('publish completed before publishCallback populated')); } diff --git a/test/realtime/connectivity.test.js b/test/realtime/connectivity.test.js index c19e3e077..64f905240 100644 --- a/test/realtime/connectivity.test.js +++ b/test/realtime/connectivity.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('realtime/connectivity', function () { @@ -21,7 +23,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { * @nospec */ it('http_connectivity_check', function (done) { - helper.whenPromiseSettles(new Ably.Realtime._Http().checkConnectivity(), function (err, res) { + Helper.whenPromiseSettles(new Ably.Realtime._Http().checkConnectivity(), function (err, res) { try { expect(res && !err, 'Connectivity check completed ' + (err && helper.Utils.inspectError(err))).to.be.ok; } catch (err) { @@ -48,7 +50,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('succeeds with scheme', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options(urlScheme + successUrl)).http.checkConnectivity(), function (err, res) { try { @@ -64,7 +66,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('fails with scheme', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options(urlScheme + failUrl)).http.checkConnectivity(), function (err, res) { try { @@ -79,7 +81,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('succeeds with querystring', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options(successUrl)).http.checkConnectivity(), function (err, res) { try { @@ -94,7 +96,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('fails with querystring', function (done) { - helper.whenPromiseSettles(helper.AblyRealtime(options(failUrl)).http.checkConnectivity(), function (err, res) { + Helper.whenPromiseSettles(helper.AblyRealtime(options(failUrl)).http.checkConnectivity(), function (err, res) { try { expect(!res, 'Connectivity check expected to return false').to.be.ok; done(); @@ -106,7 +108,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('succeeds with plain url', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options('sandbox-rest.ably.io/time')).http.checkConnectivity(), function (err, res) { try { @@ -121,7 +123,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('fails with plain url', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options('echo.ably.io')).http.checkConnectivity(), function (err, res) { try { @@ -137,7 +139,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { /** @nospec */ it('disable_connectivity_check', function (done) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( helper.AblyRealtime(options('notarealhost', true)).http.checkConnectivity(), function (err, res) { try { diff --git a/test/realtime/crypto.test.js b/test/realtime/crypto.test.js index 31b95db74..a8c9f60c4 100644 --- a/test/realtime/crypto.test.js +++ b/test/realtime/crypto.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var BufferUtils = Ably.Realtime.Platform.BufferUtils; var Crypto = Ably.Realtime.Platform.Crypto; @@ -11,7 +13,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.map( channels, function (channel, cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, callback, ); @@ -99,7 +101,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSE2a - tests length in bits with explicit keyLength */ it('generateRandomKey0', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { if (err) { done(err); return; @@ -122,7 +124,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSE2a - tests length in bits without keyLength */ it('generateRandomKey1', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { done(err); return; @@ -142,7 +144,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSE1b - tests only passing key */ it('getDefaultParams_withResultOfGenerateRandomKey', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { done(err); } @@ -160,7 +162,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /** @specpartial RSE1c - can accept binary key */ it('getDefaultParams_ArrayBuffer_key', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { done(err); } @@ -177,7 +179,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /** @specpartial RSE1c - can accept base64 string key */ it('getDefaultParams_base64_key', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { done(err); return; @@ -200,7 +202,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RSE1e */ it('getDefaultParams_check_keylength', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { if (err) { done(err); return; @@ -220,7 +222,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSE1b - tests key, algorithm, mode */ it('getDefaultParams_preserves_custom_algorithms', function (done) { - helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(64), function (err, key) { if (err) { done(err); return; @@ -251,7 +253,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async true, function (channelOpts, testMessage, encryptedMessage) { /* encrypt plaintext message; encode() also to handle data that is not already string or buffer */ - helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { + Helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { /* compare */ testMessageEquality(done, testMessage, encryptedMessage); }); @@ -272,7 +274,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async true, function (channelOpts, testMessage, encryptedMessage) { /* encrypt plaintext message; encode() also to handle data that is not already string or buffer */ - helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { + Helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { /* compare */ testMessageEquality(done, testMessage, encryptedMessage); }); @@ -359,7 +361,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async 2, false, function (channelOpts, testMessage, encryptedMessage, msgpackEncodedMessage) { - helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { + Helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { var msgpackFromEncoded = msgpack.encode(testMessage); var msgpackFromEncrypted = msgpack.encode(encryptedMessage); var messageFromMsgpack = Message.fromValues( @@ -397,7 +399,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async 2, false, function (channelOpts, testMessage, encryptedMessage, msgpackEncodedMessage) { - helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { + Helper.whenPromiseSettles(Message.encode(testMessage, channelOpts), function () { var msgpackFromEncoded = msgpack.encode(testMessage); var msgpackFromEncrypted = msgpack.encode(encryptedMessage); var messageFromMsgpack = Message.fromValues( @@ -430,7 +432,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return; } - helper.whenPromiseSettles(Crypto.generateRandomKey(keyLength), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(keyLength), function (err, key) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -442,7 +444,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel = realtime.channels.get('single_send', { cipher: { key: key } }), messageText = 'Test message for single_send - ' + JSON.stringify(realtimeOpts); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -469,14 +471,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async // Publish and subscribe, various transport, 128 and 256-bit /** @specpartial RSL5b - test aes 128 */ - helper.testOnAllTransports('single_send_128', function (realtimeOpts) { + Helper.testOnAllTransports('single_send_128', function (realtimeOpts) { return function (done) { single_send(done, realtimeOpts, 128); }; }); /** @specpartial RSL5b - test aes 256 */ - helper.testOnAllTransports('single_send_256', function (realtimeOpts) { + Helper.testOnAllTransports('single_send_256', function (realtimeOpts) { return function (done) { single_send(done, realtimeOpts, 256); }; @@ -493,7 +495,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel = realtime.channels.get(channelName), messageText = 'Test message (' + channelName + ')'; - helper.whenPromiseSettles(Crypto.generateRandomKey(128), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(128), function (err, key) { channel.setOptions({ cipher: { key: key } }); try { expect(channel.channelOptions.cipher.algorithm).to.equal('aes'); @@ -526,7 +528,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); } - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -605,7 +607,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async txChannel = txRealtime.channels.get(channelName), rxChannel = rxRealtime.channels.get(channelName); - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -690,13 +692,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channelName = 'publish_immediately', messageText = 'Test message'; - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; } var rxChannel = rxRealtime.channels.get(channelName, { cipher: { key: key } }); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( rxChannel.subscribe('event0', function (msg) { try { expect(msg.data == messageText).to.be.ok; @@ -739,10 +741,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (cb) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), cb); + Helper.whenPromiseSettles(Crypto.generateRandomKey(), cb); }, function (cb) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), cb); + Helper.whenPromiseSettles(Crypto.generateRandomKey(), cb); }, function (cb) { attachChannels([txChannel, rxChannel], cb); @@ -810,7 +812,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; } - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, rxKey) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, rxKey) { if (err) { helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; @@ -856,7 +858,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; } - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, txKey) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, txKey) { if (err) { helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; @@ -905,7 +907,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async attachChannels([txChannel, rxChannel], cb); }; var setInitialOptions = function (cb) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; @@ -938,7 +940,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; var createSecondKey = function (cb) { - helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { + Helper.whenPromiseSettles(Crypto.generateRandomKey(), function (err, key) { if (err) { helper.closeAndFinish(done, [txRealtime, rxRealtime], err); return; diff --git a/test/realtime/delta.test.js b/test/realtime/delta.test.js index cf0148772..cd8d41c4c 100644 --- a/test/realtime/delta.test.js +++ b/test/realtime/delta.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, vcdiffDecoder, async, chai) { +define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (Helper, vcdiffDecoder, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var testData = [ { foo: 'bar', count: 1, status: 'active' }, @@ -48,7 +50,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); var channel = realtime.channels.get(testName, { params: { delta: 'vcdiff' } }); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -77,7 +79,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); async.timesSeries(testData.length, function (i, cb) { - helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); + Helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); }); }); @@ -103,7 +105,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); var channel = realtime.channels.get(testName); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -122,7 +124,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); async.timesSeries(testData.length, function (i, cb) { - helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); + Helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); }); }); @@ -148,7 +150,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); var channel = realtime.channels.get(testName, { params: { delta: 'vcdiff' } }); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -191,7 +193,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); async.timesSeries(testData.length, function (i, cb) { - helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); + Helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); }); }); @@ -221,7 +223,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); var channel = realtime.channels.get(testName, { params: { delta: 'vcdiff' } }); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -246,7 +248,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v }); async.timesSeries(testData.length, function (i, cb) { - helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); + Helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); }); }); @@ -267,7 +269,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v var realtime = helper.AblyRealtime(); var channel = realtime.channels.get('noPlugin', { params: { delta: 'vcdiff' } }); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } @@ -281,7 +283,7 @@ define(['shared_helper', 'vcdiff-decoder', 'async', 'chai'], function (helper, v helper.closeAndFinish(done, realtime); }); async.timesSeries(testData.length, function (i, cb) { - helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); + Helper.whenPromiseSettles(channel.publish(i.toString(), testData[i]), cb); }); }); diff --git a/test/realtime/encoding.test.js b/test/realtime/encoding.test.js index b6a35c6cc..30b8841b9 100644 --- a/test/realtime/encoding.test.js +++ b/test/realtime/encoding.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var BufferUtils = Ably.Realtime.Platform.BufferUtils; var Defaults = Ably.Rest.Platform.Defaults; @@ -44,10 +46,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (attachCb) { - helper.whenPromiseSettles(channel.attach(), attachCb); + Helper.whenPromiseSettles(channel.attach(), attachCb); }, function (attachCb) { - helper.whenPromiseSettles(binarychannel.attach(), attachCb); + Helper.whenPromiseSettles(binarychannel.attach(), attachCb); }, ], function (err) { @@ -99,7 +101,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (parallelCb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( realtime.request( 'post', channelPath, @@ -148,10 +150,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (attachCb) { - helper.whenPromiseSettles(channel.attach(), attachCb); + Helper.whenPromiseSettles(channel.attach(), attachCb); }, function (attachCb) { - helper.whenPromiseSettles(binarychannel.attach(), attachCb); + Helper.whenPromiseSettles(binarychannel.attach(), attachCb); }, ], function (err) { @@ -173,10 +175,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (parallelCb) { - helper.whenPromiseSettles(channel.publish(name, data), parallelCb); + Helper.whenPromiseSettles(channel.publish(name, data), parallelCb); }, function (parallelCb) { - helper.whenPromiseSettles(binarychannel.publish(name, data), parallelCb); + Helper.whenPromiseSettles(binarychannel.publish(name, data), parallelCb); }, ], function (err) { @@ -184,7 +186,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async eachOfCb(err); return; } - helper.whenPromiseSettles( + Helper.whenPromiseSettles( realtime.request('get', channelPath, 3, null, null, null), function (err, resultPage) { if (err) { diff --git a/test/realtime/event_emitter.test.js b/test/realtime/event_emitter.test.js index 1743960b9..a0ec885c8 100644 --- a/test/realtime/event_emitter.test.js +++ b/test/realtime/event_emitter.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('realtime/event_emitter', function () { diff --git a/test/realtime/failure.test.js b/test/realtime/failure.test.js index 76e07fb45..dcc3c6d6b 100644 --- a/test/realtime/failure.test.js +++ b/test/realtime/failure.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var noop = function () {}; var createPM = Ably.protocolMessageFromDeserialized; @@ -257,7 +259,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var tests = [ function (callback) { - helper.whenPromiseSettles(failChan.publish('event', 'data'), function (err) { + Helper.whenPromiseSettles(failChan.publish('event', 'data'), function (err) { try { expect(err, 'publish failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'publish failure code'); @@ -268,7 +270,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.subscribe('event', noop), function (err) { + Helper.whenPromiseSettles(failChan.subscribe('event', noop), function (err) { try { expect(err, 'subscribe failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'subscribe failure code'); @@ -279,7 +281,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.presence.enterClient('clientId'), function (err) { + Helper.whenPromiseSettles(failChan.presence.enterClient('clientId'), function (err) { try { expect(err, 'presence enter failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'presence enter failure code'); @@ -290,7 +292,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.presence.leaveClient('clientId'), function (err) { + Helper.whenPromiseSettles(failChan.presence.leaveClient('clientId'), function (err) { try { expect(err, 'presence leave failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'presence leave failure code'); @@ -301,7 +303,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.presence.subscribe('event', noop), function (err) { + Helper.whenPromiseSettles(failChan.presence.subscribe('event', noop), function (err) { try { expect(err, 'presence subscribe failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'subscribe failure code'); @@ -312,7 +314,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.presence.subscribe('event', noop), function (err) { + Helper.whenPromiseSettles(failChan.presence.subscribe('event', noop), function (err) { try { expect(err, 'presence unsubscribe failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'subscribe failure code'); @@ -323,7 +325,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (callback) { - helper.whenPromiseSettles(failChan.presence.get(), function (err) { + Helper.whenPromiseSettles(failChan.presence.get(), function (err) { try { expect(err, 'presence get failed').to.be.ok; expect(err.code).to.equal(channelFailedCode, 'presence get failure code'); @@ -338,7 +340,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async try { realtime.connection.once('connected', function () { failChan = realtime.channels.get('::'); - helper.whenPromiseSettles(failChan.attach(), function (err) { + Helper.whenPromiseSettles(failChan.attach(), function (err) { try { expect(err, 'channel attach failed').to.be.ok; expect(failChan.state).to.equal('failed', 'channel in failed state'); @@ -373,7 +375,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; realtime.connection.once('connected', function () { - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { try { expect(err.code).to.equal(90007, 'check channel error code'); expect(err.statusCode).to.equal(408, 'check timeout statusCode'); @@ -426,7 +428,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.on('connected', function () { realtime.options.timeouts.realtimeRequestTimeout = 1; - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { var lastSuspended = performance.now(); channel.on(function (stateChange) { @@ -482,7 +484,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { var transport = realtime.connection.connectionManager.activeProtocol.transport, @@ -494,7 +496,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async originalOnProtocolMessage.apply(this, arguments); } }; - helper.whenPromiseSettles(channel.publish('foo', 'bar'), function (err) { + Helper.whenPromiseSettles(channel.publish('foo', 'bar'), function (err) { try { expect(err, 'Publish failed as expected').to.be.ok; expect(realtime.connection.state).to.equal( @@ -593,7 +595,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); /** @specpartial RTN14d - last sentence: check that if we received a 5xx disconnected, when we try again we use a fallback host */ - testOnAllTransports('try_fallback_hosts_on_placement_constraint', function (realtimeOpts) { + Helper.testOnAllTransports('try_fallback_hosts_on_placement_constraint', function (realtimeOpts) { return function (done) { /* Use the echoserver as a fallback host because it doesn't support * websockets, so it'll fail to connect, which we can detect */ diff --git a/test/realtime/history.test.js b/test/realtime/history.test.js index 67dfc6315..bb47ba48c 100644 --- a/test/realtime/history.test.js +++ b/test/realtime/history.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { +define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var indexes = [1, 2, 3, 4, 5]; var preAttachMessages = indexes.map(function (i) { @@ -13,7 +15,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { var parallelPublishMessages = function (done, channel, messages, callback) { var publishTasks = messages.map(function (event) { return function (publishCb) { - helper.whenPromiseSettles(channel.publish(event.name, event.data), publishCb); + Helper.whenPromiseSettles(channel.publish(event.name, event.data), publishCb); }; }); @@ -57,9 +59,9 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { parallelPublishMessages(done, restChannel, preAttachMessages, function () { /* second, connect and attach to the channel */ try { - helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { + Helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { var rtChannel = realtime.channels.get('persisted:history_until_attach'); - helper.whenPromiseSettles(rtChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -75,7 +77,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { var tests = [ function (callback) { - helper.whenPromiseSettles(rtChannel.history(), function (err, resultPage) { + Helper.whenPromiseSettles(rtChannel.history(), function (err, resultPage) { if (err) { callback(err); } @@ -92,7 +94,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); }, function (callback) { - helper.whenPromiseSettles(rtChannel.history({ untilAttach: false }), function (err, resultPage) { + Helper.whenPromiseSettles(rtChannel.history({ untilAttach: false }), function (err, resultPage) { if (err) { callback(err); } @@ -109,7 +111,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); }, function (callback) { - helper.whenPromiseSettles(rtChannel.history({ untilAttach: true }), function (err, resultPage) { + Helper.whenPromiseSettles(rtChannel.history({ untilAttach: true }), function (err, resultPage) { if (err) { callback(err); } diff --git a/test/realtime/init.test.js b/test/realtime/init.test.js index 7e8ed7705..dcdd30b10 100644 --- a/test/realtime/init.test.js +++ b/test/realtime/init.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('realtime/init', function () { @@ -82,7 +84,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { var rest = helper.AblyRest(); var testKeyOpts = { key: helper.getTestApp().keys[1].keyStr }; - helper.whenPromiseSettles(rest.auth.requestToken(null, testKeyOpts), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(null, testKeyOpts), function (err, tokenDetails) { if (err) { done(err); return; diff --git a/test/realtime/message.test.js b/test/realtime/message.test.js index 490610166..c145c1f85 100644 --- a/test/realtime/message.test.js +++ b/test/realtime/message.test.js @@ -1,13 +1,15 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; let config = Ably.Realtime.Platform.Config; var createPM = Ably.protocolMessageFromDeserialized; var publishIntervalHelper = function (currentMessageNum, channel, dataFn, onPublish) { return function () { - helper.whenPromiseSettles(channel.publish('event0', dataFn()), function () { + Helper.whenPromiseSettles(channel.publish('event0', dataFn()), function () { onPublish(); }); }; @@ -44,7 +46,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.on('connected', function () { var testMsg = 'Hello world'; var rtChannel = realtime.channels.get('publishonce'); - helper.whenPromiseSettles(rtChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -76,13 +78,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Test publishes in quick succession (on successive ticks of the event loop) * @spec RTL6b */ - helper.testOnAllTransports('publishfast', function (realtimeOpts) { + Helper.testOnAllTransports('publishfast', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); realtime.connection.once('connected', function () { var channel = realtime.channels.get('publishfast_' + String(Math.random()).substr(2)); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -100,7 +102,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async function (cb) { var ackd = 0; var publish = function (i) { - helper.whenPromiseSettles(channel.publish('event', i.toString()), function (err) { + Helper.whenPromiseSettles(channel.publish('event', i.toString()), function (err) { try { expect( !err, @@ -142,7 +144,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL6c2 * @specpartial RTL3d - test processing queued messages */ - helper.testOnAllTransports('publishQueued', function (realtimeOpts) { + Helper.testOnAllTransports('publishQueued', function (realtimeOpts) { return function (done) { var txRealtime, rxRealtime; try { @@ -159,7 +161,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(rxChannel.attach(), function (err) { + Helper.whenPromiseSettles(rxChannel.attach(), function (err) { cb(err); }); }, @@ -183,7 +185,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async function (parCb) { var ackd = 0; var publish = function (i) { - helper.whenPromiseSettles(txChannel.publish('event', { num: i }), function (err) { + Helper.whenPromiseSettles(txChannel.publish('event', { num: i }), function (err) { try { expect( !err, @@ -265,7 +267,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; // attach rtNoEchoChannel - helper.whenPromiseSettles(rtNoEchoChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtNoEchoChannel.attach(), function (err) { try { expect(!err, 'Attached to rtNoEchoChannel with no error').to.be.ok; } catch (err) { @@ -281,7 +283,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); // attach rtEchoChannel - helper.whenPromiseSettles(rtEchoChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtEchoChannel.attach(), function (err) { try { expect(!err, 'Attached to rtEchoChannel with no error').to.be.ok; } catch (err) { @@ -297,7 +299,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); // publish testMsg1 via rtNoEcho - helper.whenPromiseSettles(rtNoEchoChannel.publish('event0', testMsg1), function () { + Helper.whenPromiseSettles(rtNoEchoChannel.publish('event0', testMsg1), function () { // publish testMsg2 via rtEcho rtEchoChannel.publish('event0', testMsg2); }); @@ -341,7 +343,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* connect and attach */ realtime.connection.on('connected', function () { var rtChannel = realtime.channels.get('publishVariations'); - helper.whenPromiseSettles(rtChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -411,7 +413,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.eachSeries( testArguments, function iterator(args, callback) { - helper.whenPromiseSettles(restChannel.publish.apply(restChannel, args), callback); + Helper.whenPromiseSettles(restChannel.publish.apply(restChannel, args), callback); }, function (err) { if (err) { @@ -447,7 +449,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* connect and attach */ realtime.connection.on('connected', function () { var rtChannel = realtime.channels.get('publishDisallowed'); - helper.whenPromiseSettles(rtChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -507,7 +509,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* connect and attach */ realtime.connection.on('connected', function () { var rtChannel = realtime.channels.get('publishEncodings'); - helper.whenPromiseSettles(rtChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -554,7 +556,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async testArguments, function iterator(item, callback) { try { - helper.whenPromiseSettles(restChannel.publish(item), function (err) { + Helper.whenPromiseSettles(restChannel.publish(item), function (err) { try { expect(!err, 'Successfully published').to.be.ok; } catch (err) { @@ -617,7 +619,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec RTL6 * @spec RTL6b */ - helper.testOnAllTransports('publish', function (realtimeOpts) { + Helper.testOnAllTransports('publish', function (realtimeOpts) { return function (done) { var count = 10; var cbCount = 10; @@ -633,7 +635,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(realtimeOpts); var channel = realtime.channels.get('publish ' + JSON.stringify(realtimeOpts)); /* subscribe to event */ - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.subscribe('event0', function () { --count; checkFinish(); @@ -719,7 +721,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channel = realtime.channels.get('explicit_client_id_0'); /* subscribe to event */ - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { try { expect(!err, err && helper.displayError(err)).to.be.ok; @@ -743,7 +745,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.publish({ name: 'event0', clientId: clientId }), function (err) { + Helper.whenPromiseSettles(channel.publish({ name: 'event0', clientId: clientId }), function (err) { cb(err); }); }, @@ -767,7 +769,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async invalidClientId = 'invalid', rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: clientId }), function (err, token) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: clientId }), function (err, token) { if (err) { done(err); return; @@ -784,7 +786,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel = realtime.channels.get('explicit_client_id_1'); // Publish before authentication to ensure the client library does not reject the message as the clientId is not known - helper.whenPromiseSettles(channel.publish({ name: 'event0', clientId: invalidClientId }), function (err) { + Helper.whenPromiseSettles(channel.publish({ name: 'event0', clientId: invalidClientId }), function (err) { try { expect(err, 'Message was not published').to.be.ok; } catch (err) { @@ -835,7 +837,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { cb(err); }); }, @@ -861,7 +863,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (innercb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.publish([{ name: 'a' }, { name: 'b' }, { name: 'c' }, { name: 'd' }]), function (err) { innercb(err); @@ -894,7 +896,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async const channel = realtime.channels.get('subscribe_with_filter_object'); function send(cb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.publish([ { name: 'correct', @@ -957,7 +959,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - return helper.whenPromiseSettles(channel.attach(), cb); + return Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { return async.parallel([subscribe, send], cb); @@ -984,7 +986,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async const channel = realtime.channels.get('unsubscribe_with_filter_object'); function send(cb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.publish([ { name: 'incorrect', @@ -1026,7 +1028,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - return helper.whenPromiseSettles(channel.attach(), cb); + return Helper.whenPromiseSettles(channel.attach(), cb); }, unsubscribe, send, @@ -1051,7 +1053,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (outercb) { async.parallel( @@ -1069,7 +1071,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (innercb) { - helper.whenPromiseSettles(channel.publish([{ name: 'a', extras: extras }]), innercb); + Helper.whenPromiseSettles(channel.publish([{ name: 'a', extras: extras }]), innercb); }, ], outercb, @@ -1094,7 +1096,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime.connection.once('connected', function () { connectionManager.once('connectiondetails', function (details) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( channel.publish('foo', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), function (err) { try { @@ -1201,7 +1203,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var realtime = helper.AblyRealtime(), channel = realtime.channels.get('idempotentRealtimePublishing'); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1303,7 +1305,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var filteredMessages = []; var unFilteredMessages = []; /* subscribe to event */ - helper.whenPromiseSettles(rtFilteredChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtFilteredChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -1318,7 +1320,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } }); - helper.whenPromiseSettles(rtUnfilteredChannel.attach(), function (err) { + Helper.whenPromiseSettles(rtUnfilteredChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); return; diff --git a/test/realtime/presence.test.js b/test/realtime/presence.test.js index a8e72abcc..88a3f9c48 100644 --- a/test/realtime/presence.test.js +++ b/test/realtime/presence.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var createPM = Ably.protocolMessageFromDeserialized; var PresenceMessage = Ably.Realtime.PresenceMessage; @@ -29,7 +31,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async realtime = helper.AblyRealtime(); realtime.connection.on('connected', function () { channel = realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { callback(err, realtime, channel); }); }); @@ -99,7 +101,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async // Create authTokens associated with specific clientIds try { rest = helper.AblyRest(); - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -112,7 +114,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async return; } - helper.whenPromiseSettles( + Helper.whenPromiseSettles( rest.auth.requestToken({ clientId: testClientId2 }), function (err, tokenDetails) { if (err) { @@ -150,12 +152,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (enter0)'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (enter0)'), function (err) { cb(err, clientRealtime); }); }); @@ -179,7 +181,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( clientChannel.presence.enter('Test client data (enterWithoutAttach)'), function (err) { cb(err, clientRealtime); @@ -202,7 +204,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var enterWithoutConnect = function (cb) { var clientRealtime = helper.AblyRealtime({ clientId: testClientId, tokenDetails: authToken }); var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles( + Helper.whenPromiseSettles( clientChannel.presence.enter('Test client data (enterWithoutConnect)'), function (err) { cb(err, clientRealtime); @@ -249,19 +251,19 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, [listenerRealtime, clientRealtime], err); return; } - helper.whenPromiseSettles(clientChannel.detach(), function (err) { + Helper.whenPromiseSettles(clientChannel.detach(), function (err) { if (err) { helper.closeAndFinish(done, [listenerRealtime, clientRealtime], err); return; } }); }); - helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (enter3)'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (enter3)'), function (err) { // Note: either an error (pending messages failed to send due to detach) // or a success (pending messages were pushed out before the detach) // is an acceptable result. Throwing an uncaught exception (the behaviour @@ -295,12 +297,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter(), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter(), function (err) { cb(err, clientRealtime); }); }); @@ -322,7 +324,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; @@ -349,7 +351,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; @@ -375,7 +377,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelName = 'presenceMessageAction'; var clientChannel = clientRealtime.channels.get(channelName); var presence = clientChannel.presence; - helper.whenPromiseSettles( + Helper.whenPromiseSettles( presence.subscribe(function (presenceMessage) { try { expect(presenceMessage.action).to.equal('enter', 'Action should contain string "enter"'); @@ -412,7 +414,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(clientChannel.attach(), cb); + Helper.whenPromiseSettles(clientChannel.attach(), cb); }, // Test entering with extras function (cb) { @@ -494,17 +496,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); // NB remove besttransport in 1.1 spec, see attachdetach0 var clientChannel = clientRealtime.channels.get(channelName); clientRealtime.connection.once('connected', function () { - helper.whenPromiseSettles(clientChannel.presence.enter('first'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('first'), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.detach(), function (err) { + Helper.whenPromiseSettles(clientChannel.detach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter('second'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('second'), function (err) { cb(err, clientRealtime); }); }); @@ -528,7 +530,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime = helper.AblyRealtime({ clientId: testClientId, tokenDetails: authToken }); var clientChannel = clientRealtime.channels.get(''); clientRealtime.connection.once('connected', function () { - helper.whenPromiseSettles(clientChannel.presence.enter('clientId'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('clientId'), function (err) { if (err) { try { expect(err.code).to.equal(40010, 'Correct error code'); @@ -560,18 +562,18 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (leave0)'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (leave0)'), function (err) { if (err) { cb(err, clientRealtime); return; } }); - helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { cb(err, clientRealtime); }); }); @@ -611,17 +613,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var clientRealtime = helper.AblyRealtime({ clientId: testClientId, tokenDetails: authToken }); clientRealtime.connection.on('connected', function () { var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter('Original data'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('Original data'), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.update(newData), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.update(newData), function (err) { cb(err, clientRealtime); }); }); @@ -643,7 +645,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var eventListener = function (channel, callback) { var presenceHandler = function () { /* Should be ENTER, but may be PRESENT in a race */ - helper.whenPromiseSettles(channel.presence.get(), function (err, presenceMembers) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, presenceMembers) { if (err) { callback(err); return; @@ -666,12 +668,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter(testData), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter(testData), function (err) { cb(err, clientRealtime); }); }); @@ -724,7 +726,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.presence.enter(testData), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter(testData), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; @@ -733,7 +735,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime2.connection.on('connected', function () { var clientChannel2 = clientRealtime2.channels.get(channelName); /* GET without attaching */ - helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, presenceMembers) { + Helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, presenceMembers) { if (err) { helper.closeAndFinish(done, [clientRealtime, clientRealtime2], err); return; @@ -767,7 +769,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var presenceHandler = function () { // Ignore the first (enter) event if (this.event == 'leave') { - helper.whenPromiseSettles(channel.presence.get(), function (err, presenceMembers) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, presenceMembers) { if (err) { callback(err); return; @@ -790,17 +792,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.enter('testClientData'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('testClientData'), function (err) { if (err) { cb(err, clientRealtime); return; } - helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { cb(err, clientRealtime); }); }); @@ -822,7 +824,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelName = 'history'; var testClientData = 'Test client data (history0)'; var queryPresenceHistory = function (channel) { - helper.whenPromiseSettles(channel.presence.history(), function (err, resultPage) { + Helper.whenPromiseSettles(channel.presence.history(), function (err, resultPage) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; @@ -849,22 +851,22 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel = clientRealtime.channels.get(channelName); - helper.whenPromiseSettles(clientChannel.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel.attach(), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; } - helper.whenPromiseSettles(clientChannel.presence.enter(testClientData), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter(testClientData), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; } - helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; } - helper.whenPromiseSettles(clientChannel.detach(), function (err) { + Helper.whenPromiseSettles(clientChannel.detach(), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime, err); return; @@ -901,19 +903,19 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime1.connection.on('connected', function () { /* get channel, attach, and enter */ var clientChannel1 = clientRealtime1.channels.get(channelName); - helper.whenPromiseSettles(clientChannel1.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel1.attach(), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime1, err); return; } - helper.whenPromiseSettles(clientChannel1.presence.enter('Test client data (attach0)'), function (err) { + Helper.whenPromiseSettles(clientChannel1.presence.enter('Test client data (attach0)'), function (err) { if (err) { helper.closeAndFinish(done, clientRealtime1, err); return; } }); clientChannel1.presence.subscribe('enter', function () { - helper.whenPromiseSettles(clientChannel1.presence.get(), function (err, presenceMembers1) { + Helper.whenPromiseSettles(clientChannel1.presence.get(), function (err, presenceMembers1) { if (err) { helper.closeAndFinish(done, clientRealtime1, err); return; @@ -930,14 +932,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime2.connection.on('connected', function () { /* get channel, attach */ var clientChannel2 = clientRealtime2.channels.get(channelName); - helper.whenPromiseSettles(clientChannel2.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel2.attach(), function (err) { if (err) { helper.closeAndFinish(done, [clientRealtime1, clientRealtime2], err); return; } clientChannel2.presence.subscribe('present', function () { /* get the channel members and verify testclient is there */ - helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, presenceMembers2) { + Helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, presenceMembers2) { if (err) { helper.closeAndFinish(done, [clientRealtime1, clientRealtime2], err); return; @@ -988,12 +990,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime1.connection.on('connected', function () { /* get channel, attach, and enter */ clientChannel1 = clientRealtime1.channels.get(channelName); - helper.whenPromiseSettles(clientChannel1.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel1.attach(), function (err) { if (err) { cb1(err); return; } - helper.whenPromiseSettles(clientChannel1.presence.enter(data), function (err) { + Helper.whenPromiseSettles(clientChannel1.presence.enter(data), function (err) { if (err) { cb1(err); return; @@ -1010,13 +1012,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async clientRealtime2.connection.on('connected', function () { /* get channel, attach */ clientChannel2 = clientRealtime2.channels.get(channelName); - helper.whenPromiseSettles(clientChannel2.attach(), function (err) { + Helper.whenPromiseSettles(clientChannel2.attach(), function (err) { if (err) { cb2(err); return; } var enterPresence = function (onEnterCB) { - helper.whenPromiseSettles(clientChannel2.presence.enter(data), function (err) { + Helper.whenPromiseSettles(clientChannel2.presence.enter(data), function (err) { if (err) { cb2(err); return; @@ -1060,7 +1062,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async [ /* First test: no filters */ function (cb) { - helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, members) { + Helper.whenPromiseSettles(clientChannel2.presence.get(), function (err, members) { if (err) { return cb(err); } @@ -1079,7 +1081,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }, /* Second test: filter by clientId */ function (cb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( clientChannel2.presence.get({ clientId: testClientId }), function (err, members) { if (err) { @@ -1098,7 +1100,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }, /* Third test: filter by connectionId */ function (cb) { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( clientChannel2.presence.get({ connectionId: clientRealtime1.connection.id }), function (err, members) { if (err) { @@ -1160,16 +1162,16 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var clientChannel = clientRealtime.channels.get(channelName); clientRealtime.connection.once('connected', function () { /* get channel and enter (should automatically attach) */ - helper.whenPromiseSettles(clientChannel.presence.enter('first'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('first'), function (err) { if (err) { cb(err, clientRealtime); return; } clientRealtime.close(); - helper.whenPromiseSettles(clientRealtime.connection.whenState('closed'), function () { + Helper.whenPromiseSettles(clientRealtime.connection.whenState('closed'), function () { clientRealtime.connection.once('connected', function () { //Should automatically reattach - helper.whenPromiseSettles(clientChannel.presence.enter('second'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enter('second'), function (err) { cb(err, clientRealtime); }); }); @@ -1195,7 +1197,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var clientChannel = clientRealtime.channels.get(channelName); clientRealtime.connection.on('connected', function () { clientRealtime.close(); - helper.whenPromiseSettles(clientChannel.presence.enterClient('clientId'), function (err) { + Helper.whenPromiseSettles(clientChannel.presence.enterClient('clientId'), function (err) { try { expect(err.code).to.equal(80017, 'presence enter failed with correct code'); expect(err.statusCode).to.equal(400, 'presence enter failed with correct statusCode'); @@ -1237,17 +1239,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async originalSendPresence.apply(channel, arguments); }; - helper.whenPromiseSettles(presence.enter(null), function (err) { + Helper.whenPromiseSettles(presence.enter(null), function (err) { if (err) { helper.closeAndFinish(done, client, err); return; } - helper.whenPromiseSettles(presence.update(null), function (err) { + Helper.whenPromiseSettles(presence.update(null), function (err) { if (err) { helper.closeAndFinish(done, client, err); return; } - helper.whenPromiseSettles(presence.leave(null), function (err) { + Helper.whenPromiseSettles(presence.leave(null), function (err) { if (err) { helper.closeAndFinish(done, client, err); return; @@ -1334,7 +1336,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelName = 'enter_inherited_clientid'; var authCallback = function (tokenParams, callback) { - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -1353,7 +1355,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async cb(err); return; } - helper.whenPromiseSettles(channel.presence.enter('test data'), function (err) { + Helper.whenPromiseSettles(channel.presence.enter('test data'), function (err) { cb(err, realtime); }); }); @@ -1375,7 +1377,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var channelName = 'enter_before_know_clientid'; var enterInheritedClientId = function (cb) { - helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken({ clientId: testClientId }), function (err, tokenDetails) { if (err) { done(err); return; @@ -1388,7 +1390,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async helper.closeAndFinish(done, realtime, err); return; } - helper.whenPromiseSettles(channel.presence.enter('test data'), function (err) { + Helper.whenPromiseSettles(channel.presence.enter('test data'), function (err) { try { expect(realtime.auth.clientId).to.equal(testClientId, 'clientId has been set by the time we entered'); } catch (err) { @@ -1438,10 +1440,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (enterCb) { - helper.whenPromiseSettles(realtimeChannel.presence.enterClient('one'), enterCb); + Helper.whenPromiseSettles(realtimeChannel.presence.enterClient('one'), enterCb); }, function (enterCb) { - helper.whenPromiseSettles(realtimeChannel.presence.enterClient('two'), enterCb); + Helper.whenPromiseSettles(realtimeChannel.presence.enterClient('two'), enterCb); }, ], cb, @@ -1449,7 +1451,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } function checkPresence(first, second, cb) { - helper.whenPromiseSettles(observerChannel.presence.get(), function (err, presenceMembers) { + Helper.whenPromiseSettles(observerChannel.presence.get(), function (err, presenceMembers) { var clientIds = presenceMembers .map(function (msg) { return msg.clientId; @@ -1471,10 +1473,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel( [ function (innerCb) { - helper.whenPromiseSettles(realtimeChannel.presence.leaveClient('two'), innerCb); + Helper.whenPromiseSettles(realtimeChannel.presence.leaveClient('two'), innerCb); }, function (innerCb) { - helper.whenPromiseSettles(realtimeChannel.presence.enterClient('three'), innerCb); + Helper.whenPromiseSettles(realtimeChannel.presence.enterClient('three'), innerCb); }, ], cb, @@ -1501,17 +1503,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async [ waitForBothConnect, function (cb) { - helper.whenPromiseSettles(realtimeChannel.attach(), cb); + Helper.whenPromiseSettles(realtimeChannel.attach(), cb); }, enterOneAndTwo, function (cb) { - helper.whenPromiseSettles(observerChannel.attach(), cb); + Helper.whenPromiseSettles(observerChannel.attach(), cb); }, function (cb) { checkPresence('one', 'two', cb); }, function (cb) { - helper.whenPromiseSettles(observerChannel.detach(), cb); + Helper.whenPromiseSettles(observerChannel.detach(), cb); }, swapTwoForThree, attachAndListen, @@ -1553,13 +1555,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async [ waitForBothConnect, function (cb) { - helper.whenPromiseSettles(entererChannel.presence.enter(), cb); + Helper.whenPromiseSettles(entererChannel.presence.enter(), cb); }, function (cb) { - helper.whenPromiseSettles(detacherChannel.attach(), cb); + Helper.whenPromiseSettles(detacherChannel.attach(), cb); }, function (cb) { - helper.whenPromiseSettles(detacherChannel.detach(), cb); + Helper.whenPromiseSettles(detacherChannel.detach(), cb); }, function (cb) { try { @@ -1601,7 +1603,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { if (!channel.presence.syncComplete) { @@ -1670,7 +1672,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { if (err) { cb(err); return; @@ -1713,7 +1715,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* Request a token without the capabilities to be in the presence set */ var tokenParams = { clientId: 'me', capability: {} }; tokenParams.capability[channelName] = ['publish', 'subscribe']; - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams), function (err, tokenDetails) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams), function (err, tokenDetails) { token = tokenDetails; cb(err); }); @@ -1726,7 +1728,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { if (!channel.presence.syncComplete) { @@ -1736,7 +1738,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, members) { try { expect(members.length).to.equal(0, 'Check no-one in presence set'); } catch (err) { @@ -1778,7 +1780,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, members) { try { expect(members.length).to.equal(0, 'Check no-one in presence set'); } catch (err) { @@ -1833,7 +1835,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { try { expect(results.length).to.equal(10, 'Check all ten clients are there'); } catch (err) { @@ -1870,26 +1872,26 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(continuousRealtime.connection.whenState('connected'), function () { + Helper.whenPromiseSettles(continuousRealtime.connection.whenState('connected'), function () { cb(); }); }, function (cb) { - helper.whenPromiseSettles(continuousChannel.attach(), cb); + Helper.whenPromiseSettles(continuousChannel.attach(), cb); }, function (cb) { - helper.whenPromiseSettles(continuousChannel.presence.enter(), cb); + Helper.whenPromiseSettles(continuousChannel.presence.enter(), cb); }, function (cb) { - helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { + Helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { cb(); }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get({ waitForSync: true }), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get({ waitForSync: true }), function (err, members) { try { expect(members && members.length).to.equal(1, 'Check one member present'); } catch (err) { @@ -1922,7 +1924,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, members) { try { expect(members && members.length).to.equal(2, 'Check two members present'); } catch (err) { @@ -1947,7 +1949,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async channel.sync(); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get({ waitForSync: true }), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get({ waitForSync: true }), function (err, members) { try { expect(members && members.length).to.equal(1, 'Check back to one member present'); expect(members && members[0] && members[0].clientId).to.equal( @@ -1984,12 +1986,12 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { + Helper.whenPromiseSettles(realtime.connection.whenState('connected'), function () { cb(); }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { /* Inject a member locally */ @@ -2014,7 +2016,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, members) { try { expect(members && members.length).to.equal(1, 'Check one member present'); } catch (err) { @@ -2045,7 +2047,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async ); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, members) { try { expect(members && members.length).to.equal(0, 'Check no members present'); } catch (err) { @@ -2085,15 +2087,15 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.series( [ function (cb) { - helper.whenPromiseSettles(rt.connection.whenState('connected'), function () { + Helper.whenPromiseSettles(rt.connection.whenState('connected'), function () { cb(); }); }, function (cb) { - helper.whenPromiseSettles(channel.attach(), cb); + Helper.whenPromiseSettles(channel.attach(), cb); }, function (cb) { - helper.whenPromiseSettles(channel.presence.enter(), cb); + Helper.whenPromiseSettles(channel.presence.enter(), cb); }, ], outerCb, @@ -2122,7 +2124,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.parallel([waitFor('leaves'), enter(leavesRealtime)], cb); }, function (cb) { - helper.whenPromiseSettles(mainChannel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(mainChannel.presence.get(), function (err, members) { try { expect(members.length).to.equal(3, 'Check all three expected members here'); } catch (err) { @@ -2136,7 +2138,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async helper.becomeSuspended(mainRealtime, cb); }, function (cb) { - helper.whenPromiseSettles(mainChannel.presence.get(), function (err) { + Helper.whenPromiseSettles(mainChannel.presence.get(), function (err) { /* Check RTP11d: get() returns an error by default */ try { expect(err, 'Check error returned by get() while suspended').to.be.ok; @@ -2149,7 +2151,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(mainChannel.presence.get({ waitForSync: false }), function (err, members) { + Helper.whenPromiseSettles(mainChannel.presence.get({ waitForSync: false }), function (err, members) { /* Check RTP11d: get() works while suspended if waitForSync: false */ try { expect(!err, 'Check no error returned by get() while suspended if waitForSync: false').to.be.ok; @@ -2162,7 +2164,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(leavesRealtime.connection.whenState('closed'), function () { + Helper.whenPromiseSettles(leavesRealtime.connection.whenState('closed'), function () { cb(); }); leavesRealtime.close(); @@ -2186,7 +2188,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async setTimeout(cb, 1000); }, function (cb) { - helper.whenPromiseSettles(mainChannel.presence.get(), function (err, members) { + Helper.whenPromiseSettles(mainChannel.presence.get(), function (err, members) { try { expect(members && members.length).to.equal(3, 'Check three expected members here'); } catch (err) { @@ -2217,7 +2219,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async presence = channel.presence, numUpdates = 0; - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err) { helper.closeAndFinish(done, client, err); } @@ -2228,7 +2230,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async async.timesSeries( 15, function (i, cb) { - helper.whenPromiseSettles(presence.update(i.toString()), cb); + Helper.whenPromiseSettles(presence.update(i.toString()), cb); }, function (err) { if (err) { diff --git a/test/realtime/reauth.test.js b/test/realtime/reauth.test.js index 67a131693..c7daf7ab2 100644 --- a/test/realtime/reauth.test.js +++ b/test/realtime/reauth.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { +define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var clientId = 'testClientId'; var rest; @@ -23,7 +25,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { function getToken(tokenParams) { return function (state, callback) { - helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, token) { + Helper.whenPromiseSettles(rest.auth.requestToken(tokenParams, null), function (err, token) { callback(err, helper.Utils.mixin(state, { token: token })); }); }; @@ -70,7 +72,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { async.parallel( [ function (cb) { - helper.whenPromiseSettles(state.realtime.auth.authorize(null, { token: state.token }), cb); + Helper.whenPromiseSettles(state.realtime.auth.authorize(null, { token: state.token }), cb); }, function (cb) { state.realtime.connection.on('update', function (stateChange) { @@ -88,7 +90,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { function attach(channelName) { return function (state, callback) { var channel = state.realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { callback(err, state); }); }; @@ -144,7 +146,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { function checkCantAttach(channelName) { return function (state, callback) { var channel = state.realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.attach(), function (err) { + Helper.whenPromiseSettles(channel.attach(), function (err) { if (err && err.code === 40160) { callback(null, state); } else { @@ -157,7 +159,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { function checkCanPublish(channelName) { return function (state, callback) { var channel = state.realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.publish(null, null), function (err) { + Helper.whenPromiseSettles(channel.publish(null, null), function (err) { callback(err, state); }); }; @@ -166,7 +168,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { function checkCantPublish(channelName) { return function (state, callback) { var channel = state.realtime.channels.get(channelName); - helper.whenPromiseSettles(channel.publish(null, null), function (err) { + Helper.whenPromiseSettles(channel.publish(null, null), function (err) { if (err && err.code === 40160) { callback(null, state); } else { @@ -177,7 +179,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { } function testCase(name, steps) { - helper.testOnAllTransports(name, function (realtimeOpts) { + Helper.testOnAllTransports(name, function (realtimeOpts) { return function (done) { var _steps = steps.slice(); _steps.unshift(function (cb) { diff --git a/test/realtime/resume.test.js b/test/realtime/resume.test.js index 404c14a7a..5ac302e1c 100644 --- a/test/realtime/resume.test.js +++ b/test/realtime/resume.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { +define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('realtime/resume', function () { @@ -27,7 +29,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { receivingChannel.unsubscribe(event); callback(); }); - helper.whenPromiseSettles(sendingChannel.publish(event, message), function (err) { + Helper.whenPromiseSettles(sendingChannel.publish(event, message), function (err) { if (err) callback(err); }); } @@ -47,7 +49,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { var rxCount = 0; function phase0(callback) { - helper.whenPromiseSettles(rxChannel.attach(), callback); + Helper.whenPromiseSettles(rxChannel.attach(), callback); } function phase1(callback) { @@ -137,7 +139,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * Related to RTN15b, RTN15c. * @nospec */ - helper.testOnAllTransports('resume_inactive', function (realtimeOpts) { + Helper.testOnAllTransports('resume_inactive', function (realtimeOpts) { return function (done) { resume_inactive(done, 'resume_inactive' + String(Math.random()), {}, realtimeOpts); }; @@ -158,7 +160,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { var rxCount = 0; function phase0(callback) { - helper.whenPromiseSettles(rxChannel.attach(), callback); + Helper.whenPromiseSettles(rxChannel.attach(), callback); } function phase1(callback) { @@ -184,7 +186,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { var txCount = 0; function ph2TxOnce() { - helper.whenPromiseSettles( + Helper.whenPromiseSettles( txChannel.publish('sentWhileDisconnected', 'phase 2, message ' + txCount), function (err) { if (err) callback(err); @@ -261,7 +263,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * Related to RTN15b, RTN15c. * @nospec */ - helper.testOnAllTransports('resume_active', function (realtimeOpts) { + Helper.testOnAllTransports('resume_active', function (realtimeOpts) { return function (done) { resume_active(done, 'resume_active' + String(Math.random()), {}, realtimeOpts); }; @@ -271,7 +273,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * Resume with loss of continuity * @spec RTN15c7 */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_lost_continuity', function (realtimeOpts) { return function (done) { @@ -291,7 +293,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }, function (cb) { suspendedChannel.state = 'suspended'; - helper.whenPromiseSettles(attachedChannel.attach(), cb); + Helper.whenPromiseSettles(attachedChannel.attach(), cb); }, function (cb) { /* Sabotage the resume */ @@ -338,7 +340,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * Resume with token error * @spec RTN15c5 */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_token_error', function (realtimeOpts) { return function (done) { @@ -354,7 +356,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); }, function (cb) { - helper.whenPromiseSettles(realtime.auth.requestToken({ ttl: 1 }, null), function (err, token) { + Helper.whenPromiseSettles(realtime.auth.requestToken({ ttl: 1 }, null), function (err, token) { badtoken = token; cb(err); }); @@ -392,7 +394,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * Resume with fatal error * @spec RTN15c4 */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_fatal_error', function (realtimeOpts) { return function (done) { @@ -658,7 +660,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { const rxChannels = channelNames.map((name) => rxRealtime.channels.get(name)); function attachChannels(callback) { - async.each(rxChannels, (channel, cb) => helper.whenPromiseSettles(channel.attach(), cb), callback); + async.each(rxChannels, (channel, cb) => Helper.whenPromiseSettles(channel.attach(), cb), callback); } function publishSubscribeWhileConnectedOnce(callback) { @@ -688,7 +690,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { channelNames, (name, cb) => { const tx = txRest.channels.get(name); - helper.whenPromiseSettles(tx.publish('sentWhileDisconnected', null), cb); + Helper.whenPromiseSettles(tx.publish('sentWhileDisconnected', null), cb); }, callback, ); diff --git a/test/realtime/sync.test.js b/test/realtime/sync.test.js index 1d6334b78..c53b1c68f 100644 --- a/test/realtime/sync.test.js +++ b/test/realtime/sync.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var createPM = Ably.protocolMessageFromDeserialized; @@ -93,7 +95,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { try { expect(results.length).to.equal(2, 'Check correct number of results'); expect(channel.presence.syncComplete, 'Check in sync').to.be.ok; @@ -136,7 +138,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }, function (cb) { - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { try { expect(results.length).to.equal(2, 'Check correct number of results'); expect(channel.presence.syncComplete, 'Check in sync').to.be.ok; @@ -245,7 +247,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async err ? reject(err) : resolve(); }; - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -334,7 +336,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async err ? reject(err) : resolve(); }; - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -420,7 +422,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async err ? reject(err) : resolve(); }; - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -578,7 +580,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var done = function (err) { err ? reject(err) : resolve(); }; - helper.whenPromiseSettles(channel.presence.get(), function (err, results) { + Helper.whenPromiseSettles(channel.presence.get(), function (err, results) { if (err) { helper.closeAndFinish(done, realtime, err); return; @@ -632,13 +634,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async [ waitForBothConnect, function (cb) { - helper.whenPromiseSettles(entererChannel.attach(), cb); + Helper.whenPromiseSettles(entererChannel.attach(), cb); }, function (cb) { async.times( 110, function (i, presCb) { - helper.whenPromiseSettles(entererChannel.presence.enterClient(i.toString(), null), presCb); + Helper.whenPromiseSettles(entererChannel.presence.enterClient(i.toString(), null), presCb); }, cb, ); @@ -664,10 +666,10 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); } }; - helper.whenPromiseSettles(syncerChannel.attach(), cb); + Helper.whenPromiseSettles(syncerChannel.attach(), cb); }, function (cb) { - helper.whenPromiseSettles(syncerChannel.presence.get(), function (err, presenceSet) { + Helper.whenPromiseSettles(syncerChannel.presence.get(), function (err, presenceSet) { try { expect(presenceSet && presenceSet.length).to.equal(111, 'Check everyone’s in presence set'); } catch (err) { diff --git a/test/realtime/transports.test.js b/test/realtime/transports.test.js index e94b60c97..0ea8e7c51 100644 --- a/test/realtime/transports.test.js +++ b/test/realtime/transports.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai', 'ably'], function (helper, async, chai, Ably) { +define(['shared_helper', 'async', 'chai', 'ably'], function (Helper, async, chai, Ably) { + const helper = new Helper(); + const expect = chai.expect; const Defaults = Ably.Rest.Platform.Defaults; const originialWsCheckUrl = Defaults.wsConnectivityUrl; diff --git a/test/realtime/utils.test.js b/test/realtime/utils.test.js index 35d94f627..5e20ee3ff 100644 --- a/test/realtime/utils.test.js +++ b/test/realtime/utils.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('incremental backoff and jitter', function () { diff --git a/test/rest/auth.test.js b/test/rest/auth.test.js index cc980c1b1..4727ce818 100644 --- a/test/rest/auth.test.js +++ b/test/rest/auth.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['chai', 'shared_helper', 'async', 'globals'], function (chai, helper, async, globals) { +define(['chai', 'shared_helper', 'async', 'globals'], function (chai, Helper, async, globals) { + const helper = new Helper(); + var currentTime; var rest; var expect = chai.expect; diff --git a/test/rest/batch.test.js b/test/rest/batch.test.js index b3ecf8483..2b19faaa6 100644 --- a/test/rest/batch.test.js +++ b/test/rest/batch.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('rest/batchPublish', function () { @@ -267,8 +269,8 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { key: testApp.keys[4].keyStr /* this key has revocableTokens enabled */, }); - const clientId1 = `clientId1-${helper.randomString()}`; - const clientId2 = `clientId2-${helper.randomString()}`; + const clientId1 = `clientId1-${Helper.randomString()}`; + const clientId2 = `clientId2-${Helper.randomString()}`; // First, we fetch tokens for a couple of different clientIds... const [clientId1TokenDetails, clientId2TokenDetails] = await Promise.all([ @@ -363,7 +365,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { key: testApp.keys[4].keyStr /* this key has revocableTokens enabled */, }); - const clientId = `clientId-${helper.randomString()}`; + const clientId = `clientId-${Helper.randomString()}`; const serverTimeAtStartOfTest = await rest.time(); const issuedBefore = serverTimeAtStartOfTest - 20 * 60 * 1000; // i.e. ~20 minutes ago (arbitrarily chosen) diff --git a/test/rest/capability.test.js b/test/rest/capability.test.js index 905f289db..52df30bd1 100644 --- a/test/rest/capability.test.js +++ b/test/rest/capability.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var currentTime; var rest; var testApp; diff --git a/test/rest/fallbacks.test.js b/test/rest/fallbacks.test.js index 290044447..e8bafb93b 100644 --- a/test/rest/fallbacks.test.js +++ b/test/rest/fallbacks.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { +define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var goodHost; diff --git a/test/rest/history.test.js b/test/rest/history.test.js index 09f3b52f9..5d037f121 100644 --- a/test/rest/history.test.js +++ b/test/rest/history.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { +define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; var exports = {}; @@ -30,7 +32,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * @spec RSL2 * @spec RSL2a */ - helper.restTestOnJsonMsgpack('history_simple', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('history_simple', async function (rest, channelName) { var testchannel = rest.channels.get('persisted:' + channelName); /* first, send a number of events to this channel */ @@ -61,7 +63,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * @spec RSL2 * @spec RSL2a */ - helper.restTestOnJsonMsgpack('history_multiple', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('history_multiple', async function (rest, channelName) { var testchannel = rest.channels.get('persisted:' + channelName); /* first, send a number of events to this channel */ @@ -89,7 +91,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { * @spec RSL2b2 * @specpartial RSL2b3 - should also test maximum supported limit of 1000 */ - helper.restTestOnJsonMsgpack('history_simple_paginated_b', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('history_simple_paginated_b', async function (rest, channelName) { var testchannel = rest.channels.get('persisted:' + channelName); /* first, send a number of events to this channel */ @@ -251,7 +253,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); /** @nospec */ - helper.restTestOnJsonMsgpack('history_encoding_errors', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('history_encoding_errors', async function (rest, channelName) { var testchannel = rest.channels.get('persisted:' + channelName); var badMessage = { name: 'jsonUtf8string', encoding: 'json/utf-8', data: '{"foo":"bar"}' }; testchannel.publish(badMessage); @@ -264,7 +266,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); /** @specpartial TG4 - in the context of RestChannel#history */ - helper.restTestOnJsonMsgpack('history_no_next_page', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('history_no_next_page', async function (rest, channelName) { const channel = rest.channels.get(channelName); const firstPage = await channel.history(); diff --git a/test/rest/http.test.js b/test/rest/http.test.js index 29020536e..eee16156d 100644 --- a/test/rest/http.test.js +++ b/test/rest/http.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; var Defaults = Ably.Rest.Platform.Defaults; diff --git a/test/rest/init.test.js b/test/rest/init.test.js index 488c90714..c218b7c57 100644 --- a/test/rest/init.test.js +++ b/test/rest/init.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { +define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) { + const helper = new Helper(); + var expect = chai.expect; describe('rest/init', function () { diff --git a/test/rest/message.test.js b/test/rest/message.test.js index 28a131289..f22c2ee5f 100644 --- a/test/rest/message.test.js +++ b/test/rest/message.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var expect = chai.expect; var noop = function () {}; diff --git a/test/rest/presence.test.js b/test/rest/presence.test.js index 6679266c7..55e1471d4 100644 --- a/test/rest/presence.test.js +++ b/test/rest/presence.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var rest; var cipherConfig; var expect = chai.expect; diff --git a/test/rest/push.test.js b/test/rest/push.test.js index 251b77ef0..e00406bfd 100644 --- a/test/rest/push.test.js +++ b/test/rest/push.test.js @@ -2,12 +2,14 @@ define(['ably', 'shared_helper', 'async', 'chai', 'test/support/push_channel_transport', 'push'], function ( Ably, - helper, + Helper, async, chai, pushChannelTransport, PushPlugin, ) { + const helper = new Helper(); + var expect = chai.expect; var originalPushConfig = Ably.Realtime.Platform.Config.push; @@ -405,7 +407,7 @@ define(['ably', 'shared_helper', 'async', 'chai', 'test/support/push_channel_tra } }) .then(() => { - helper.whenPromiseSettles(realtime.push.admin.publish(pushRecipient, pushPayload), function (err) { + Helper.whenPromiseSettles(realtime.push.admin.publish(pushRecipient, pushPayload), function (err) { if (err) { helper.closeAndFinish(done, realtime, err); } diff --git a/test/rest/request.test.js b/test/rest/request.test.js index 7a1dd2d88..bba9f0744 100644 --- a/test/rest/request.test.js +++ b/test/rest/request.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async, chai) { +define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; var echoServerHost = 'echo.ably.io'; @@ -27,7 +29,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSC7e - tests providing a version value in .request parameters * @specpartial CSV2c - tests version is provided in http requests */ - helper.restTestOnJsonMsgpack('request_version', function (rest) { + Helper.restTestOnJsonMsgpack('request_version', function (rest) { const version = 150; // arbitrarily chosen async function testRequestHandler(_, __, headers) { @@ -54,7 +56,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec HP5 * @specpartial RSC19f - basic test for passing a http method, path and version parameters */ - helper.restTestOnJsonMsgpack('request_time', async function (rest) { + Helper.restTestOnJsonMsgpack('request_time', async function (rest) { const res = await rest.request('get', '/time', 3, null, null, null); expect(res.statusCode).to.equal(200, 'Check statusCode'); expect(res.success).to.equal(true, 'Check success'); @@ -70,7 +72,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec HP6 * @spec HP7 */ - helper.restTestOnJsonMsgpack('request_404', async function (rest) { + Helper.restTestOnJsonMsgpack('request_404', async function (rest) { /* NB: can't just use /invalid or something as the CORS preflight will * fail. Need something superficially a valid path but where the actual * request fails */ @@ -107,7 +109,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial HP2 - tests overriden .next method only * @specpartial RSC19f - more tests with passing other methods, body and parameters */ - helper.restTestOnJsonMsgpack('request_post_get_messages', async function (rest, channelName) { + Helper.restTestOnJsonMsgpack('request_post_get_messages', async function (rest, channelName) { var channelPath = '/channels/' + channelName + '/messages', msgone = { name: 'faye', data: 'whittaker' }, msgtwo = { name: 'martin', data: 'reed' }; @@ -152,7 +154,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @spec HP7 * @specpartial RSC19f - more tests with POST method and passing body */ - helper.restTestOnJsonMsgpack('request_batch_api_success', async function (rest, name) { + Helper.restTestOnJsonMsgpack('request_batch_api_success', async function (rest, name) { var body = { channels: [name + '1', name + '2'], messages: { data: 'foo' } }; const res = await rest.request('POST', '/messages', 2, {}, body, {}); @@ -183,7 +185,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * @specpartial RSC19f - more tests with POST method and passing body * @specskip */ - helper.restTestOnJsonMsgpack.skip('request_batch_api_partial_success', async function (rest, name) { + Helper.restTestOnJsonMsgpack.skip('request_batch_api_partial_success', async function (rest, name) { var body = { channels: [name, '[invalid', ''], messages: { data: 'foo' } }; var res = await rest.request('POST', '/messages', 2, {}, body, {}); diff --git a/test/rest/stats.test.js b/test/rest/stats.test.js index 0980ccef5..a92334069 100644 --- a/test/rest/stats.test.js +++ b/test/rest/stats.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; diff --git a/test/rest/status.test.js b/test/rest/status.test.js index c9c40ffae..422868913 100644 --- a/test/rest/status.test.js +++ b/test/rest/status.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; @@ -33,7 +35,7 @@ define(['shared_helper', 'chai'], function (helper, chai) { * @spec CHM2e * @spec CHM2f */ - helper.restTestOnJsonMsgpack('status0', async function (rest) { + Helper.restTestOnJsonMsgpack('status0', async function (rest) { var channel = rest.channels.get('status0'); var channelDetails = await channel.status(); expect(channelDetails.channelId).to.equal('status0'); diff --git a/test/rest/time.test.js b/test/rest/time.test.js index aae050c61..bce93d1b4 100644 --- a/test/rest/time.test.js +++ b/test/rest/time.test.js @@ -1,6 +1,8 @@ 'use strict'; -define(['shared_helper', 'chai'], function (helper, chai) { +define(['shared_helper', 'chai'], function (Helper, chai) { + const helper = new Helper(); + var rest; var expect = chai.expect; diff --git a/test/support/root_hooks.js b/test/support/root_hooks.js index aab15e140..7e7ed1005 100644 --- a/test/support/root_hooks.js +++ b/test/support/root_hooks.js @@ -1,4 +1,6 @@ -define(['shared_helper'], function (helper) { +define(['shared_helper'], function (Helper) { + const helper = new Helper(); + after(function (done) { this.timeout(10 * 1000); helper.tearDownApp(function (err) { @@ -10,8 +12,16 @@ define(['shared_helper'], function (helper) { }); }); - afterEach(helper.closeActiveClients); - afterEach(helper.logTestResults); - afterEach(helper.flushTestLogs); - beforeEach(helper.clearTransportPreference); + afterEach(function () { + helper.closeActiveClients(); + }); + afterEach(function () { + helper.logTestResults(this); + }); + afterEach(function () { + helper.flushTestLogs(); + }); + beforeEach(function () { + helper.clearTransportPreference(); + }); });