Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix tests for sourcemaps branch #3823

Merged
merged 9 commits into from
Jan 10, 2020
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
10 changes: 10 additions & 0 deletions __mocks__/languages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"en": {
"fileName": "en_EN.json",
"label": "English"
},
"en-us": {
"fileName": "en_US.json",
"label": "English (US)"
}
}
4 changes: 2 additions & 2 deletions .babelrc → babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"sourceMaps": "inline",
"presets": [
["@babel/preset-env", {
Expand All @@ -23,4 +23,4 @@
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-runtime"
]
}
};
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@
"@babel/preset-typescript": "^7.7.4",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.7.6",
"@peculiar/webcrypto": "^1.0.22",
"babel-eslint": "^10.0.3",
"babel-jest": "^23.6.0",
"babel-jest": "^24.9.0",
"chokidar": "^2.1.2",
"concurrently": "^4.0.1",
"enzyme": "^3.10.0",
Expand All @@ -137,7 +138,7 @@
"estree-walker": "^0.5.0",
"file-loader": "^3.0.1",
"flow-parser": "^0.57.3",
"jest": "^23.2.0",
"jest": "^24.9.0",
"matrix-mock-request": "^1.2.3",
"matrix-react-test-utils": "^0.2.2",
"react-test-renderer": "^16.9.0",
Expand All @@ -147,18 +148,23 @@
"stylelint": "^9.10.1",
"stylelint-config-standard": "^18.2.0",
"stylelint-scss": "^3.9.0",
"subtle": "^0.1.8",
"tslint": "^5.20.1",
"typescript": "^3.7.3",
"walk": "^2.3.9",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1"
},
"jest": {
"testMatch": ["<rootDir>/test/**/*-test.js"],
"testMatch": [
"<rootDir>/test/**/*-test.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/test/setupTests.js",
"moduleNameMapper": {
"\\.(gif|png|svg|ttf|woff2)$": "<rootDir>/__mocks__/imageMock.js"
}
"\\.(gif|png|svg|ttf|woff2)$": "<rootDir>/__mocks__/imageMock.js",
"\\$webapp/i18n/languages.json": "<rootDir>/__mocks__/languages.json"
},
"transformIgnorePatterns": [
"/node_modules/(?!matrix-js-sdk).+$"
]
}
}
4 changes: 2 additions & 2 deletions src/languageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ export function pickBestLanguage(langs) {
function getLangsJson() {
return new Promise(async (resolve, reject) => {
let url;
try {
if (typeof(webpackLangJsonUrl) === 'string') { // in Jest this 'url' isn't a URL, so just fall through
url = webpackLangJsonUrl;
} catch (e) {
} else {
url = i18nFolder + 'languages.json';
}
request(
Expand Down
46 changes: 25 additions & 21 deletions test/components/views/messages/TextualBody-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { configure, mount } from "enzyme";

import sdk from "../../../skinned-sdk";
import {mkEvent, mkStubRoom} from "../../../test-utils";
import MatrixClientPeg from "../../../../src/MatrixClientPeg";
import {MatrixClientPeg} from "../../../../src/MatrixClientPeg";
import * as languageHandler from "../../../../src/languageHandler";

const TextualBody = sdk.getComponent("views.messages.TextualBody");
Expand All @@ -33,7 +33,7 @@ describe("<TextualBody />", () => {
MatrixClientPeg.matrixClient = null;
});

describe("renders m.emote correctly", () => {
it("renders m.emote correctly", () => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
Expand All @@ -56,7 +56,7 @@ describe("<TextualBody />", () => {
expect(content.html()).toBe('<span class="mx_EventTile_body" dir="auto">winks</span>');
});

describe("renders m.notice correctly", () => {
it("renders m.notice correctly", () => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
Expand All @@ -80,12 +80,14 @@ describe("<TextualBody />", () => {
});

describe("renders plain-text m.text correctly", () => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
};
beforeEach(() => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
};
});

describe("simple message renders as expected", () => {
it("simple message renders as expected", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
Expand All @@ -104,7 +106,7 @@ describe("<TextualBody />", () => {
});

// If pills were rendered within a Portal/same shadow DOM then it'd be easier to test
describe("linkification get applied correctly into the DOM", () => {
it("linkification get applied correctly into the DOM", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
Expand All @@ -126,16 +128,18 @@ describe("<TextualBody />", () => {
});

describe("renders formatted m.text correctly", () => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
getUserId: () => "@me:my_server",
getHomeserverUrl: () => "https://my_server/",
on: () => undefined,
removeListener: () => undefined,
};
beforeEach(() => {
MatrixClientPeg.matrixClient = {
getRoom: () => mkStubRoom("room_id"),
getAccountData: () => undefined,
getUserId: () => "@me:my_server",
getHomeserverUrl: () => "https://my_server/",
on: () => undefined,
removeListener: () => undefined,
};
});

describe("italics, bold, underline and strikethrough render as expected", () => {
it("italics, bold, underline and strikethrough render as expected", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
Expand All @@ -156,7 +160,7 @@ describe("<TextualBody />", () => {
ev.getContent().formatted_body + '</span>');
});

describe("spoilers get injected properly into the DOM", () => {
it("spoilers get injected properly into the DOM", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
Expand All @@ -182,7 +186,7 @@ describe("<TextualBody />", () => {
});

// If pills were rendered within a Portal/same shadow DOM then it'd be easier to test
describe("pills get injected correctly into the DOM", () => {
it("pills get injected correctly into the DOM", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
Expand All @@ -208,7 +212,7 @@ describe("<TextualBody />", () => {
});
});

describe("renders url previews correctly", () => {
it("renders url previews correctly", () => {
languageHandler.setMissingEntryGenerator(key => key.split('|', 2)[1]);

MatrixClientPeg.matrixClient = {
Expand Down
2 changes: 1 addition & 1 deletion test/components/views/rooms/RoomSettings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';
import jest from 'jest-mock';
import * as testUtils from '../../../test-utils';
import sdk from '../../../skinned-sdk';
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
import {MatrixClientPeg} from '../../../../src/MatrixClientPeg';
import SettingsStore from '../../../../src/settings/SettingsStore';


Expand Down
16 changes: 5 additions & 11 deletions test/skinned-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
* app to provide
*/

// for ES6 stuff like startsWith() and Object.values() that babel doesn't do by
// default
require('babel-polyfill');
import * as sdk from "../src/index";
import stubComponent from "./components/stub-component";

const sdk = require("../src/index");

const skin = require('../src/component-index.js');
const stubComponent = require('./components/stub-component.js');

const components = skin.components;
const components = {};
components['structures.LeftPanel'] = stubComponent();
components['structures.RightPanel'] = stubComponent();
components['structures.RoomDirectory'] = stubComponent();
Expand All @@ -31,6 +25,6 @@ components['views.messages.MessageTimestamp'] = stubComponent({displayName: 'Mes
components['views.messages.SenderProfile'] = stubComponent({displayName: 'SenderProfile'});
components['views.rooms.SearchBar'] = stubComponent();

sdk.loadSkin(skin);
sdk.loadSkin({components});

module.exports = sdk;
export default sdk;
2 changes: 1 addition & 1 deletion test/stores/RoomViewStore-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RoomViewStore from '../../src/stores/RoomViewStore';

import peg from '../../src/MatrixClientPeg';
import {MatrixClientPeg as peg} from '../../src/MatrixClientPeg';

import * as testUtils from '../test-utils';

Expand Down
5 changes: 2 additions & 3 deletions test/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use strict";

import React from 'react';
import peg from '../src/MatrixClientPeg';
import {MatrixClientPeg as peg} from '../src/MatrixClientPeg';
import dis from '../src/dispatcher';
import jssdk from 'matrix-js-sdk';
import {makeType} from "../src/utils/TypeUtils";
import {ValidatedServerConfig} from "../src/utils/AutoDiscoveryUtils";
import ShallowRenderer from 'react-test-renderer/shallow';
import MatrixClientContext from "../src/contexts/MatrixClientContext";
const MatrixEvent = jssdk.MatrixEvent;
import {MatrixEvent} from "matrix-js-sdk/src/models/event";

export function getRenderer() {
// Old: ReactTestUtils.createRenderer();
Expand Down
2 changes: 1 addition & 1 deletion test/utils/permalinks/Permalinks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import peg from '../../../src/MatrixClientPeg';
import {MatrixClientPeg as peg} from '../../../src/MatrixClientPeg';
import {
makeGroupPermalink,
makeRoomPermalink,
Expand Down
Loading