Skip to content

Commit e235100

Browse files
authored
Fix flaky jest tests (#29927)
* Debug flaky jest test Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Discard changes to jest.config.ts --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 10757b4 commit e235100

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/Lifecycle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,9 @@ export async function onLoggedOut(): Promise<void> {
11151115
* @param {object} opts Options for how to clear storage.
11161116
* @returns {Promise} promise which resolves once the stores have been cleared
11171117
*/
1118-
async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void> {
1118+
export async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void> {
1119+
logger.info(`Clearing storage, deleteEverything=${opts?.deleteEverything}`);
1120+
11191121
if (window.localStorage) {
11201122
// get the currently defined device language, if set, so we can restore it later
11211123
const language = SettingsStore.getValueAt(SettingLevel.DEVICE, "language", null, true, true);

src/utils/StorageManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ export async function checkConsistency(): Promise<{
9292
if (dataInLocalStorage && cryptoInited && !dataInCryptoStore) {
9393
healthy = false;
9494
error(
95-
"Data exists in local storage and crypto is marked as initialised " +
96-
" but no data found in crypto store. " +
95+
"Data exists in local storage and crypto is marked as initialised but no data found in crypto store. " +
9796
"IndexedDB storage has likely been evicted by the browser!",
9897
);
9998
}

test/unit-tests/components/structures/MatrixChat-test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import AutoDiscoveryUtils from "../../../../src/utils/AutoDiscoveryUtils";
6868
import { type ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
6969
import Modal from "../../../../src/Modal.tsx";
7070
import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStore.ts";
71+
import { clearStorage } from "../../../../src/Lifecycle";
7172

7273
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
7374
completeAuthorizationCodeGrant: jest.fn(),
@@ -217,6 +218,9 @@ describe("<MatrixChat />", () => {
217218
};
218219

219220
beforeEach(async () => {
221+
await clearStorage();
222+
Lifecycle.setSessionLockNotStolen();
223+
220224
localStorage.clear();
221225
jest.restoreAllMocks();
222226
defaultProps = {
@@ -344,10 +348,6 @@ describe("<MatrixChat />", () => {
344348
},
345349
});
346350

347-
jest.spyOn(logger, "error").mockClear();
348-
});
349-
350-
beforeEach(() => {
351351
loginClient = getMockClientWithEventEmitter(getMockClientMethods());
352352
// this is used to create a temporary client during login
353353
jest.spyOn(MatrixJs, "createClient").mockReturnValue(loginClient);

0 commit comments

Comments
 (0)