Skip to content

Commit 98e358a

Browse files
authored
chore: Use vi.waitFor for async side-effects (#1385)
* chore: Use vi.waitFor for async side-effects * chore: Fix type error in dispatcher-ws.spec.ts * chore: Type-check tsconfig.test.json
1 parent 87ade31 commit 98e358a

9 files changed

Lines changed: 110 additions & 70 deletions

package-lock.json

Lines changed: 23 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"scripts": {
3939
"test": "npm-run-all test:*",
40+
"test:typecheck": "tsc --project tsconfig.test.json",
4041
"test:unit": "vitest --project unit",
4142
"test:e2e": "vitest --project e2e",
4243
"lint": "npm-run-all lint:*",
@@ -58,7 +59,6 @@
5859
},
5960
"devDependencies": {
6061
"@eslint/js": "^9.38.0",
61-
"@sadams/wait-for-expect": "^1.2.0",
6262
"@size-limit/preset-small-lib": "^12.0.0",
6363
"@tsconfig/node22": "^22.0.2",
6464
"@types/eslint__js": "^8.42.3",

src/adapters/action/dispatcher-ws.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("DispatcherWs", () => {
2525
path: "/api/v2/unknown",
2626
data: undefined,
2727
meta: {},
28+
raw: false,
2829
});
2930
}).toThrow(MastoUnexpectedError);
3031
});

tests/rest/v1/conversations.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import assert from "node:assert";
22

3-
import waitForExpect from "@sadams/wait-for-expect";
4-
53
import { type mastodon } from "../../../src/index.js";
64

75
describe("conversations", () => {
@@ -20,13 +18,17 @@ describe("conversations", () => {
2018
visibility: "direct",
2119
});
2220

23-
await waitForExpect(async () => {
24-
const conversations = await alice.rest.v1.conversations.list();
25-
conversation = conversations.find(
26-
(c) => c.lastStatus?.id === status.id,
27-
);
28-
expect(conversation?.accounts).toContainEqual(bob.account);
29-
});
21+
await vi.waitFor(
22+
async () => {
23+
const conversations = await alice.rest.v1.conversations.list();
24+
conversation = conversations.find(
25+
(c) => c.lastStatus?.id === status.id,
26+
);
27+
expect(conversation?.accounts).toContainEqual(bob.account);
28+
},
29+
30+
{ timeout: 4500 },
31+
);
3032

3133
assert.ok(conversation != undefined);
3234

tests/rest/v1/follow-requests.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import waitForExpect from "@sadams/wait-for-expect";
2-
31
it("authorize follow requests", async () => {
42
await using alice = await sessions.acquire();
53
await using bob = await sessions.acquire();
64
await alice.rest.v1.accounts.updateCredentials({ locked: true });
75

8-
await waitForExpect(async () => {
9-
const me = await alice.rest.v1.accounts.verifyCredentials();
10-
expect(me.locked).toBe(true);
11-
});
6+
await vi.waitFor(
7+
async () => {
8+
const me = await alice.rest.v1.accounts.verifyCredentials();
9+
expect(me.locked).toBe(true);
10+
},
11+
{ timeout: 4500 },
12+
);
1213

1314
try {
1415
let relationship = await bob.rest.v1.accounts.$select(alice.id).follow();
@@ -33,10 +34,13 @@ it("rejects follow requests", async () => {
3334
await using bob = await sessions.acquire();
3435
await alice.rest.v1.accounts.updateCredentials({ locked: true });
3536

36-
await waitForExpect(async () => {
37-
const target = await bob.rest.v1.accounts.$select(alice.id).fetch();
38-
expect(target.locked).toBe(true);
39-
});
37+
await vi.waitFor(
38+
async () => {
39+
const target = await bob.rest.v1.accounts.$select(alice.id).fetch();
40+
expect(target.locked).toBe(true);
41+
},
42+
{ timeout: 4500 },
43+
);
4044

4145
try {
4246
let relationship = await bob.rest.v1.accounts.$select(alice.id).follow();

tests/rest/v1/notifications.spec.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import assert from "node:assert";
22

3-
import waitForExpect from "@sadams/wait-for-expect";
4-
53
it("handles notifications", async () => {
64
await using alice = await sessions.acquire();
75
await using bob = await sessions.acquire();
@@ -10,10 +8,14 @@ it("handles notifications", async () => {
108
});
119

1210
try {
13-
await waitForExpect(async () => {
14-
const unreadCount = await alice.rest.v1.notifications.unreadCount.fetch();
15-
expect(unreadCount.count).toBe(1);
16-
});
11+
await vi.waitFor(
12+
async () => {
13+
const unreadCount =
14+
await alice.rest.v1.notifications.unreadCount.fetch();
15+
expect(unreadCount.count).toBe(1);
16+
},
17+
{ timeout: 4500 },
18+
);
1719

1820
let notifications = await alice.rest.v1.notifications.list();
1921
let notification = notifications.find((n) => n.status?.id === status.id);
@@ -52,12 +54,15 @@ it("clear notifications", async () => {
5254
try {
5355
let notifications = await alice.rest.v1.notifications.list();
5456

55-
await waitForExpect(async () => {
56-
notifications = await alice.rest.v1.notifications.list();
57-
expect(notifications.map((n) => n.status)).toContainEqual(s1);
58-
expect(notifications.map((n) => n.status)).toContainEqual(s2);
59-
expect(notifications.map((n) => n.status)).toContainEqual(s3);
60-
});
57+
await vi.waitFor(
58+
async () => {
59+
notifications = await alice.rest.v1.notifications.list();
60+
expect(notifications.map((n) => n.status)).toContainEqual(s1);
61+
expect(notifications.map((n) => n.status)).toContainEqual(s2);
62+
expect(notifications.map((n) => n.status)).toContainEqual(s3);
63+
},
64+
{ timeout: 4500 },
65+
);
6166

6267
expect(notifications.length >= 3).toBe(true);
6368

tests/rest/v1/timelines.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import waitForExpect from "@sadams/wait-for-expect";
2-
31
import { type mastodon } from "../../../src/index.js";
42

53
describe("timeline", () => {
@@ -21,10 +19,14 @@ describe("timeline", () => {
2119

2220
let statuses: mastodon.v1.Status[] | undefined;
2321

24-
await waitForExpect(async () => {
25-
statuses = await client.rest.v1.timelines.home.list();
26-
expect(statuses).toContainEqual(status);
27-
});
22+
await vi.waitFor(
23+
async () => {
24+
statuses = await client.rest.v1.timelines.home.list();
25+
expect(statuses).toContainEqual(status);
26+
},
27+
28+
{ timeout: 4500 },
29+
);
2830
});
2931

3032
it("returns public", async () => {

0 commit comments

Comments
 (0)