diff --git a/test/browser/connection.test.js b/test/browser/connection.test.js index 813819539..69abc4fb4 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 0331b6dd6..fbdc961bf 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; diff --git a/test/browser/modular.test.js b/test/browser/modular.test.js index 7289eb077..7a6688b8f 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) => { @@ -885,8 +886,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/simple.test.js b/test/browser/simple.test.js index 260f4d548..325baf093 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 () { diff --git a/test/common/modules/shared_helper.js b/test/common/modules/shared_helper.js index a12c2af3f..b1cfd46ba 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. + */ + 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); - } + 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 c9195ef4c..05c753949 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 = {}; @@ -639,7 +641,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Check state change reason is propogated during a disconnect * (when connecting with a token that expires while connected) */ - helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) { + Helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) { return function (done) { var clientRealtime, rest = helper.AblyRest(); @@ -733,7 +735,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * If using authcallback when a token expires, should automatically request a * new token */ - 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(); @@ -776,7 +778,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Same as previous but with just a token, so ably-js doesn't know that the * token's expired */ - 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(); @@ -818,7 +820,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Same as previous but with no way to generate a new token */ - 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(); @@ -861,7 +863,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Try to connect with an expired token string */ - helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) { + Helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); @@ -905,7 +907,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * use authorize() to force a reauth using an existing authCallback */ - helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) { + Helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) { return function (done) { var realtime, rest = helper.AblyRest(); @@ -1368,7 +1370,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }); - 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, diff --git a/test/realtime/channel.test.js b/test/realtime/channel.test.js index 72ddd3153..d0368f055 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; @@ -164,7 +166,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Channel init with options */ - helper.testOnAllTransports('channelinit0', function (realtimeOpts) { + Helper.testOnAllTransports('channelinit0', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -197,7 +199,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Base attach case */ - helper.testOnAllTransports('channelattach0', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach0', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -220,7 +222,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Attach before connect */ - helper.testOnAllTransports('channelattach2', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach2', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -242,7 +244,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Attach then detach */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'channelattach3', function (realtimeOpts) { return function (done) { @@ -279,7 +281,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Attach with an empty channel and expect a channel error * and the connection to remain open */ - helper.testOnAllTransports('channelattachempty', function (realtimeOpts) { + Helper.testOnAllTransports('channelattachempty', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -311,7 +313,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Attach with an invalid channel name and expect a channel error * and the connection to remain open */ - helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) { + Helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -349,7 +351,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Publishing on a nonattached channel */ - helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) { + Helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -376,7 +378,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * publishing on a nonattached channel with an invalid channel name */ - helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -405,7 +407,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Attach with an invalid channel name and expect a channel error * and the connection to remain open */ - helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) { + Helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -484,7 +486,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } }); - helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsBasicChannelsGet'; try { @@ -537,7 +539,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; }); - helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsBasicSetOptions'; try { @@ -586,7 +588,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; }); - helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) { return function (done) { var testName = 'subscribeAfterSetOptions'; try { @@ -658,7 +660,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async } }); - helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) { + Helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) { return function (done) { var testName = 'setOptionsCallbackBehaviour'; try { @@ -733,7 +735,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); /* Verify modes is ignored when params.modes is present */ - helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsModesAndChannelModes'; try { @@ -787,7 +789,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; }); - helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelModes'; try { @@ -836,7 +838,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }; }); - helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { + Helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { return function (done) { var testName = 'attachWithChannelParamsDeltaAndModes'; try { diff --git a/test/realtime/connection.test.js b/test/realtime/connection.test.js index ebcb3795d..6efba0001 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; diff --git a/test/realtime/connectivity.test.js b/test/realtime/connectivity.test.js index 39b3ccde0..9c8097e76 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 () { diff --git a/test/realtime/crypto.test.js b/test/realtime/crypto.test.js index 2f7ba86d3..fbbbe085b 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; @@ -415,13 +417,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /** * Publish and subscribe, various transport, 128 and 256-bit */ - helper.testOnAllTransports('single_send_128', function (realtimeOpts) { + Helper.testOnAllTransports('single_send_128', function (realtimeOpts) { return function (done) { single_send(done, realtimeOpts, 128); }; }); - helper.testOnAllTransports('single_send_256', function (realtimeOpts) { + Helper.testOnAllTransports('single_send_256', function (realtimeOpts) { return function (done) { single_send(done, realtimeOpts, 256); }; diff --git a/test/realtime/delta.test.js b/test/realtime/delta.test.js index 79420bdbf..44e580f7e 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' }, diff --git a/test/realtime/encoding.test.js b/test/realtime/encoding.test.js index 82ad4c2be..d1bf4a685 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; diff --git a/test/realtime/event_emitter.test.js b/test/realtime/event_emitter.test.js index 90e9c718f..bec7608b9 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 3fd0ccb55..9f83359be 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; @@ -557,7 +559,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* RTN14d last sentence: Check that if we received a 5xx disconnected, when * we try again we use a fallback host */ - helper.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 ef9fd3fd2..630991871 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) { diff --git a/test/realtime/init.test.js b/test/realtime/init.test.js index 055077489..f1672764c 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 () { diff --git a/test/realtime/message.test.js b/test/realtime/message.test.js index 6baf10b7c..fdac6bb39 100644 --- a/test/realtime/message.test.js +++ b/test/realtime/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; let config = Ably.Realtime.Platform.Config; var createPM = Ably.protocolMessageFromDeserialized; @@ -71,7 +73,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async /* * Test publishes in quick succession (on successive ticks of the event loop) */ - helper.testOnAllTransports('publishfast', function (realtimeOpts) { + Helper.testOnAllTransports('publishfast', function (realtimeOpts) { return function (done) { try { var realtime = helper.AblyRealtime(realtimeOpts); @@ -134,7 +136,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async * Test queuing: publishing a series of messages that start before the lib is connected * Also checks they arrive in the right order */ - helper.testOnAllTransports('publishQueued', function (realtimeOpts) { + Helper.testOnAllTransports('publishQueued', function (realtimeOpts) { return function (done) { var txRealtime, rxRealtime; try { @@ -584,7 +586,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }, 500); }); - helper.testOnAllTransports('publish', function (realtimeOpts) { + Helper.testOnAllTransports('publish', function (realtimeOpts) { return function (done) { var count = 10; var cbCount = 10; diff --git a/test/realtime/presence.test.js b/test/realtime/presence.test.js index a0fd7ed84..26b5b4b3f 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; diff --git a/test/realtime/reauth.test.js b/test/realtime/reauth.test.js index d8996718e..2d5c2ae02 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; @@ -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 e074df27a..190795cb9 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 () { @@ -133,7 +135,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); } - helper.testOnAllTransports('resume_inactive', function (realtimeOpts) { + Helper.testOnAllTransports('resume_inactive', function (realtimeOpts) { return function (done) { resume_inactive(done, 'resume_inactive' + String(Math.random()), {}, realtimeOpts); }; @@ -253,7 +255,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); } - helper.testOnAllTransports('resume_active', function (realtimeOpts) { + Helper.testOnAllTransports('resume_active', function (realtimeOpts) { return function (done) { resume_active(done, 'resume_active' + String(Math.random()), {}, realtimeOpts); }; @@ -262,7 +264,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { /* RTN15c3 * Resume with loss of continuity */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_lost_continuity', function (realtimeOpts) { return function (done) { @@ -328,7 +330,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { /* RTN15c5 * Resume with token error */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_token_error', function (realtimeOpts) { return function (done) { @@ -381,7 +383,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { /* RTN15c4 * Resume with fatal error */ - helper.testOnAllTransports( + Helper.testOnAllTransports( 'resume_fatal_error', function (realtimeOpts) { return function (done) { diff --git a/test/realtime/sync.test.js b/test/realtime/sync.test.js index 390d102f2..523bf2d1f 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; diff --git a/test/realtime/transports.test.js b/test/realtime/transports.test.js index 67085e23e..1e9ed3322 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 0794f6a6b..00c4fe431 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; // RTB1 diff --git a/test/rest/auth.test.js b/test/rest/auth.test.js index 39e5d7233..8be261151 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 73f9ad8c8..e9856b833 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 () { diff --git a/test/rest/capability.test.js b/test/rest/capability.test.js index 6684cce8b..fac2b1de2 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 6e6a2d016..633edbe49 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 32c64c0b6..1155ca632 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 = {}; @@ -25,7 +27,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { }); }); - 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 */ @@ -51,7 +53,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { ); }); - 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 */ @@ -74,7 +76,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { ); }); - 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 */ @@ -223,7 +225,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { ); }); - 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); @@ -235,7 +237,7 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { expect(message.encoding).to.equal(badMessage.encoding, 'Verify encoding preserved'); }); - 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 f8911dcc4..32d8e7328 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 2d4b316dd..7a0afbb1e 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 40da61677..f75833008 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 d0e6d98a7..d9d668e3c 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 ddc0d148a..0d83ac194 100644 --- a/test/rest/push.test.js +++ b/test/rest/push.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 expect = chai.expect; var testDevice = { diff --git a/test/rest/request.test.js b/test/rest/request.test.js index 06f8b0e06..2cf60f96f 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'; @@ -20,7 +22,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); }); - helper.restTestOnJsonMsgpack('request_version', function (rest) { + Helper.restTestOnJsonMsgpack('request_version', function (rest) { const version = 150; // arbitrarily chosen async function testRequestHandler(_, __, headers) { @@ -39,7 +41,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async rest.request('get', '/time' /* arbitrarily chosen */, version, null, null, null); }); - helper.restTestOnJsonMsgpack('request_time', async function (rest) { + Helper.restTestOnJsonMsgpack('request_time', async function (rest) { const res = await rest.request('get', '/time', Defaults.protocolVersion, null, null, null); expect(res.statusCode).to.equal(200, 'Check statusCode'); expect(res.success).to.equal(true, 'Check success'); @@ -47,7 +49,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async expect(res.items.length).to.equal(1, 'Check array was of length 1'); }); - 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 */ @@ -79,7 +81,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async }); /* Use the request feature to publish, then retrieve (one at a time), some messages */ - 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' }; @@ -121,7 +123,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async expect(res.items[0].data).to.equal(msgtwo.data, 'Check data is as expected'); }); - 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, {}); @@ -141,7 +143,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async expect(res.items[1].channel).to.equal(name + '2', 'Verify channel2 response includes correct channel'); }); - 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 171a69730..540dccf9f 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 d1868e912..f296d7770 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; @@ -19,7 +21,7 @@ define(['shared_helper', 'chai'], function (helper, chai) { }); }); - 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 f491e892c..b6cb68f90 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(); + }); });