From 17dd0aa1739e9eb0e451b5b19bf3d10352be416d Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Thu, 24 Feb 2022 14:46:15 +0000 Subject: [PATCH] Fix the test script `yarn test:manual` and add it to tsconfig (#234) * Add test:manual launch script to tsconfig this is so we won't keep breaking it --- package.json | 1 + test/integration/clientHelper.ts | 10 +++++----- test/integration/mjolnirSetupUtils.ts | 6 +++--- tsconfig.json | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 174f8bdc..2ab9a2a3 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "private": true, "scripts": { "build": "tsc", + "postbuild": "rm -rf lib/test/ && cp -r lib/src/* lib/ && rm -rf lib/src/", "lint": "tslint --project ./tsconfig.json -t stylish", "start:dev": "yarn build && node --async-stack-traces lib/index.js", "test": "ts-mocha --project ./tsconfig.json test/commands/**/*.ts", diff --git a/test/integration/clientHelper.ts b/test/integration/clientHelper.ts index bf6902f7..7b38900e 100644 --- a/test/integration/clientHelper.ts +++ b/test/integration/clientHelper.ts @@ -19,7 +19,7 @@ const REGISTRATION_RETRY_BASE_DELAY_MS = 100; export async function registerUser(username: string, displayname: string, password: string, admin: boolean): Promise { let registerUrl = `${config.homeserverUrl}/_synapse/admin/v1/register` const data: {nonce: string} = await new Promise((resolve, reject) => { - getRequestFn()({uri: registerUrl, method: "GET", timeout: 60000}, (error, response, resBody) => { + getRequestFn()({uri: registerUrl, method: "GET", timeout: 60000}, (error: any, response: any, resBody: any) => { error ? reject(error) : resolve(JSON.parse(resBody)) }); }); @@ -42,7 +42,7 @@ export async function registerUser(username: string, displayname: string, passwo timeout: 60000 } return await new Promise((resolve, reject) => { - getRequestFn()(params, error => error ? reject(error) : resolve()); + getRequestFn()(params, (error: any) => error ? reject(error) : resolve()); }); } catch (ex) { // In case of timeout or throttling, backoff and retry. @@ -79,7 +79,7 @@ export type RegistrationOptions = { /** * Register a new test user. * - * @returns A string that is both the username and password of a new user. + * @returns A string that is both the username and password of a new user. */ async function registerNewTestUser(options: RegistrationOptions) { do { @@ -174,8 +174,8 @@ export async function resetRatelimitForUser(userId: string) { * @param cb The callback when a m.notice event is found in targetRoomId. * @returns The callback to pass to `MatrixClient.on('room.message', cb)` */ -export function noticeListener(targetRoomdId: string, cb) { - return (roomId, event) => { +export function noticeListener(targetRoomdId: string, cb: (event: any) => void) { + return (roomId: string, event: any) => { if (roomId !== targetRoomdId) return; if (event?.content?.msgtype !== "m.notice") return; cb(event); diff --git a/test/integration/mjolnirSetupUtils.ts b/test/integration/mjolnirSetupUtils.ts index bf7c9246..2a4939bb 100644 --- a/test/integration/mjolnirSetupUtils.ts +++ b/test/integration/mjolnirSetupUtils.ts @@ -82,10 +82,10 @@ export async function makeMjolnir(): Promise { await overrideRatelimitForUser(await client.getUserId()); patchMatrixClient(); await ensureAliasedRoomExists(client, config.managementRoom); - let mjolnir = await Mjolnir.setupMjolnirFromConfig(client); + let mj = await Mjolnir.setupMjolnirFromConfig(client); globalClient = client; - globalMjolnir = mjolnir; - return mjolnir; + globalMjolnir = mj; + return mj; } /** diff --git a/tsconfig.json b/tsconfig.json index 79ca60af..a6e9d291 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,6 +19,7 @@ ] }, "include": [ - "./src/**/*" + "./src/**/*", + "./test/integration/manualLaunchScript.ts" ] }