Stabilise Vitest MatrixChat test (#34555)
* Stabilise Vitest MatrixChat test * Ignore post-teardown exceptions in vitest * Iterate
This commit is contained in:
@@ -39,6 +39,8 @@ interface IState {
|
||||
}
|
||||
|
||||
export default class LanguageDropdown extends React.Component<IProps, IState> {
|
||||
private unmounted = false;
|
||||
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
@@ -49,8 +51,11 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.unmounted = false;
|
||||
|
||||
getAllLanguagesWithLabels()
|
||||
.then((langs) => {
|
||||
if (this.unmounted) return;
|
||||
langs.sort(function (a, b) {
|
||||
if (a.labelInTargetLanguage < b.labelInTargetLanguage) return -1;
|
||||
if (a.labelInTargetLanguage > b.labelInTargetLanguage) return 1;
|
||||
@@ -59,6 +64,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
|
||||
this.setState({ langs });
|
||||
})
|
||||
.catch(() => {
|
||||
if (this.unmounted) return;
|
||||
this.setState({
|
||||
langs: [
|
||||
{
|
||||
@@ -78,6 +84,10 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
|
||||
}
|
||||
}
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
this.unmounted = true;
|
||||
}
|
||||
|
||||
private onSearchChange = (search: string): void => {
|
||||
this.setState({
|
||||
searchQuery: search,
|
||||
|
||||
@@ -18,9 +18,26 @@ declare global {
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
|
||||
// Ignore benign post-teardown exceptions as they cause flakes
|
||||
const guardState = globalThis as unknown as { __vitestTestRunning?: boolean; __teardownGuardInstalled?: boolean };
|
||||
if (!guardState.__teardownGuardInstalled) {
|
||||
guardState.__teardownGuardInstalled = true;
|
||||
const isPostTeardownStraggler = (): boolean => !guardState.__vitestTestRunning || typeof window === "undefined";
|
||||
process.on("uncaughtException", (err) => {
|
||||
if (isPostTeardownStraggler()) return;
|
||||
throw err;
|
||||
});
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
if (isPostTeardownStraggler()) return;
|
||||
throw reason;
|
||||
});
|
||||
}
|
||||
|
||||
manageFetchMockGlobally();
|
||||
|
||||
beforeEach(() => {
|
||||
guardState.__vitestTestRunning = true;
|
||||
|
||||
vi.stubEnv("TZ", "UTC");
|
||||
|
||||
// set up fetch API mock
|
||||
@@ -31,7 +48,10 @@ beforeEach(() => {
|
||||
setupLanguageMock();
|
||||
});
|
||||
|
||||
afterEach(() => fetchMock.callHistory.flush());
|
||||
afterEach(() => {
|
||||
guardState.__vitestTestRunning = false;
|
||||
return fetchMock.callHistory.flush();
|
||||
});
|
||||
|
||||
// uninitialised SdkConfig causes lots of warnings in console, init with defaults
|
||||
SdkConfig.put(DEFAULTS);
|
||||
|
||||
Reference in New Issue
Block a user