From c4836223f5a57c44ad644a84ee8ef6cc2700b98d Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 6 Jun 2024 15:43:30 -0300 Subject: [PATCH] Convert shared helper to a class TODO figure out what should be class method; at the moment everything is instance except for the ones that have a .skip because that wasn't implementable for an instance method. But there may well be other stuff (e.g. stuff that's used at a non-test level, or it might just be that the instance doesn't always have a test) --- test/browser/connection.test.js | 4 +- test/browser/http.test.js | 4 +- test/browser/modular.test.js | 7 +- test/browser/simple.test.js | 4 +- test/common/modules/shared_helper.js | 464 +++++++++++++-------------- test/realtime/auth.test.js | 18 +- test/realtime/channel.test.js | 36 ++- test/realtime/connection.test.js | 4 +- test/realtime/connectivity.test.js | 4 +- test/realtime/crypto.test.js | 8 +- test/realtime/delta.test.js | 4 +- test/realtime/encoding.test.js | 4 +- test/realtime/event_emitter.test.js | 4 +- test/realtime/failure.test.js | 6 +- test/realtime/history.test.js | 4 +- test/realtime/init.test.js | 4 +- test/realtime/message.test.js | 6 +- test/realtime/presence.test.js | 4 +- test/realtime/reauth.test.js | 6 +- test/realtime/resume.test.js | 14 +- test/realtime/sync.test.js | 4 +- test/realtime/transports.test.js | 4 +- test/realtime/utils.test.js | 4 +- test/rest/auth.test.js | 4 +- test/rest/batch.test.js | 4 +- test/rest/capability.test.js | 4 +- test/rest/fallbacks.test.js | 4 +- test/rest/history.test.js | 14 +- test/rest/http.test.js | 4 +- test/rest/init.test.js | 4 +- test/rest/message.test.js | 4 +- test/rest/presence.test.js | 4 +- test/rest/push.test.js | 4 +- test/rest/request.test.js | 16 +- test/rest/stats.test.js | 4 +- test/rest/status.test.js | 6 +- test/rest/time.test.js | 4 +- test/support/root_hooks.js | 20 +- 38 files changed, 393 insertions(+), 328 deletions(-) diff --git a/test/browser/connection.test.js b/test/browser/connection.test.js index 813819539d..69abc4fb46 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 0331b6dd6e..fbdc961bf6 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 7289eb0778..7a6688b8fe 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 260f4d548f..325baf0930 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 a12c2af3fa..b1cfd46ba4 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 c9195ef4c3..05c7539491 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 72ddd31537..d0368f0559 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 51a1340317..6a8069af3c 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; describe('realtime/connection', function () { diff --git a/test/realtime/connectivity.test.js b/test/realtime/connectivity.test.js index d0c1e1ea23..df272b0ded 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 2f7ba86d31..fbbbe085b7 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 79420bdbf4..44e580f7ed 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 ce59883775..787be2af20 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; // TODO something with this one diff --git a/test/realtime/event_emitter.test.js b/test/realtime/event_emitter.test.js index 90e9c718f4..bec7608b9d 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 3fd0ccb554..9f83359be9 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 ef9fd3fd2b..630991871d 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 055077489b..f1672764c6 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 1a2c85331b..906073a2ef 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; var displayError = helper.displayError; var utils = helper.Utils; @@ -8,7 +10,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var closeAndFinish = helper.closeAndFinish; var createPM = Ably.protocolMessageFromDeserialized; var monitorConnection = helper.monitorConnection; - var testOnAllTransports = helper.testOnAllTransports; + var testOnAllTransports = Helper.testOnAllTransports; var whenPromiseSettles = helper.whenPromiseSettles; var publishIntervalHelper = function (currentMessageNum, channel, dataFn, onPublish) { diff --git a/test/realtime/presence.test.js b/test/realtime/presence.test.js index a0fd7ed840..26b5b4b3f6 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 8eca481719..50c72ba1c7 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 e074df27a7..190795cb9e 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 390d102f2b..523bf2d1f3 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 77506a9512..ac0f00da7e 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 0794f6a6be..00c4fe431d 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 39e5d7233c..8be261151d 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 73f9ad8c82..e9856b8337 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 6684cce8b4..fac2b1de21 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 6e6a2d016c..633edbe496 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 32c64c0b69..1155ca6322 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 f8911dcc4e..32d8e7328e 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 2d4b316dde..7a0afbb1e1 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 40da61677e..f75833008c 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 d0e6d98a74..d9d668e3cd 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 ddc0d148a4..0d83ac1943 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 06f8b0e06c..2cf60f96f9 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 171a69730a..540dccf9fc 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 d1868e912d..f296d7770f 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 f491e892c8..b6cb68f903 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 aab15e140d..7e7ed1005c 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(); + }); });