diff --git a/package.json b/package.json index 4c56cc2b5..e45d1d4c8 100644 --- a/package.json +++ b/package.json @@ -81,5 +81,8 @@ "source-map-support": "^0.5.13", "tslint": "^5.20.1", "typescript": "^3.7.3" + }, + "jest": { + "testEnvironment": "node" } } diff --git a/spec/MockStorageApi.js b/spec/MockStorageApi.js index 1063ad3db..d985fe0cf 100644 --- a/spec/MockStorageApi.js +++ b/spec/MockStorageApi.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,7 +19,7 @@ limitations under the License. * A mock implementation of the webstorage api * @constructor */ -function MockStorageApi() { +export function MockStorageApi() { this.data = {}; this.keys = []; this.length = 0; @@ -52,5 +53,3 @@ MockStorageApi.prototype = { }, }; -/** */ -module.exports = MockStorageApi; diff --git a/spec/TestClient.js b/spec/TestClient.js index 1663847d2..4b661c83b 100644 --- a/spec/TestClient.js +++ b/spec/TestClient.js @@ -21,11 +21,13 @@ limitations under the License. // load olm before the sdk if possible import './olm-loader'; -import sdk from '..'; -import testUtils from './test-utils'; import MockHttpBackend from 'matrix-mock-request'; -import LocalStorageCryptoStore from '../lib/crypto/store/localStorage-crypto-store'; -import logger from '../lib/logger'; +import {LocalStorageCryptoStore} from '../src/crypto/store/localStorage-crypto-store'; +import {logger} from '../src/logger'; +import {WebStorageSessionStore} from "../src/store/session/webstorage"; +import {syncPromise} from "./test-utils"; +import {createClient} from "../src/matrix"; +import {MockStorageApi} from "./MockStorageApi"; /** * Wrapper for a MockStorageApi, MockHttpBackend and MatrixClient @@ -39,16 +41,16 @@ import logger from '../lib/logger'; * session store. If undefined, we will create a MockStorageApi. * @param {object} options additional options to pass to the client */ -export default function TestClient( +export function TestClient( userId, deviceId, accessToken, sessionStoreBackend, options, ) { this.userId = userId; this.deviceId = deviceId; if (sessionStoreBackend === undefined) { - sessionStoreBackend = new testUtils.MockStorageApi(); + sessionStoreBackend = new MockStorageApi(); } - const sessionStore = new sdk.WebStorageSessionStore(sessionStoreBackend); + const sessionStore = new WebStorageSessionStore(sessionStoreBackend); this.httpBackend = new MockHttpBackend(); @@ -65,7 +67,7 @@ export default function TestClient( this.cryptoStore = new LocalStorageCryptoStore(sessionStoreBackend); options.cryptoStore = this.cryptoStore; } - this.client = sdk.createClient(options); + this.client = createClient(options); this.deviceKeys = null; this.oneTimeKeys = {}; @@ -97,7 +99,7 @@ TestClient.prototype.start = function() { return Promise.all([ this.httpBackend.flushAllExpected(), - testUtils.syncPromise(this.client), + syncPromise(this.client), ]).then(() => { logger.log(this + ': started'); }); @@ -225,7 +227,7 @@ TestClient.prototype.flushSync = function() { logger.log(`${this}: flushSync`); return Promise.all([ this.httpBackend.flush('/sync', 1), - testUtils.syncPromise(this.client), + syncPromise(this.client), ]).then(() => { logger.log(`${this}: flushSync completed`); }); diff --git a/spec/integ/devicelist-integ-spec.js b/spec/integ/devicelist-integ-spec.js index 52c906625..039d541ff 100644 --- a/spec/integ/devicelist-integ-spec.js +++ b/spec/integ/devicelist-integ-spec.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd Copyright 2018 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,9 +16,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import TestClient from '../TestClient'; -import testUtils from '../test-utils'; -import logger from '../../lib/logger'; +import {TestClient} from '../TestClient'; +import * as testUtils from '../test-utils'; +import {logger} from '../../src/logger'; const ROOM_ID = "!room:id"; diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index 1e3471b64..7105a406e 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -2,6 +2,7 @@ Copyright 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd Copyright 2018 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,11 +31,11 @@ import 'source-map-support/register'; // load olm before the sdk if possible import '../olm-loader'; -const sdk = require("../.."); -const utils = require("../../lib/utils"); -const testUtils = require("../test-utils"); -const TestClient = require('../TestClient').default; -import logger from '../../lib/logger'; +import {logger} from '../../src/logger'; +import * as testUtils from "../test-utils"; +import * as utils from "../../src/utils"; +import {TestClient} from "../TestClient"; +import {CRYPTO_ENABLED} from "../../src/client"; let aliTestClient; const roomId = "!room:localhost"; @@ -400,7 +401,7 @@ function firstSync(testClient) { describe("MatrixClient crypto", function() { - if (!sdk.CRYPTO_ENABLED) { + if (!CRYPTO_ENABLED) { return; } diff --git a/spec/integ/matrix-client-event-emitter.spec.js b/spec/integ/matrix-client-event-emitter.spec.js index 62381171e..e56d824a5 100644 --- a/spec/integ/matrix-client-event-emitter.spec.js +++ b/spec/integ/matrix-client-event-emitter.spec.js @@ -1,24 +1,18 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const HttpBackend = require("matrix-mock-request"); -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {TestClient} from "../TestClient"; describe("MatrixClient events", function() { - const baseUrl = "http://localhost.or.something"; let client; let httpBackend; const selfUserId = "@alice:localhost"; const selfAccessToken = "aseukfgwef"; beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); - client = sdk.createClient({ - baseUrl: baseUrl, - userId: selfUserId, - accessToken: selfAccessToken, - }); + const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken); + client = testClient.client; + httpBackend = testClient.httpBackend; httpBackend.when("GET", "/pushrules").respond(200, {}); httpBackend.when("POST", "/filter").respond(200, { filter_id: "a filter id" }); }); diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index 7024e47c6..8815582e1 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -1,12 +1,10 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const HttpBackend = require("matrix-mock-request"); -const utils = require("../test-utils"); -const EventTimeline = sdk.EventTimeline; -import logger from '../../lib/logger'; +import * as utils from "../test-utils"; +import {EventTimeline} from "../../src/matrix"; +import {logger} from "../../src/logger"; +import {TestClient} from "../TestClient"; -const baseUrl = "http://localhost.or.something"; const userId = "@alice:localhost"; const userName = "Alice"; const accessToken = "aseukfgwef"; @@ -103,8 +101,9 @@ describe("getEventTimeline support", function() { let client; beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); + const testClient = new TestClient(userId, "DEVICE", accessToken); + client = testClient.client; + httpBackend = testClient.httpBackend; }); afterEach(function() { @@ -115,12 +114,6 @@ describe("getEventTimeline support", function() { }); it("timeline support must be enabled to work", function() { - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - }); - return startClient(httpBackend, client).then(function() { const room = client.getRoom(roomId); const timelineSet = room.getTimelineSets()[0]; @@ -131,12 +124,15 @@ describe("getEventTimeline support", function() { }); it("timeline support works when enabled", function() { - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - timelineSupport: true, - }); + const testClient = new TestClient( + userId, + "DEVICE", + accessToken, + undefined, + {timelineSupport: true}, + ); + client = testClient.client; + httpBackend = testClient.httpBackend; return startClient(httpBackend, client).then(() => { const room = client.getRoom(roomId); @@ -151,11 +147,7 @@ describe("getEventTimeline support", function() { it("scrollback should be able to scroll back to before a gappy /sync", function() { // need a client with timelineSupport disabled to make this work - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - }); + let room; return startClient(httpBackend, client).then(function() { @@ -223,15 +215,15 @@ describe("MatrixClient event timelines", function() { let httpBackend = null; beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); - - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - timelineSupport: true, - }); + const testClient = new TestClient( + userId, + "DEVICE", + accessToken, + undefined, + {timelineSupport: true}, + ); + client = testClient.client; + httpBackend = testClient.httpBackend; return startClient(httpBackend, client); }); diff --git a/spec/integ/matrix-client-methods.spec.js b/spec/integ/matrix-client-methods.spec.js index 6b2a83df0..35d47ce70 100644 --- a/spec/integ/matrix-client-methods.spec.js +++ b/spec/integ/matrix-client-methods.spec.js @@ -1,39 +1,25 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const HttpBackend = require("matrix-mock-request"); -const publicGlobals = require("../../lib/matrix"); -const Room = publicGlobals.Room; -const MemoryStore = publicGlobals.MemoryStore; -const Filter = publicGlobals.Filter; -const utils = require("../test-utils"); -const MockStorageApi = require("../MockStorageApi"); +import * as utils from "../test-utils"; +import {CRYPTO_ENABLED} from "../../src/client"; +import {Filter, MemoryStore, Room} from "../../src/matrix"; +import {TestClient} from "../TestClient"; describe("MatrixClient", function() { - const baseUrl = "http://localhost.or.something"; let client = null; let httpBackend = null; let store = null; - let sessionStore = null; const userId = "@alice:localhost"; const accessToken = "aseukfgwef"; beforeEach(function() { - httpBackend = new HttpBackend(); store = new MemoryStore(); - const mockStorage = new MockStorageApi(); - sessionStore = new sdk.WebStorageSessionStore(mockStorage); - - sdk.request(httpBackend.requestFn); - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - deviceId: "aliceDevice", - accessToken: accessToken, + const testClient = new TestClient(userId, "aliceDevice", accessToken, undefined, { store: store, - sessionStore: sessionStore, }); + httpBackend = testClient.httpBackend; + client = testClient.client; }); afterEach(function() { @@ -303,7 +289,7 @@ describe("MatrixClient", function() { describe("downloadKeys", function() { - if (!sdk.CRYPTO_ENABLED) { + if (!CRYPTO_ENABLED) { return; } diff --git a/spec/integ/matrix-client-opts.spec.js b/spec/integ/matrix-client-opts.spec.js index f1a45effa..128a931c9 100644 --- a/spec/integ/matrix-client-opts.spec.js +++ b/spec/integ/matrix-client-opts.spec.js @@ -1,9 +1,10 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const MatrixClient = sdk.MatrixClient; -const HttpBackend = require("matrix-mock-request"); -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import HttpBackend from "matrix-mock-request"; +import {MatrixClient} from "../../src/matrix"; +import {MatrixScheduler} from "../../src/scheduler"; +import {MemoryStore} from "../../src/store/memory"; describe("MatrixClient opts", function() { const baseUrl = "http://localhost.or.something"; @@ -71,7 +72,7 @@ describe("MatrixClient opts", function() { baseUrl: baseUrl, userId: userId, accessToken: accessToken, - scheduler: new sdk.MatrixScheduler(), + scheduler: new MatrixScheduler(), }); }); @@ -124,7 +125,7 @@ describe("MatrixClient opts", function() { beforeEach(function() { client = new MatrixClient({ request: httpBackend.requestFn, - store: new sdk.MemoryStore(), + store: new MemoryStore(), baseUrl: baseUrl, userId: userId, accessToken: accessToken, diff --git a/spec/integ/matrix-client-retrying.spec.js b/spec/integ/matrix-client-retrying.spec.js index 949f153fc..e79c4e8a2 100644 --- a/spec/integ/matrix-client-retrying.spec.js +++ b/spec/integ/matrix-client-retrying.spec.js @@ -1,12 +1,11 @@ "use strict"; import 'source-map-support/register'; - -const sdk = require("../.."); -const HttpBackend = require("matrix-mock-request"); -const EventStatus = sdk.EventStatus; +import {EventStatus} from "../../src/matrix"; +import {MatrixScheduler} from "../../src/scheduler"; +import {Room} from "../../src/models/room"; +import {TestClient} from "../TestClient"; describe("MatrixClient retrying", function() { - const baseUrl = "http://localhost.or.something"; let client = null; let httpBackend = null; let scheduler; @@ -16,16 +15,17 @@ describe("MatrixClient retrying", function() { let room; beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); - scheduler = new sdk.MatrixScheduler(); - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - scheduler: scheduler, - }); - room = new sdk.Room(roomId); + scheduler = new MatrixScheduler(); + const testClient = new TestClient( + userId, + "DEVICE", + accessToken, + undefined, + {scheduler}, + ); + httpBackend = testClient.httpBackend; + client = testClient.client; + room = new Room(roomId); client.store.storeRoom(room); }); diff --git a/spec/integ/matrix-client-room-timeline.spec.js b/spec/integ/matrix-client-room-timeline.spec.js index 20e0d8d84..a6fe5c51c 100644 --- a/spec/integ/matrix-client-room-timeline.spec.js +++ b/spec/integ/matrix-client-room-timeline.spec.js @@ -1,12 +1,11 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const EventStatus = sdk.EventStatus; -const HttpBackend = require("matrix-mock-request"); -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {EventStatus} from "../../src/models/event"; +import {TestClient} from "../TestClient"; + describe("MatrixClient room timelines", function() { - const baseUrl = "http://localhost.or.something"; let client = null; let httpBackend = null; const userId = "@alice:localhost"; @@ -101,15 +100,17 @@ describe("MatrixClient room timelines", function() { } beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); - client = sdk.createClient({ - baseUrl: baseUrl, - userId: userId, - accessToken: accessToken, - // these tests should work with or without timelineSupport - timelineSupport: true, - }); + // these tests should work with or without timelineSupport + const testClient = new TestClient( + userId, + "DEVICE", + accessToken, + undefined, + {timelineSupport: true}, + ); + httpBackend = testClient.httpBackend; + client = testClient.client; + setNextSyncData(); httpBackend.when("GET", "/pushrules").respond(200, {}); httpBackend.when("POST", "/filter").respond(200, { filter_id: "fid" }); diff --git a/spec/integ/matrix-client-syncing.spec.js b/spec/integ/matrix-client-syncing.spec.js index 9e406ad50..5513ecf54 100644 --- a/spec/integ/matrix-client-syncing.spec.js +++ b/spec/integ/matrix-client-syncing.spec.js @@ -1,13 +1,11 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const HttpBackend = require("matrix-mock-request"); -const utils = require("../test-utils"); -const MatrixEvent = sdk.MatrixEvent; -const EventTimeline = sdk.EventTimeline; +import {MatrixEvent} from "../../src/models/event"; +import {EventTimeline} from "../../src/models/event-timeline"; +import * as utils from "../test-utils"; +import {TestClient} from "../TestClient"; describe("MatrixClient syncing", function() { - const baseUrl = "http://localhost.or.something"; let client = null; let httpBackend = null; const selfUserId = "@alice:localhost"; @@ -20,13 +18,9 @@ describe("MatrixClient syncing", function() { const roomTwo = "!bar:localhost"; beforeEach(function() { - httpBackend = new HttpBackend(); - sdk.request(httpBackend.requestFn); - client = sdk.createClient({ - baseUrl: baseUrl, - userId: selfUserId, - accessToken: selfAccessToken, - }); + const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken); + httpBackend = testClient.httpBackend; + client = testClient.client; httpBackend.when("GET", "/pushrules").respond(200, {}); httpBackend.when("POST", "/filter").respond(200, { filter_id: "a filter id" }); }); diff --git a/spec/integ/megolm-integ.spec.js b/spec/integ/megolm-integ.spec.js index 858568e94..b9f084ee4 100644 --- a/spec/integ/megolm-integ.spec.js +++ b/spec/integ/megolm-integ.spec.js @@ -1,5 +1,6 @@ /* Copyright 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,12 +17,11 @@ limitations under the License. "use strict"; -const anotherjson = require('another-json'); - -const utils = require('../../lib/utils'); -const testUtils = require('../test-utils'); -const TestClient = require('../TestClient').default; -import logger from '../../lib/logger'; +import anotherjson from "another-json"; +import * as utils from "../../src/utils"; +import * as testUtils from "../test-utils"; +import {TestClient} from "../TestClient"; +import {logger} from "../../src/logger"; const ROOM_ID = "!room:id"; diff --git a/spec/olm-loader.js b/spec/olm-loader.js index 25ba6a5a5..b06ecdffc 100644 --- a/spec/olm-loader.js +++ b/spec/olm-loader.js @@ -1,5 +1,6 @@ /* Copyright 2017 Vector creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import logger from '../lib/logger'; +import {logger} from '../src/logger'; // try to load the olm library. try { diff --git a/spec/test-utils.js b/spec/test-utils.js index b18d10ae1..32a68f06a 100644 --- a/spec/test-utils.js +++ b/spec/test-utils.js @@ -2,9 +2,8 @@ // load olm before the sdk if possible import './olm-loader'; -import logger from '../lib/logger'; -import sdk from '..'; -const MatrixEvent = sdk.MatrixEvent; +import {logger} from '../src/logger'; +import {MatrixEvent} from "../src/models/event"; /** * Return a promise that is resolved when the client next emits a @@ -13,7 +12,7 @@ const MatrixEvent = sdk.MatrixEvent; * @param {Number=} count Number of syncs to wait for (default 1) * @return {Promise} Resolves once the client has emitted a SYNCING event */ -module.exports.syncPromise = function(client, count) { +export function syncPromise(client, count) { if (count === undefined) { count = 1; } @@ -24,7 +23,7 @@ module.exports.syncPromise = function(client, count) { const p = new Promise((resolve, reject) => { const cb = (state) => { logger.log(`${Date.now()} syncPromise(${count}): ${state}`); - if (state == 'SYNCING') { + if (state === 'SYNCING') { resolve(); } else { client.once('sync', cb); @@ -34,9 +33,9 @@ module.exports.syncPromise = function(client, count) { }); return p.then(() => { - return module.exports.syncPromise(client, count-1); + return syncPromise(client, count-1); }); -}; +} /** * Create a spy for an object and automatically spy its methods. @@ -44,7 +43,7 @@ module.exports.syncPromise = function(client, count) { * @param {string} name The name of the class * @return {Object} An instantiated object with spied methods/properties. */ -module.exports.mock = function(constr, name) { +export function mock(constr, name) { // Based on // http://eclipsesource.com/blogs/2014/03/27/mocks-in-jasmine-tests/ const HelperConstr = new Function(); // jshint ignore:line @@ -65,7 +64,7 @@ module.exports.mock = function(constr, name) { } } return result; -}; +} /** * Create an Event. @@ -78,7 +77,7 @@ module.exports.mock = function(constr, name) { * @param {boolean} opts.event True to make a MatrixEvent. * @return {Object} a JSON object representing this event. */ -module.exports.mkEvent = function(opts) { +export function mkEvent(opts) { if (!opts.type || !opts.content) { throw new Error("Missing .type or .content =>" + JSON.stringify(opts)); } @@ -97,14 +96,14 @@ module.exports.mkEvent = function(opts) { event.state_key = ""; } return opts.event ? new MatrixEvent(event) : event; -}; +} /** * Create an m.presence event. * @param {Object} opts Values for the presence. * @return {Object|MatrixEvent} The event */ -module.exports.mkPresence = function(opts) { +export function mkPresence(opts) { if (!opts.user) { throw new Error("Missing user"); } @@ -120,7 +119,7 @@ module.exports.mkPresence = function(opts) { }, }; return opts.event ? new MatrixEvent(event) : event; -}; +} /** * Create an m.room.member event. @@ -135,7 +134,7 @@ module.exports.mkPresence = function(opts) { * @param {boolean} opts.event True to make a MatrixEvent. * @return {Object|MatrixEvent} The event */ -module.exports.mkMembership = function(opts) { +export function mkMembership(opts) { opts.type = "m.room.member"; if (!opts.skey) { opts.skey = opts.sender || opts.user; @@ -152,8 +151,8 @@ module.exports.mkMembership = function(opts) { if (opts.url) { opts.content.avatar_url = opts.url; } - return module.exports.mkEvent(opts); -}; + return mkEvent(opts); +} /** * Create an m.room.message event. @@ -164,7 +163,7 @@ module.exports.mkMembership = function(opts) { * @param {boolean} opts.event True to make a MatrixEvent. * @return {Object|MatrixEvent} The event */ -module.exports.mkMessage = function(opts) { +export function mkMessage(opts) { opts.type = "m.room.message"; if (!opts.msg) { opts.msg = "Random->" + Math.random(); @@ -176,8 +175,8 @@ module.exports.mkMessage = function(opts) { msgtype: "m.text", body: opts.msg, }; - return module.exports.mkEvent(opts); -}; + return mkEvent(opts); +} /** @@ -185,10 +184,10 @@ module.exports.mkMessage = function(opts) { * * @constructor */ -module.exports.MockStorageApi = function() { +export function MockStorageApi() { this.data = {}; -}; -module.exports.MockStorageApi.prototype = { +} +MockStorageApi.prototype = { get length() { return Object.keys(this.data).length; }, @@ -213,7 +212,7 @@ module.exports.MockStorageApi.prototype = { * @param {MatrixEvent} event * @returns {Promise} promise which resolves (to `event`) when the event has been decrypted */ -module.exports.awaitDecryption = function(event) { +export function awaitDecryption(event) { if (!event.isBeingDecrypted()) { return Promise.resolve(event); } @@ -226,19 +225,19 @@ module.exports.awaitDecryption = function(event) { resolve(ev); }); }); -}; +} -const HttpResponse = module.exports.HttpResponse = function( +export function HttpResponse( httpLookups, acceptKeepalives, ignoreUnhandledSync, ) { this.httpLookups = httpLookups; this.acceptKeepalives = acceptKeepalives === undefined ? true : acceptKeepalives; this.ignoreUnhandledSync = ignoreUnhandledSync; this.pendingLookup = null; -}; +} -HttpResponse.prototype.request = function HttpResponse( +HttpResponse.prototype.request = function( cb, method, path, qp, data, prefix, ) { if (path === HttpResponse.KEEP_ALIVE_PATH && this.acceptKeepalives) { @@ -351,7 +350,7 @@ HttpResponse.defaultResponses = function(userId) { ]; }; -module.exports.setHttpResponses = function setHttpResponses( +export function setHttpResponses( client, responses, acceptKeepalives, ignoreUnhandledSyncs, ) { const httpResponseObj = new HttpResponse( @@ -367,4 +366,4 @@ module.exports.setHttpResponses = function setHttpResponses( client._http.authedRequestWithPrefix.mockImplementation(httpReq); client._http.requestWithPrefix.mockImplementation(httpReq); client._http.request.mockImplementation(httpReq); -}; +} diff --git a/spec/unit/autodiscovery.spec.js b/spec/unit/autodiscovery.spec.js index 760c03adc..6bdf3cd02 100644 --- a/spec/unit/autodiscovery.spec.js +++ b/spec/unit/autodiscovery.spec.js @@ -1,5 +1,6 @@ /* Copyright 2018 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,12 +17,10 @@ limitations under the License. "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); - -const AutoDiscovery = sdk.AutoDiscovery; import MockHttpBackend from "matrix-mock-request"; - +import * as sdk from "../../src"; +import {AutoDiscovery} from "../../src/autodiscovery"; describe("AutoDiscovery", function() { let httpBackend = null; diff --git a/spec/unit/content-repo.spec.js b/spec/unit/content-repo.spec.js index 70174fc77..d40d40d93 100644 --- a/spec/unit/content-repo.spec.js +++ b/spec/unit/content-repo.spec.js @@ -1,6 +1,6 @@ "use strict"; import 'source-map-support/register'; -const ContentRepo = require("../../lib/content-repo"); +import * as ContentRepo from "../../src/content-repo"; describe("ContentRepo", function() { const baseUrl = "https://my.home.server"; diff --git a/spec/unit/crypto.spec.js b/spec/unit/crypto.spec.js index c449d4624..ac30fd45d 100644 --- a/spec/unit/crypto.spec.js +++ b/spec/unit/crypto.spec.js @@ -1,26 +1,22 @@ import 'source-map-support/register'; import '../olm-loader'; - -import Crypto from '../../lib/crypto'; - -import WebStorageSessionStore from '../../lib/store/session/webstorage'; -import MemoryCryptoStore from '../../lib/crypto/store/memory-crypto-store.js'; -import MockStorageApi from '../MockStorageApi'; -import TestClient from '../TestClient'; -import {MatrixEvent} from '../../lib/models/event'; -import Room from '../../lib/models/room'; -import olmlib from '../../lib/crypto/olmlib'; +import {Crypto} from "../../src/crypto"; +import {WebStorageSessionStore} from "../../src/store/session/webstorage"; +import {MemoryCryptoStore} from "../../src/crypto/store/memory-crypto-store"; +import {MockStorageApi} from "../MockStorageApi"; +import {TestClient} from "../TestClient"; +import {MatrixEvent} from "../../src/models/event"; +import {Room} from "../../src/models/room"; +import * as olmlib from "../../src/crypto/olmlib"; import {sleep} from "../../src/utils"; - -const EventEmitter = require("events").EventEmitter; - -const sdk = require("../.."); +import {EventEmitter} from "events"; +import {CRYPTO_ENABLED} from "../../src/client"; const Olm = global.Olm; describe("Crypto", function() { - if (!sdk.CRYPTO_ENABLED) { + if (!CRYPTO_ENABLED) { return; } diff --git a/spec/unit/crypto/DeviceList.spec.js b/spec/unit/crypto/DeviceList.spec.js index 683187b78..1b92826e8 100644 --- a/spec/unit/crypto/DeviceList.spec.js +++ b/spec/unit/crypto/DeviceList.spec.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd Copyright 2018, 2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,10 +16,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -import DeviceList from '../../../lib/crypto/DeviceList'; -import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js'; -import utils from '../../../lib/utils'; -import logger from '../../../lib/logger'; +import {logger} from "../../../src/logger"; +import * as utils from "../../../src/utils"; +import {MemoryCryptoStore} from "../../../src/crypto/store/memory-crypto-store"; +import {DeviceList} from "../../../src/crypto/DeviceList"; const signedDeviceList = { "failures": {}, diff --git a/spec/unit/crypto/algorithms/megolm.spec.js b/spec/unit/crypto/algorithms/megolm.spec.js index 88beac84f..699e26ceb 100644 --- a/spec/unit/crypto/algorithms/megolm.spec.js +++ b/spec/unit/crypto/algorithms/megolm.spec.js @@ -1,15 +1,13 @@ import '../../../olm-loader'; +import * as algorithms from "../../../../src/crypto/algorithms"; +import {MemoryCryptoStore} from "../../../../src/crypto/store/memory-crypto-store"; +import {MockStorageApi} from "../../../MockStorageApi"; +import * as testUtils from "../../../test-utils"; +import {OlmDevice} from "../../../../src/crypto/OlmDevice"; +import {Crypto} from "../../../../src/crypto"; +import {logger} from "../../../../src/logger"; +import {MatrixEvent} from "../../../../src/models/event"; -import sdk from '../../../..'; -import algorithms from '../../../../lib/crypto/algorithms'; -import MemoryCryptoStore from '../../../../lib/crypto/store/memory-crypto-store.js'; -import MockStorageApi from '../../../MockStorageApi'; -import testUtils from '../../../test-utils'; -import OlmDevice from '../../../../lib/crypto/OlmDevice'; -import Crypto from '../../../../lib/crypto'; -import logger from '../../../../lib/logger'; - -const MatrixEvent = sdk.MatrixEvent; const MegolmDecryption = algorithms.DECRYPTION_CLASSES['m.megolm.v1.aes-sha2']; const MegolmEncryption = algorithms.ENCRYPTION_CLASSES['m.megolm.v1.aes-sha2']; diff --git a/spec/unit/crypto/algorithms/olm.spec.js b/spec/unit/crypto/algorithms/olm.spec.js index e701e2894..889115776 100644 --- a/spec/unit/crypto/algorithms/olm.spec.js +++ b/spec/unit/crypto/algorithms/olm.spec.js @@ -1,5 +1,6 @@ /* Copyright 2018,2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +16,12 @@ limitations under the License. */ import '../../../olm-loader'; - -import MemoryCryptoStore from '../../../../lib/crypto/store/memory-crypto-store.js'; -import MockStorageApi from '../../../MockStorageApi'; -import logger from '../../../../lib/logger'; - -import OlmDevice from '../../../../lib/crypto/OlmDevice'; -import olmlib from '../../../../lib/crypto/olmlib'; -import DeviceInfo from '../../../../lib/crypto/deviceinfo'; +import {MemoryCryptoStore} from "../../../../src/crypto/store/memory-crypto-store"; +import {MockStorageApi} from "../../../MockStorageApi"; +import {logger} from "../../../../src/logger"; +import {OlmDevice} from "../../../../src/crypto/OlmDevice"; +import * as olmlib from "../../../../src/crypto/olmlib"; +import {DeviceInfo} from "../../../../src/crypto/deviceinfo"; function makeOlmDevice() { const mockStorage = new MockStorageApi(); diff --git a/spec/unit/crypto/backup.spec.js b/spec/unit/crypto/backup.spec.js index acba78310..21f273f47 100644 --- a/spec/unit/crypto/backup.spec.js +++ b/spec/unit/crypto/backup.spec.js @@ -1,5 +1,6 @@ /* Copyright 2018 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,23 +16,20 @@ limitations under the License. */ import '../../olm-loader'; - -import sdk from '../../..'; -import algorithms from '../../../lib/crypto/algorithms'; -import WebStorageSessionStore from '../../../lib/store/session/webstorage'; -import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js'; -import MockStorageApi from '../../MockStorageApi'; -import testUtils from '../../test-utils'; - -import OlmDevice from '../../../lib/crypto/OlmDevice'; -import Crypto from '../../../lib/crypto'; -import logger from '../../../lib/logger'; -import olmlib from '../../../lib/crypto/olmlib'; +import {logger} from "../../../src/logger"; +import * as olmlib from "../../../src/crypto/olmlib"; +import {MatrixClient} from "../../../src/client"; +import {MatrixEvent} from "../../../src/models/event"; +import * as algorithms from "../../../src/crypto/algorithms"; +import {WebStorageSessionStore} from "../../../src/store/session/webstorage"; +import {MemoryCryptoStore} from "../../../src/crypto/store/memory-crypto-store"; +import {MockStorageApi} from "../../MockStorageApi"; +import * as testUtils from "../../test-utils"; +import {OlmDevice} from "../../../src/crypto/OlmDevice"; +import {Crypto} from "../../../src/crypto"; const Olm = global.Olm; -const MatrixClient = sdk.MatrixClient; -const MatrixEvent = sdk.MatrixEvent; const MegolmDecryption = algorithms.DECRYPTION_CLASSES['m.megolm.v1.aes-sha2']; const ROOM_ID = '!ROOM:ID'; diff --git a/spec/unit/crypto/cross-signing.spec.js b/spec/unit/crypto/cross-signing.spec.js index a36c3bf70..23ee0ee1b 100644 --- a/spec/unit/crypto/cross-signing.spec.js +++ b/spec/unit/crypto/cross-signing.spec.js @@ -16,13 +16,9 @@ limitations under the License. */ import '../../olm-loader'; - import anotherjson from 'another-json'; - -import olmlib from '../../../lib/crypto/olmlib'; - -import TestClient from '../../TestClient'; - +import * as olmlib from "../../../src/crypto/olmlib"; +import {TestClient} from '../../TestClient'; import {HttpResponse, setHttpResponses} from '../../test-utils'; async function makeTestClient(userInfo, options, keys) { diff --git a/spec/unit/crypto/secrets.spec.js b/spec/unit/crypto/secrets.spec.js index 7c1195aae..254adf0c0 100644 --- a/spec/unit/crypto/secrets.spec.js +++ b/spec/unit/crypto/secrets.spec.js @@ -15,14 +15,11 @@ limitations under the License. */ import '../../olm-loader'; - -import { MatrixEvent } from '../../../lib/models/event'; -import { SECRET_STORAGE_ALGORITHM_V1 } from '../../../lib/crypto/SecretStorage'; - -import olmlib from '../../../lib/crypto/olmlib'; - -import TestClient from '../../TestClient'; -import { makeTestClients } from './verification/util'; +import * as olmlib from "../../../src/crypto/olmlib"; +import {SECRET_STORAGE_ALGORITHM_V1} from "../../../src/crypto/SecretStorage"; +import {MatrixEvent} from "../../../src/models/event"; +import {TestClient} from '../../TestClient'; +import {makeTestClients} from './verification/util'; async function makeTestClient(userInfo, options) { const client = (new TestClient( diff --git a/spec/unit/crypto/verification/qr_code.spec.js b/spec/unit/crypto/verification/qr_code.spec.js index 3c92426b9..9f9a4c8bb 100644 --- a/spec/unit/crypto/verification/qr_code.spec.js +++ b/spec/unit/crypto/verification/qr_code.spec.js @@ -1,5 +1,6 @@ /* Copyright 2018-2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,17 +14,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import logger from '../../../../lib/logger'; - -try { - global.Olm = require('olm'); -} catch (e) { - logger.warn("unable to run device verification tests: libolm not available"); -} - -import DeviceInfo from '../../../../lib/crypto/deviceinfo'; - -import {ShowQRCode, ScanQRCode} from '../../../../lib/crypto/verification/QRCode'; +import "../../../olm-loader"; +import {logger} from "../../../../src/logger"; +import {DeviceInfo} from "../../../../src/crypto/deviceinfo"; +import {ScanQRCode, ShowQRCode} from "../../../../src/crypto/verification/QRCode"; const Olm = global.Olm; diff --git a/spec/unit/crypto/verification/request.spec.js b/spec/unit/crypto/verification/request.spec.js index 99ba0225b..be039824c 100644 --- a/spec/unit/crypto/verification/request.spec.js +++ b/spec/unit/crypto/verification/request.spec.js @@ -1,5 +1,6 @@ /* Copyright 2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,22 +14,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import logger from '../../../../lib/logger'; - -try { - global.Olm = require('olm'); -} catch (e) { - logger.warn("unable to run device verification tests: libolm not available"); -} - -import {verificationMethods} from '../../../../lib/crypto'; - -import SAS from '../../../../lib/crypto/verification/SAS'; +import "../../../olm-loader"; +import {verificationMethods} from "../../../../src/crypto"; +import {logger} from "../../../../src/logger"; +import {SAS} from "../../../../src/crypto/verification/SAS"; +import {makeTestClients} from './util'; const Olm = global.Olm; -import {makeTestClients} from './util'; - describe("verification request", function() { if (!global.Olm) { logger.warn('Not running device verification unit tests: libolm not present'); diff --git a/spec/unit/crypto/verification/sas.spec.js b/spec/unit/crypto/verification/sas.spec.js index aa358dbf9..388737dd3 100644 --- a/spec/unit/crypto/verification/sas.spec.js +++ b/spec/unit/crypto/verification/sas.spec.js @@ -1,5 +1,6 @@ /* Copyright 2018-2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,29 +14,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import logger from '../../../../lib/logger'; - -try { - global.Olm = require('olm'); -} catch (e) { - logger.warn("unable to run device verification tests: libolm not available"); -} - -import olmlib from '../../../../lib/crypto/olmlib'; - -import sdk from '../../../..'; - -import {verificationMethods} from '../../../../lib/crypto'; -import DeviceInfo from '../../../../lib/crypto/deviceinfo'; - -import SAS from '../../../../lib/crypto/verification/SAS'; +import "../../../olm-loader"; +import {makeTestClients} from './util'; +import {MatrixEvent} from "../../../../src/models/event"; +import {SAS} from "../../../../src/crypto/verification/SAS"; +import {DeviceInfo} from "../../../../src/crypto/deviceinfo"; +import {verificationMethods} from "../../../../src/crypto"; +import * as olmlib from "../../../../src/crypto/olmlib"; +import {logger} from "../../../../src/logger"; const Olm = global.Olm; -const MatrixEvent = sdk.MatrixEvent; - -import {makeTestClients} from './util'; - let ALICE_DEVICES; let BOB_DEVICES; diff --git a/spec/unit/crypto/verification/util.js b/spec/unit/crypto/verification/util.js index 53eb1b654..ea1cd81c9 100644 --- a/spec/unit/crypto/verification/util.js +++ b/spec/unit/crypto/verification/util.js @@ -1,5 +1,6 @@ /* Copyright 2019 New Vector Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,10 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import TestClient from '../../../TestClient'; - -import sdk from '../../../..'; -const MatrixEvent = sdk.MatrixEvent; +import {TestClient} from '../../../TestClient'; +import {MatrixEvent} from "../../../../src/models/event"; export async function makeTestClients(userInfos, options) { const clients = []; diff --git a/spec/unit/event-timeline.spec.js b/spec/unit/event-timeline.spec.js index ab4ce9f38..a4fc0ff5e 100644 --- a/spec/unit/event-timeline.spec.js +++ b/spec/unit/event-timeline.spec.js @@ -1,12 +1,12 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const EventTimeline = sdk.EventTimeline; -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {EventTimeline} from "../../src/models/event-timeline"; +import {RoomState} from "../../src/models/room-state"; function mockRoomStates(timeline) { - timeline._startState = utils.mock(sdk.RoomState, "startState"); - timeline._endState = utils.mock(sdk.RoomState, "endState"); + timeline._startState = utils.mock(RoomState, "startState"); + timeline._endState = utils.mock(RoomState, "endState"); } describe("EventTimeline", function() { diff --git a/spec/unit/event.spec.js b/spec/unit/event.spec.js index 225580d81..9b88e7ce9 100644 --- a/spec/unit/event.spec.js +++ b/spec/unit/event.spec.js @@ -1,5 +1,6 @@ /* Copyright 2017 New Vector Ltd +Copyright 2019 The Matrix.org Foundaction C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,10 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import sdk from '../..'; -const MatrixEvent = sdk.MatrixEvent; - -import logger from '../../lib/logger'; +import {logger} from "../../src/logger"; +import {MatrixEvent} from "../../src/models/event"; describe("MatrixEvent", () => { describe(".attemptDecryption", () => { diff --git a/spec/unit/filter.spec.js b/spec/unit/filter.spec.js index ed7722cf8..251495e0a 100644 --- a/spec/unit/filter.spec.js +++ b/spec/unit/filter.spec.js @@ -1,7 +1,6 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const Filter = sdk.Filter; +import {Filter} from "../../src/filter"; describe("Filter", function() { const filterId = "f1lt3ring15g00d4ursoul"; diff --git a/spec/unit/interactive-auth.spec.js b/spec/unit/interactive-auth.spec.js index 0d706da30..c15543be8 100644 --- a/spec/unit/interactive-auth.spec.js +++ b/spec/unit/interactive-auth.spec.js @@ -1,5 +1,6 @@ /* Copyright 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,12 +17,9 @@ limitations under the License. "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); - -const InteractiveAuth = sdk.InteractiveAuth; -const MatrixError = sdk.MatrixError; - -import logger from '../../lib/logger'; +import {logger} from "../../src/logger"; +import {InteractiveAuth} from "../../src/interactive-auth"; +import {MatrixError} from "../../src/http-api"; // Trivial client object to test interactive auth // (we do not need TestClient here) diff --git a/spec/unit/login.spec.js b/spec/unit/login.spec.js index 0a294adc3..32d68f458 100644 --- a/spec/unit/login.spec.js +++ b/spec/unit/login.spec.js @@ -1,4 +1,4 @@ -import TestClient from '../TestClient'; +import {TestClient} from '../TestClient'; describe('Login request', function() { let client; diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index c1726e174..a36371bf5 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -1,9 +1,9 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const MatrixClient = sdk.MatrixClient; -import logger from '../../lib/logger'; +import {logger} from "../../src/logger"; +import {MatrixClient} from "../../src/client"; +import {Filter} from "../../src/filter"; jest.useFakeTimers(); @@ -180,7 +180,7 @@ describe("MatrixClient", function() { httpLookups.push(SYNC_RESPONSE); const filterId = "ehfewf"; store.getFilterIdByName.mockReturnValue(filterId); - const filter = new sdk.Filter(0, filterId); + const filter = new Filter(0, filterId); filter.setDefinition({"room": {"timeline": {"limit": 8}}}); store.getFilter.mockReturnValue(filter); const syncPromise = new Promise((resolve, reject) => { @@ -247,7 +247,7 @@ describe("MatrixClient", function() { const filterName = getFilterName(client.credentials.userId); client.store.setFilterIdByName(filterName, invalidFilterId); - const filter = new sdk.Filter(client.credentials.userId); + const filter = new Filter(client.credentials.userId); client.getOrCreateFilter(filterName, filter).then(function(filterId) { expect(filterId).toEqual(FILTER_RESPONSE.data.filter_id); diff --git a/spec/unit/pushprocessor.spec.js b/spec/unit/pushprocessor.spec.js index 32580dec2..3fcecdb5a 100644 --- a/spec/unit/pushprocessor.spec.js +++ b/spec/unit/pushprocessor.spec.js @@ -1,7 +1,7 @@ "use strict"; import 'source-map-support/register'; -const PushProcessor = require("../../lib/pushprocessor"); -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {PushProcessor} from "../../src/pushprocessor"; describe('NotificationService', function() { const testUserId = "@ali:matrix.org"; diff --git a/spec/unit/realtime-callbacks.spec.js b/spec/unit/realtime-callbacks.spec.js index 70510b26a..712818c04 100644 --- a/spec/unit/realtime-callbacks.spec.js +++ b/spec/unit/realtime-callbacks.spec.js @@ -1,7 +1,7 @@ "use strict"; import 'source-map-support/register'; -const callbacks = require("../../src/realtime-callbacks"); +import * as callbacks from "../../src/realtime-callbacks"; let wallTime = 1234567890; jest.useFakeTimers(); diff --git a/spec/unit/room-member.spec.js b/spec/unit/room-member.spec.js index 9c7a8ee32..8ab78583c 100644 --- a/spec/unit/room-member.spec.js +++ b/spec/unit/room-member.spec.js @@ -1,8 +1,7 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const RoomMember = sdk.RoomMember; -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {RoomMember} from "../../src/models/room-member"; describe("RoomMember", function() { const roomId = "!foo:bar"; diff --git a/spec/unit/room-state.spec.js b/spec/unit/room-state.spec.js index 87aedaf79..c5a0a1745 100644 --- a/spec/unit/room-state.spec.js +++ b/spec/unit/room-state.spec.js @@ -1,9 +1,8 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const RoomState = sdk.RoomState; -const RoomMember = sdk.RoomMember; -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {RoomState} from "../../src/models/room-state"; +import {RoomMember} from "../../src/models/room-member"; describe("RoomState", function() { const roomId = "!foo:bar"; diff --git a/spec/unit/room.spec.js b/spec/unit/room.spec.js index 58cf2fd01..ff1880708 100644 --- a/spec/unit/room.spec.js +++ b/spec/unit/room.spec.js @@ -1,12 +1,10 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const Room = sdk.Room; -const RoomState = sdk.RoomState; -const MatrixEvent = sdk.MatrixEvent; -const EventStatus = sdk.EventStatus; -const EventTimeline = sdk.EventTimeline; -const utils = require("../test-utils"); +import * as utils from "../test-utils"; +import {EventStatus, MatrixEvent} from "../../src/models/event"; +import {EventTimeline} from "../../src/models/event-timeline"; +import {RoomState} from "../../src/models/room-state"; +import {Room} from "../../src/models/room"; describe("Room", function() { const roomId = "!foo:bar"; @@ -20,9 +18,9 @@ describe("Room", function() { room = new Room(roomId); // mock RoomStates room.oldState = room.getLiveTimeline()._startState = - utils.mock(sdk.RoomState, "oldState"); + utils.mock(RoomState, "oldState"); room.currentState = room.getLiveTimeline()._endState = - utils.mock(sdk.RoomState, "currentState"); + utils.mock(RoomState, "currentState"); }); describe("getAvatarUrl", function() { diff --git a/spec/unit/scheduler.spec.js b/spec/unit/scheduler.spec.js index d45e77bab..6ecb38c85 100644 --- a/spec/unit/scheduler.spec.js +++ b/spec/unit/scheduler.spec.js @@ -3,10 +3,9 @@ import 'source-map-support/register'; import {defer} from '../../src/utils'; -const sdk = require("../.."); -const MatrixScheduler = sdk.MatrixScheduler; -const MatrixError = sdk.MatrixError; -const utils = require("../test-utils"); +import {MatrixError} from "../../src/http-api"; +import {MatrixScheduler} from "../../src/scheduler"; +import * as utils from "../test-utils"; jest.useFakeTimers(); diff --git a/spec/unit/sync-accumulator.spec.js b/spec/unit/sync-accumulator.spec.js index 6dfd76043..1cdc88214 100644 --- a/spec/unit/sync-accumulator.spec.js +++ b/spec/unit/sync-accumulator.spec.js @@ -1,5 +1,6 @@ /* Copyright 2017 Vector Creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,9 +17,8 @@ limitations under the License. "use strict"; import 'source-map-support/register'; -import sdk from "../.."; -const SyncAccumulator = sdk.SyncAccumulator; +import {SyncAccumulator} from "../../src/sync-accumulator"; describe("SyncAccumulator", function() { let sa; diff --git a/spec/unit/timeline-window.spec.js b/spec/unit/timeline-window.spec.js index 2de036370..2916cfba8 100644 --- a/spec/unit/timeline-window.spec.js +++ b/spec/unit/timeline-window.spec.js @@ -1,11 +1,8 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const EventTimeline = sdk.EventTimeline; -const TimelineWindow = sdk.TimelineWindow; -const TimelineIndex = require("../../lib/timeline-window").TimelineIndex; - -const utils = require("../test-utils"); +import {EventTimeline} from "../../src/models/event-timeline"; +import {TimelineIndex, TimelineWindow} from "../../src/timeline-window"; +import * as utils from "../test-utils"; const ROOM_ID = "roomId"; const USER_ID = "userId"; diff --git a/spec/unit/user.spec.js b/spec/unit/user.spec.js index 8cea9c03d..6f20eb0dd 100644 --- a/spec/unit/user.spec.js +++ b/spec/unit/user.spec.js @@ -1,8 +1,7 @@ "use strict"; import 'source-map-support/register'; -const sdk = require("../.."); -const User = sdk.User; -const utils = require("../test-utils"); +import {User} from "../../src/models/user"; +import * as utils from "../test-utils"; describe("User", function() { const userId = "@alice:bar"; diff --git a/spec/unit/utils.spec.js b/spec/unit/utils.spec.js index c52d00d2b..83ddcf184 100644 --- a/spec/unit/utils.spec.js +++ b/spec/unit/utils.spec.js @@ -1,6 +1,6 @@ "use strict"; import 'source-map-support/register'; -const utils = require("../../lib/utils"); +import * as utils from "../../src/utils"; describe("utils", function() { describe("encodeParams", function() {