Fix flaky jest tests (#29927)
* Debug flaky jest test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Discard changes to jest.config.ts --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
10757b4357
commit
e235100dd0
@@ -1115,7 +1115,9 @@ export async function onLoggedOut(): Promise<void> {
|
|||||||
* @param {object} opts Options for how to clear storage.
|
* @param {object} opts Options for how to clear storage.
|
||||||
* @returns {Promise} promise which resolves once the stores have been cleared
|
* @returns {Promise} promise which resolves once the stores have been cleared
|
||||||
*/
|
*/
|
||||||
async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void> {
|
export async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void> {
|
||||||
|
logger.info(`Clearing storage, deleteEverything=${opts?.deleteEverything}`);
|
||||||
|
|
||||||
if (window.localStorage) {
|
if (window.localStorage) {
|
||||||
// get the currently defined device language, if set, so we can restore it later
|
// get the currently defined device language, if set, so we can restore it later
|
||||||
const language = SettingsStore.getValueAt(SettingLevel.DEVICE, "language", null, true, true);
|
const language = SettingsStore.getValueAt(SettingLevel.DEVICE, "language", null, true, true);
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ export async function checkConsistency(): Promise<{
|
|||||||
if (dataInLocalStorage && cryptoInited && !dataInCryptoStore) {
|
if (dataInLocalStorage && cryptoInited && !dataInCryptoStore) {
|
||||||
healthy = false;
|
healthy = false;
|
||||||
error(
|
error(
|
||||||
"Data exists in local storage and crypto is marked as initialised " +
|
"Data exists in local storage and crypto is marked as initialised but no data found in crypto store. " +
|
||||||
" but no data found in crypto store. " +
|
|
||||||
"IndexedDB storage has likely been evicted by the browser!",
|
"IndexedDB storage has likely been evicted by the browser!",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ import AutoDiscoveryUtils from "../../../../src/utils/AutoDiscoveryUtils";
|
|||||||
import { type ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
|
import { type ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
|
||||||
import Modal from "../../../../src/Modal.tsx";
|
import Modal from "../../../../src/Modal.tsx";
|
||||||
import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStore.ts";
|
import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStore.ts";
|
||||||
|
import { clearStorage } from "../../../../src/Lifecycle";
|
||||||
|
|
||||||
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
|
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
|
||||||
completeAuthorizationCodeGrant: jest.fn(),
|
completeAuthorizationCodeGrant: jest.fn(),
|
||||||
@@ -217,6 +218,9 @@ describe("<MatrixChat />", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
await clearStorage();
|
||||||
|
Lifecycle.setSessionLockNotStolen();
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
defaultProps = {
|
defaultProps = {
|
||||||
@@ -344,10 +348,6 @@ describe("<MatrixChat />", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(logger, "error").mockClear();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
loginClient = getMockClientWithEventEmitter(getMockClientMethods());
|
loginClient = getMockClientWithEventEmitter(getMockClientMethods());
|
||||||
// this is used to create a temporary client during login
|
// this is used to create a temporary client during login
|
||||||
jest.spyOn(MatrixJs, "createClient").mockReturnValue(loginClient);
|
jest.spyOn(MatrixJs, "createClient").mockReturnValue(loginClient);
|
||||||
|
|||||||
Reference in New Issue
Block a user