test: Enable quality gate and touch a file
This commit is contained in:
@@ -13,7 +13,6 @@ coverage:
|
|||||||
informational: true
|
informational: true
|
||||||
patch:
|
patch:
|
||||||
default:
|
default:
|
||||||
# Encourage (but don't enforce) 80% coverage on all lines that a PR
|
# Enforce 80% coverage on all lines that a PR
|
||||||
# touches
|
# touches
|
||||||
target: 80%
|
target: 80%
|
||||||
informational: true
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|||||||
Please see LICENSE in the repository root for full details.
|
Please see LICENSE in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { BehaviorSubject, combineLatest, Subject } from "rxjs";
|
import { BehaviorSubject, combineLatest, Subject } from "rxjs";
|
||||||
import { logger } from "matrix-js-sdk/lib/logger";
|
import { logger } from "matrix-js-sdk/lib/logger";
|
||||||
|
|
||||||
@@ -102,3 +102,52 @@ describe("Epoch", () => {
|
|||||||
s$.complete();
|
s$.complete();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Reconcile", () => {
|
||||||
|
it("should wait for cleanup to complete before processing next Value", async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
|
||||||
|
const scope = new ObservableScope();
|
||||||
|
const cleanUp1 = Promise.withResolvers<void>();
|
||||||
|
const cleanUp2 = vi.fn();
|
||||||
|
|
||||||
|
const behavior$ = new BehaviorSubject<number>(1);
|
||||||
|
let lastProcessed = 0;
|
||||||
|
|
||||||
|
scope.reconcile<number>(
|
||||||
|
behavior$,
|
||||||
|
async (value: number): Promise<(() => Promise<void>) | void> => {
|
||||||
|
lastProcessed = value;
|
||||||
|
if (value === 1) {
|
||||||
|
return Promise.resolve(async (): Promise<void> => cleanUp1.promise);
|
||||||
|
} else if (value === 2) {
|
||||||
|
return Promise.resolve(async (): Promise<void> => {
|
||||||
|
cleanUp2();
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// behavior$.next(1);
|
||||||
|
await vi.advanceTimersByTimeAsync(200);
|
||||||
|
behavior$.next(2);
|
||||||
|
await vi.advanceTimersByTimeAsync(300);
|
||||||
|
|
||||||
|
await vi.runAllTimersAsync();
|
||||||
|
|
||||||
|
// Should not have processed 2 yet because cleanup of 1 is pending
|
||||||
|
expect(lastProcessed).toBe(1);
|
||||||
|
cleanUp1.resolve();
|
||||||
|
// await flushPromises();
|
||||||
|
|
||||||
|
await vi.runAllTimersAsync();
|
||||||
|
// Now 2 should be processed
|
||||||
|
expect(lastProcessed).toBe(2);
|
||||||
|
|
||||||
|
scope.end();
|
||||||
|
await vi.runAllTimersAsync();
|
||||||
|
expect(cleanUp2).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -117,6 +117,10 @@ export class ObservableScope {
|
|||||||
* values may be skipped.
|
* values may be skipped.
|
||||||
*
|
*
|
||||||
* Basically, this is like React's useEffect but async and for Behaviors.
|
* Basically, this is like React's useEffect but async and for Behaviors.
|
||||||
|
*
|
||||||
|
* @arg value$ - The Behavior to track.
|
||||||
|
* @arg callback - Called whenever the value must be handled. May return a clean-up function
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public reconcile<T>(
|
public reconcile<T>(
|
||||||
value$: Behavior<T>,
|
value$: Behavior<T>,
|
||||||
@@ -221,6 +225,7 @@ export class Epoch<T> {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
this.epoch = epoch ?? 0;
|
this.epoch = epoch ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the value inside the epoch to a new value while keeping the epoch number.
|
* Maps the value inside the epoch to a new value while keeping the epoch number.
|
||||||
* # usage
|
* # usage
|
||||||
|
|||||||
Reference in New Issue
Block a user