Skip to content

Commit

Permalink
Add typescript support and fix tests after threads work (#19247)
Browse files Browse the repository at this point in the history
* Typescriptify tests
* Fix tests after threads work
* Add proper types for jest
  • Loading branch information
Palid authored Oct 1, 2021
1 parent fe9d018 commit 4efa0b2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 18 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@principalstudio/html-webpack-inject-preload": "^1.2.7",
"@types/flux": "^3.1.9",
"@types/jest": "^27.0.2",
"@types/modernizr": "^3.5.3",
"@types/node": "^14.14.22",
"@types/react": "17.0.14",
Expand Down Expand Up @@ -166,7 +167,7 @@
"jest": {
"testEnvironment": "jest-environment-jsdom-sixteen",
"testMatch": [
"<rootDir>/test/**/*-test.[tj]s"
"<rootDir>/test/**/*-test.[tj]s?(x)"
],
"setupFilesAfterEnv": [
"<rootDir>/node_modules/matrix-react-sdk/test/setupTests.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import {sleep} from "../test-utils";
import * as test_utils from "../test-utils";
import MockHttpBackend from "matrix-mock-request";
import "fake-indexeddb/auto";
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';


const MatrixChat = sdk.getComponent('structures.MatrixChat');
const RoomDirectory = sdk.getComponent('structures.RoomDirectory');
const RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar');
const RoomView = sdk.getComponent('structures.RoomView');

const HS_URL='http://localhost';
const IS_URL='http://localhost';
Expand All @@ -50,7 +50,6 @@ describe('joining a room', function() {
let matrixChat;

beforeEach(function() {
test_utils.beforeEach(this);
httpBackend = new MockHttpBackend();
jssdk.request(httpBackend.requestFn);
parentDiv = document.createElement('div');
Expand Down Expand Up @@ -148,7 +147,7 @@ describe('joining a room', function() {

// enter an alias in the input, and simulate enter
const input = ReactTestUtils.findRenderedDOMComponentWithTag(
roomDir, 'input');
roomDir, 'input') as HTMLInputElement;
input.value = ROOM_ALIAS;
ReactTestUtils.Simulate.change(input);
ReactTestUtils.Simulate.keyUp(input, {key: 'Enter'});
Expand All @@ -165,7 +164,7 @@ describe('joining a room', function() {

// we should now have a roomview
roomView = ReactTestUtils.findRenderedComponentWithType(
matrixChat, RoomView);
matrixChat, RoomViewClass);

// the preview bar may take a tick to be displayed
return sleep(1);
Expand Down Expand Up @@ -228,7 +227,7 @@ describe('joining a room', function() {
return httpBackend.flush();
}).then(() => {
// now the room should have loaded
expect(roomView.state.room).toExist();
expect(roomView.state.room).toBeTruthy();
});
});
});
Expand Down
20 changes: 11 additions & 9 deletions test/app-tests/loading-test.js → test/app-tests/loading-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {sleep} from "../test-utils";
import "fake-indexeddb/auto";
import {cleanLocalstorage} from "../test-utils";
import {IndexedDBCryptoStore} from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';
import LoginComponent from 'matrix-react-sdk/src/components/structures/auth/Login';

const DEFAULT_HS_URL='http://my_server';
const DEFAULT_IS_URL='http://my_is';
Expand Down Expand Up @@ -94,7 +96,7 @@ describe('loading:', function() {
* TODO: it would be nice to factor some of this stuff out of index.js so
* that we can test it rather than our own implementation of it.
*/
function loadApp(opts) {
function loadApp(opts?) {
opts = opts || {};
const queryString = opts.queryString || "";
const uriFragment = opts.uriFragment || "";
Expand Down Expand Up @@ -164,7 +166,7 @@ describe('loading:', function() {
// http requests until we do.
//
// returns a promise resolving to the received request
async function expectAndAwaitSync(opts) {
async function expectAndAwaitSync(opts?) {
let syncRequest = null;
const isGuest = opts && opts.isGuest;
if (!isGuest) {
Expand Down Expand Up @@ -633,7 +635,7 @@ describe('loading:', function() {
async function completeLogin(matrixChat) {
// we expect a single <Login> component
const login = ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.auth.Login'));
matrixChat, LoginComponent);

// When we switch to the login component, it'll hit the login endpoint
// for proof of life and to get flows. We'll only give it one option.
Expand Down Expand Up @@ -673,7 +675,7 @@ describe('loading:', function() {

// assert that we are on the loading page
function assertAtLoadingSpinner(matrixChat) {
const domComponent = ReactDOM.findDOMNode(matrixChat);
const domComponent = ReactDOM.findDOMNode(matrixChat) as Element;
expect(domComponent.className).toEqual("mx_MatrixChat_splash");

// just the spinner
Expand All @@ -691,14 +693,14 @@ function awaitLoggedIn(matrixChat) {
}
console.log(Date.now() + ": Received on_logged_in action");
dis.unregister(dispatcherRef);
resolve();
resolve(undefined);
};
const dispatcherRef = dis.register(onAction);
console.log(Date.now() + ": Waiting for on_logged_in action");
});
}

function awaitRoomView(matrixChat, retryLimit, retryCount) {
function awaitRoomView(matrixChat, retryLimit?, retryCount?) {
if (retryLimit === undefined) {
retryLimit = 5;
}
Expand All @@ -721,17 +723,17 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {

// state looks good, check the rendered output
ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.RoomView'));
matrixChat, RoomViewClass);
return Promise.resolve();
}

function awaitLoginComponent(matrixChat, attempts) {
function awaitLoginComponent(matrixChat, attempts?) {
return MatrixReactTestUtils.waitForRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.auth.Login'), attempts,
);
}

function awaitWelcomeComponent(matrixChat, attempts) {
function awaitWelcomeComponent(matrixChat, attempts?) {
return MatrixReactTestUtils.waitForRenderedComponentWithType(
matrixChat, sdk.getComponent('auth.Welcome'), attempts,
);
Expand Down
65 changes: 62 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,17 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"

"@jest/types@^27.2.4":
version "27.2.4"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.2.4.tgz#2430042a66e00dc5b140c3636f4474d464c21ee8"
integrity sha512-IDO2ezTxeMvQAHxzG/ZvEyA47q0aVfzT95rGFl7bZs/Go0aIucvfDbS2rmnoEdXxlLQhcolmoG/wvL/uKx4tKA==
dependencies:
"@types/istanbul-lib-coverage" "^2.0.0"
"@types/istanbul-reports" "^3.0.0"
"@types/node" "*"
"@types/yargs" "^16.0.0"
chalk "^4.0.0"

"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz":
version "3.2.3"
resolved "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz#cc332fdd25c08ef0e40f4d33fc3f822a0f98b6f4"
Expand Down Expand Up @@ -1652,6 +1663,14 @@
dependencies:
"@types/istanbul-lib-report" "*"

"@types/jest@^27.0.2":
version "27.0.2"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7"
integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==
dependencies:
jest-diff "^27.0.0"
pretty-format "^27.0.0"

"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
Expand Down Expand Up @@ -1822,6 +1841,13 @@
dependencies:
"@types/yargs-parser" "*"

"@types/yargs@^16.0.0":
version "16.0.4"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-16.0.4.tgz#26aad98dd2c2a38e421086ea9ad42b9e51642977"
integrity sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^4.17.0":
version "4.31.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.1.tgz#e938603a136f01dcabeece069da5fb2e331d4498"
Expand Down Expand Up @@ -2193,7 +2219,7 @@ ansi-regex@^4.1.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==

ansi-regex@^5.0.0:
ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
Expand All @@ -2217,6 +2243,11 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0:
dependencies:
color-convert "^2.0.1"

ansi-styles@^5.0.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b"
integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==

anymatch@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
Expand Down Expand Up @@ -4115,6 +4146,11 @@ diff-sequences@^26.6.2:
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-26.6.2.tgz#48ba99157de1923412eed41db6b6d4aa9ca7c0b1"
integrity sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==

diff-sequences@^27.0.6:
version "27.0.6"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.6.tgz#3305cb2e55a033924054695cc66019fd7f8e5723"
integrity sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==

diffie-hellman@^5.0.0:
version "5.0.3"
resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875"
Expand Down Expand Up @@ -6867,6 +6903,16 @@ jest-diff@^26.6.2:
jest-get-type "^26.3.0"
pretty-format "^26.6.2"

jest-diff@^27.0.0:
version "27.2.4"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.2.4.tgz#171c51d3d2c105c457100fee6e7bf7cee51c8d8c"
integrity sha512-bLAVlDSCR3gqUPGv+4nzVpEXGsHh98HjUL7Vb2hVyyuBDoQmja8eJb0imUABsuxBeUVmf47taJSAd9nDrwWKEg==
dependencies:
chalk "^4.0.0"
diff-sequences "^27.0.6"
jest-get-type "^27.0.6"
pretty-format "^27.2.4"

jest-docblock@^26.0.0:
version "26.0.0"
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-26.0.0.tgz#3e2fa20899fc928cb13bd0ff68bd3711a36889b5"
Expand Down Expand Up @@ -6925,6 +6971,11 @@ jest-get-type@^26.3.0:
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0"
integrity sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==

jest-get-type@^27.0.6:
version "27.0.6"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.0.6.tgz#0eb5c7f755854279ce9b68a9f1a4122f69047cfe"
integrity sha512-XTkK5exIeUbbveehcSR8w0bhH+c0yloW/Wpl+9vZrjzztCPWrxhHwkIFpZzCt71oRBsgxmuUfxEqOYoZI2macg==

jest-haste-map@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-26.6.2.tgz#dd7e60fe7dc0e9f911a23d79c5ff7fb5c2cafeaa"
Expand Down Expand Up @@ -9780,6 +9831,16 @@ pretty-format@^26.6.2:
ansi-styles "^4.0.0"
react-is "^17.0.1"

pretty-format@^27.0.0, pretty-format@^27.2.4:
version "27.2.4"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.2.4.tgz#08ea39c5eab41b082852d7093059a091f6ddc748"
integrity sha512-NUjw22WJHldzxyps2YjLZkUj6q1HvjqFezkB9Y2cklN8NtVZN/kZEXGZdFw4uny3oENzV5EEMESrkI0YDUH8vg==
dependencies:
"@jest/types" "^27.2.4"
ansi-regex "^5.0.1"
ansi-styles "^5.0.0"
react-is "^17.0.1"

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down Expand Up @@ -12204,10 +12265,8 @@ watchpack@^1.7.4:
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453"
integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ==
dependencies:
chokidar "^3.4.1"
graceful-fs "^4.1.2"
neo-async "^2.5.0"
watchpack-chokidar2 "^2.0.1"
optionalDependencies:
chokidar "^3.4.1"
watchpack-chokidar2 "^2.0.1"
Expand Down

0 comments on commit 4efa0b2

Please sign in to comment.