Merge pull request #3823 from matrix-org/travis/sm-fix-tests

Fix tests for sourcemaps branch
This commit is contained in:
Travis Ralston 2020-01-09 17:38:21 -07:00 committed by GitHub
commit 4c3703a5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 870 additions and 1132 deletions

10
__mocks__/languages.json Normal file
View File

@ -0,0 +1,10 @@
{
"en": {
"fileName": "en_EN.json",
"label": "English"
},
"en-us": {
"fileName": "en_US.json",
"label": "English (US)"
}
}

View File

@ -1,4 +1,4 @@
{
module.exports = {
"sourceMaps": "inline",
"presets": [
["@babel/preset-env", {
@ -23,4 +23,4 @@
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-runtime"
]
}
};

View File

@ -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",
@ -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",
@ -147,7 +148,6 @@
"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",
@ -155,10 +155,16 @@
"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).+$"
]
}
}

View File

@ -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(

View File

@ -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");
@ -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,
@ -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,
@ -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",
@ -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",
@ -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",
@ -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",
@ -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",
@ -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 = {

View File

@ -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';

View File

@ -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();
@ -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;

View File

@ -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';

View File

@ -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();

View File

@ -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,

1893
yarn.lock

File diff suppressed because it is too large Load Diff