Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-focus sourcemap generation #1126

Merged
merged 7 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sourceMaps": "inline",
"sourceMaps": true,
"presets": [
["@babel/preset-env", {
"targets": {
Expand Down
1 change: 0 additions & 1 deletion .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ steps:
- label: ":jest: Tests"
command:
- "yarn install"
- "yarn build" # Needed for the tests to run - we don't build on install
- "yarn test"
plugins:
- docker#v3.0.1:
Expand Down
11 changes: 9 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ minutes.
Code style
~~~~~~~~~~

The code-style for matrix-js-sdk is not formally documented, but contributors
are encouraged to read the code style document for matrix-react-sdk
The js-sdk aims to target TypeScript/ES6. All new files should be written in
TypeScript and existing files should use ES6 principles where possible.

Members should not be exported as a default export - this is to prevent problems
down the line when importing various bits of code in other layers and in the
index for this project. In short, don't use `export default`.

The remaining code-style for matrix-js-sdk is not formally documented, but
contributors are encouraged to read the code style document for matrix-react-sdk
(`<https://github.com/matrix-org/matrix-react-sdk/blob/master/code_style.md>`_)
and follow the principles set out there.

Expand Down
6 changes: 0 additions & 6 deletions index.js

This file was deleted.

20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "yarn clean && git rev-parse HEAD > git-revision.txt && yarn build:compile && yarn build:compile-browser && yarn build:types",
"build:types": "tsc --emitDeclarationOnly",
"build:compile": "babel src -s -d lib --verbose --extensions \".ts,.js\"",
"build:compile-browser": "mkdirp dist && browserify -d browser-index.js -t [ babelify --sourceMaps=inline ] > dist/browser-matrix.js",
"build:compile-browser": "mkdirp dist && browserify -d src/browser-index.js -p [ tsify -p ./tsconfig.json ] -t [ babelify --sourceMaps=inline ] > dist/browser-matrix.js",
"gendoc": "jsdoc -c jsdoc.json -P package.json",
"lint": "yarn lint:types && yarn lint:ts && yarn lint:js",
"lint:js": "eslint --max-warnings 93 src spec",
Expand All @@ -24,22 +24,20 @@
"keywords": [
"matrix-org"
],
"main": "./index.js",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"browser": "browser-index.js",
"browser": "./lib/browser-index.js",
"author": "matrix.org",
"license": "Apache-2.0",
"files": [
"lib",
"dist",
"git-revision.txt",
"CHANGELOG.md",
"CONTRIBUTING.rst",
"LICENSE",
"README.md",
"git-revision.txt",
"index.js",
"browser-index.js",
"lib",
"package.json",
"src"
"package.json"
],
"dependencies": {
"another-json": "^0.2.0",
Expand Down Expand Up @@ -79,7 +77,11 @@
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
"rimraf": "^3.0.0",
"source-map-support": "^0.5.13",
"tsify": "^4.0.1",
"tslint": "^5.20.1",
"typescript": "^3.7.3"
},
"jest": {
"testEnvironment": "node"
}
}
5 changes: 2 additions & 3 deletions spec/MockStorageApi.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -52,5 +53,3 @@ MockStorageApi.prototype = {
},
};

/** */
module.exports = MockStorageApi;
22 changes: 12 additions & 10 deletions spec/TestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -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 = {};
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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`);
});
Expand Down
7 changes: 4 additions & 3 deletions spec/integ/devicelist-integ-spec.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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";

Expand Down
13 changes: 7 additions & 6 deletions spec/integ/matrix-client-crypto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -400,7 +401,7 @@ function firstSync(testClient) {


describe("MatrixClient crypto", function() {
if (!sdk.CRYPTO_ENABLED) {
if (!CRYPTO_ENABLED) {
return;
}

Expand Down
16 changes: 5 additions & 11 deletions spec/integ/matrix-client-event-emitter.spec.js
Original file line number Diff line number Diff line change
@@ -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" });
});
Expand Down
60 changes: 26 additions & 34 deletions spec/integ/matrix-client-event-timeline.spec.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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() {
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
});
Expand Down
Loading