mirror of https://github.com/vector-im/riot-web
Replace sinon fake timers with jest timers (#11275)
parent
f04a0e2860
commit
8f000384fe
|
@ -143,7 +143,6 @@
|
|||
"@peculiar/webcrypto": "^1.4.3",
|
||||
"@percy/cli": "^1.11.0",
|
||||
"@percy/cypress": "^3.1.2",
|
||||
"@sinonjs/fake-timers": "^9.1.2",
|
||||
"@testing-library/cypress": "^9.0.0",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^12.1.5",
|
||||
|
|
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import FakeTimers from "@sinonjs/fake-timers";
|
||||
import EventEmitter from "events";
|
||||
|
||||
import UserActivity from "../src/UserActivity";
|
||||
|
@ -33,19 +32,17 @@ describe("UserActivity", function () {
|
|||
let fakeWindow: FakeDomEventEmitter;
|
||||
let fakeDocument: FakeDomEventEmitter & { hasFocus?(): boolean };
|
||||
let userActivity: UserActivity;
|
||||
let clock: FakeTimers.InstalledClock;
|
||||
|
||||
beforeEach(function () {
|
||||
fakeWindow = new FakeDomEventEmitter();
|
||||
fakeDocument = new FakeDomEventEmitter();
|
||||
userActivity = new UserActivity(fakeWindow as unknown as Window, fakeDocument as unknown as Document);
|
||||
userActivity.start();
|
||||
clock = FakeTimers.install();
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
userActivity.stop();
|
||||
clock.uninstall();
|
||||
});
|
||||
|
||||
it("should return the same shared instance", function () {
|
||||
|
@ -74,7 +71,7 @@ describe("UserActivity", function () {
|
|||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
expect(userActivity.userActiveNow()).toBe(true);
|
||||
expect(userActivity.userActiveRecently()).toBe(true);
|
||||
clock.tick(200);
|
||||
jest.advanceTimersByTime(200);
|
||||
expect(userActivity.userActiveNow()).toBe(true);
|
||||
expect(userActivity.userActiveRecently()).toBe(true);
|
||||
});
|
||||
|
@ -83,7 +80,7 @@ describe("UserActivity", function () {
|
|||
fakeDocument.hasFocus = jest.fn().mockReturnValue(true);
|
||||
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(10000);
|
||||
jest.advanceTimersByTime(10000);
|
||||
expect(userActivity.userActiveNow()).toBe(false);
|
||||
});
|
||||
|
||||
|
@ -91,7 +88,7 @@ describe("UserActivity", function () {
|
|||
fakeDocument.hasFocus = jest.fn().mockReturnValue(true);
|
||||
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(10000);
|
||||
jest.advanceTimersByTime(10000);
|
||||
expect(userActivity.userActiveRecently()).toBe(true);
|
||||
});
|
||||
|
||||
|
@ -99,7 +96,7 @@ describe("UserActivity", function () {
|
|||
fakeDocument.hasFocus = jest.fn().mockReturnValue(true);
|
||||
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(10000);
|
||||
jest.advanceTimersByTime(10000);
|
||||
|
||||
fakeDocument.hasFocus = jest.fn().mockReturnValue(false);
|
||||
fakeWindow.emit("blur", {});
|
||||
|
@ -111,7 +108,7 @@ describe("UserActivity", function () {
|
|||
fakeDocument.hasFocus = jest.fn().mockReturnValue(true);
|
||||
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(3 * 60 * 1000);
|
||||
jest.advanceTimersByTime(3 * 60 * 1000);
|
||||
|
||||
expect(userActivity.userActiveRecently()).toBe(false);
|
||||
});
|
||||
|
@ -120,11 +117,11 @@ describe("UserActivity", function () {
|
|||
fakeDocument.hasFocus = jest.fn().mockReturnValue(true);
|
||||
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(1 * 60 * 1000);
|
||||
jest.advanceTimersByTime(1 * 60 * 1000);
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(1 * 60 * 1000);
|
||||
jest.advanceTimersByTime(1 * 60 * 1000);
|
||||
userActivity.onUserActivity({ type: "event" } as Event);
|
||||
clock.tick(1 * 60 * 1000);
|
||||
jest.advanceTimersByTime(1 * 60 * 1000);
|
||||
|
||||
expect(userActivity.userActiveRecently()).toBe(true);
|
||||
});
|
||||
|
|
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { EventEmitter } from "events";
|
||||
import { MatrixEvent, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import FakeTimers from "@sinonjs/fake-timers";
|
||||
import { render } from "@testing-library/react";
|
||||
import { Thread } from "matrix-js-sdk/src/models/thread";
|
||||
|
||||
|
@ -46,7 +45,6 @@ jest.mock("../../../src/utils/beacon", () => ({
|
|||
const roomId = "!roomId:server_name";
|
||||
|
||||
describe("MessagePanel", function () {
|
||||
let clock: FakeTimers.InstalledClock;
|
||||
const events = mkEvents();
|
||||
const userId = "@me:here";
|
||||
const client = getMockClientWithEventEmitter({
|
||||
|
@ -116,10 +114,6 @@ describe("MessagePanel", function () {
|
|||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
clock?.uninstall();
|
||||
});
|
||||
|
||||
function mkEvents() {
|
||||
const events: MatrixEvent[] = [];
|
||||
const ts0 = Date.now();
|
||||
|
@ -406,7 +400,7 @@ describe("MessagePanel", function () {
|
|||
|
||||
it("shows a ghost read-marker when the read-marker moves", function () {
|
||||
// fake the clock so that we can test the velocity animation.
|
||||
clock = FakeTimers.install();
|
||||
jest.useFakeTimers();
|
||||
|
||||
const { container, rerender } = render(
|
||||
<div>
|
||||
|
@ -447,7 +441,7 @@ describe("MessagePanel", function () {
|
|||
expect(readMarkers[1].previousSibling).toEqual(tiles[6]);
|
||||
|
||||
// advance the clock, and then let the browser run an animation frame to let the animation start
|
||||
clock.tick(1500);
|
||||
jest.advanceTimersByTime(1500);
|
||||
expect(hr.style.opacity).toEqual("0");
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue