Skip to content

Commit 9a23823

Browse files
authored
feat: upgrade ava (#1075)
1 parent 83429e5 commit 9a23823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1090
-987
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"extensions": {
99
"ts": "module"
1010
},
11+
"require": ["./tests/utils/_force-exit.ts"],
1112
"nodeArguments": [
1213
"--no-warnings",
1314
"--conditions=source",
1415
"--experimental-transform-types",
1516
"--experimental-specifier-resolution=node"
1617
],
18+
"timeout": "30s",
1719
"workerThreads": false
1820
},
1921
"scripts": {
@@ -47,10 +49,9 @@
4749
"ncu": "ncu -i --deep && pnpm install"
4850
},
4951
"devDependencies": {
50-
"@ava/typescript": "^3.0.1",
5152
"@biomejs/biome": "2.4.5",
5253
"@types/bun": "^1.3.9",
53-
"ava": "^4.3.3",
54+
"ava": "^7.0.0",
5455
"concurrently": "^6.4.0",
5556
"lerna": "^9.0.5",
5657
"nx": "^22.5.3",

pnpm-lock.yaml

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

tests/extension-database/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { newHocuspocus, newHocuspocusProvider } from '../utils/index.ts'
55

66
test('fetch has the document name', async t => {
77
await new Promise(async resolve => {
8-
const server = await newHocuspocus({
8+
const server = await newHocuspocus(t, {
99
extensions: [
1010
new Database({
1111
async fetch({ documentName }) {
@@ -19,15 +19,15 @@ test('fetch has the document name', async t => {
1919
],
2020
})
2121

22-
newHocuspocusProvider(server, {
22+
newHocuspocusProvider(t, server, {
2323
name: 'my-unique-document-name',
2424
})
2525
})
2626
})
2727

2828
test('passes context from onAuthenticate to fetch', async t => {
2929
await new Promise(async resolve => {
30-
const server = await newHocuspocus({
30+
const server = await newHocuspocus(t, {
3131
extensions: [
3232
new Database({
3333
async fetch({ context }) {
@@ -48,7 +48,7 @@ test('passes context from onAuthenticate to fetch', async t => {
4848
},
4949
})
5050

51-
newHocuspocusProvider(server, {
51+
newHocuspocusProvider(t, server, {
5252
token: 'SUPER-SECRET-TOKEN',
5353
name: 'my-unique-document-name',
5454
})

tests/extension-logger/onListen.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ test('logs something', async t => {
1010
await new Promise(async resolve => {
1111
const spy = sinon.spy(fakeLogger)
1212

13-
const server = await newHocuspocus({
13+
const server = await newHocuspocus(t, {
1414
extensions: [
1515
new Logger({
1616
log: spy,
1717
}),
1818
],
1919
})
2020

21-
newHocuspocusProvider(server, {
21+
newHocuspocusProvider(t, server, {
2222
onConnect() {
23-
t.true(spy.callCount > 1, 'Expected the Logger to log something, but didnt receive anything.')
23+
t.true(spy.callCount > 1, 'Expected the Logger to log something, but didn\'t receive anything.')
2424
t.true(spy.callCount === 3, `Expected it to log 11 times, but actually logged ${spy.callCount} times`)
2525

2626
resolve('done')
@@ -33,13 +33,8 @@ test('uses the global instance name', async t => {
3333
await new Promise(async resolve => {
3434
const spy = sinon.spy(fakeLogger)
3535

36-
const hocuspocus = await newHocuspocus({
36+
const hocuspocus = await newHocuspocus(t, {
3737
name: 'FOOBAR123',
38-
async onDestroy() {
39-
t.is(spy.args[spy.args.length - 1][0].includes('FOOBAR123'), true, 'Expected the Logger to use the configured instance name.')
40-
41-
resolve('done')
42-
},
4338
extensions: [
4439
new Logger({
4540
log: spy,
@@ -48,24 +43,23 @@ test('uses the global instance name', async t => {
4843
})
4944

5045
await hocuspocus.server!.destroy()
46+
47+
t.is(spy.args[spy.args.length - 1][0].includes('FOOBAR123'), true, 'Expected the Logger to use the configured instance name.')
48+
49+
resolve('done')
5150
})
5251

5352
})
5453

55-
test('doesnt log anything if all messages are disabled', async t => {
54+
test('doesn\'t log anything if all messages are disabled', async t => {
5655
await new Promise(async resolve => {
5756
const spy = sinon.spy(fakeLogger)
5857

59-
const hocuspocus = await newHocuspocus({
60-
async onDestroy() {
61-
t.is(spy.callCount, 0, 'Expected the Logger to not log anything.')
62-
63-
resolve('done')
64-
},
58+
const hocuspocus = await newHocuspocus(t, {
6559
extensions: [
6660
new Logger({
6761
log: spy,
68-
// TODO: Those hooks arent triggered anyway.
62+
// TODO: Those hooks aren't triggered anyway.
6963
// onLoadDocument: false,
7064
// onChange: false,
7165
// onConnect: false,
@@ -81,5 +75,9 @@ test('doesn’t log anything if all messages are disabled', async t => {
8175
})
8276

8377
await hocuspocus.server!.destroy()
78+
79+
t.is(spy.callCount, 0, 'Expected the Logger to not log anything.')
80+
81+
resolve('done')
8482
})
8583
})

tests/extension-redis/onAwarenessChange.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test("syncs existing awareness state", async (t) => {
1111
const documentName = `test-${crypto.randomUUID()}`;
1212

1313
await new Promise(async (resolve) => {
14-
const server = await newHocuspocus({
14+
const server = await newHocuspocus(t, {
1515
extensions: [
1616
new Redis({
1717
...redisConnectionSettings,
@@ -20,7 +20,7 @@ test("syncs existing awareness state", async (t) => {
2020
],
2121
});
2222

23-
const anotherServer = await newHocuspocus({
23+
const anotherServer = await newHocuspocus(t, {
2424
extensions: [
2525
new Redis({
2626
...redisConnectionSettings,
@@ -29,7 +29,7 @@ test("syncs existing awareness state", async (t) => {
2929
],
3030
});
3131

32-
const provider = newHocuspocusProvider(server, {
32+
const provider = newHocuspocusProvider(t, server, {
3333
name: documentName,
3434
onSynced() {
3535
// Once we're set up, change the local Awareness state.
@@ -39,7 +39,7 @@ test("syncs existing awareness state", async (t) => {
3939

4040
// Time to initialize a second provider, and connect to `anotherServer`
4141
// to check whether existing Awareness states are synced through Redis.
42-
newHocuspocusProvider(anotherServer, {
42+
newHocuspocusProvider(t, anotherServer, {
4343
name: documentName,
4444
onAwarenessChange({ states }: onAwarenessChangeParameters) {
4545
// Wait until we have exactly 2 states with the expected data
@@ -61,7 +61,7 @@ test("syncs awareness between servers and clients", async (t) => {
6161
const documentName = `test-${crypto.randomUUID()}`;
6262

6363
await new Promise(async (resolve) => {
64-
const server = await newHocuspocus({
64+
const server = await newHocuspocus(t, {
6565
extensions: [
6666
new Redis({
6767
...redisConnectionSettings,
@@ -70,7 +70,7 @@ test("syncs awareness between servers and clients", async (t) => {
7070
],
7171
});
7272

73-
const anotherServer = await newHocuspocus({
73+
const anotherServer = await newHocuspocus(t, {
7474
extensions: [
7575
new Redis({
7676
...redisConnectionSettings,
@@ -79,7 +79,7 @@ test("syncs awareness between servers and clients", async (t) => {
7979
],
8080
});
8181

82-
const provider = newHocuspocusProvider(anotherServer, {
82+
const provider = newHocuspocusProvider(t, anotherServer, {
8383
name: documentName,
8484
onSynced() {
8585
// once we're setup change awareness on provider, to get to client it will
@@ -89,7 +89,7 @@ test("syncs awareness between servers and clients", async (t) => {
8989
},
9090
});
9191

92-
newHocuspocusProvider(server, {
92+
newHocuspocusProvider(t, server, {
9393
name: documentName,
9494
onAwarenessChange: ({ states }: onAwarenessChangeParameters) => {
9595
// Wait until we have exactly 2 states with the expected data

tests/extension-redis/onChange.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88

99
test("syncs updates between servers and clients", async (t) => {
1010
await new Promise(async (resolve) => {
11-
const server = await newHocuspocus({
11+
let resolved = false;
12+
13+
const server = await newHocuspocus(t, {
1214
extensions: [
1315
new Redis({
1416
...redisConnectionSettings,
@@ -17,7 +19,7 @@ test("syncs updates between servers and clients", async (t) => {
1719
],
1820
});
1921

20-
const anotherServer = await newHocuspocus({
22+
const anotherServer = await newHocuspocus(t, {
2123
extensions: [
2224
new Redis({
2325
...redisConnectionSettings,
@@ -29,17 +31,20 @@ test("syncs updates between servers and clients", async (t) => {
2931
// Once we’re setup make an edit on anotherProvider. To get to the provider it will need
3032
// to pass through Redis:
3133
// provider -> server -> Redis -> anotherServer -> anotherProvider
32-
const provider = newHocuspocusProvider(server, {
34+
const provider = newHocuspocusProvider(t, server, {
3335
onSynced() {
3436
provider.document.getArray("foo").insert(0, ["bar"]);
3537
},
3638
});
3739

3840
// Once the initial data is synced, wait for an additional update to check
3941
// if both documents have the same content.
40-
const anotherProvider = newHocuspocusProvider(anotherServer, {
42+
const anotherProvider = newHocuspocusProvider(t, anotherServer, {
4143
onSynced() {
4244
provider.on("message", () => {
45+
if (resolved) return;
46+
resolved = true;
47+
4348
setTimeout(() => {
4449
t.is(
4550
provider.document.getArray("foo").get(0),

tests/extension-redis/onStateless.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test("syncs broadcast stateless message between servers and clients", async (t)
1111

1212
await new Promise(async (resolve) => {
1313
const payloadToSend = "STATELESS-MESSAGE";
14-
const server = await newHocuspocus({
14+
const server = await newHocuspocus(t, {
1515
extensions: [
1616
new Redis({
1717
...redisConnectionSettings,
@@ -21,7 +21,7 @@ test("syncs broadcast stateless message between servers and clients", async (t)
2121
],
2222
});
2323

24-
const anotherServer = await newHocuspocus({
24+
const anotherServer = await newHocuspocus(t, {
2525
extensions: [
2626
new Redis({
2727
...redisConnectionSettings,
@@ -36,15 +36,15 @@ test("syncs broadcast stateless message between servers and clients", async (t)
3636
// provider -> server -> Redis -> anotherServer -> anotherProvider
3737

3838
// Wait for a stateless message to confirm whether another provider has the same payload.
39-
newHocuspocusProvider(anotherServer, {
39+
newHocuspocusProvider(t, anotherServer, {
4040
onStateless: ({ payload }) => {
4141
t.is(payload, payloadToSend);
4242
t.pass();
4343
resolve("done");
4444
},
4545
onSynced() {
4646
// Once the initial data is synced, send a stateless message
47-
newHocuspocusProvider(server, {
47+
newHocuspocusProvider(t, server, {
4848
onSynced() {
4949
server.documents
5050
.get("hocuspocus-test")
@@ -61,7 +61,7 @@ test("client stateless messages shouldnt propagate to other server", async (t) =
6161

6262
await new Promise(async (resolve) => {
6363
const payloadToSend = "STATELESS-MESSAGE";
64-
const server = await newHocuspocus({
64+
const server = await newHocuspocus(t, {
6565
extensions: [
6666
new Redis({
6767
...redisConnectionSettings,
@@ -76,7 +76,7 @@ test("client stateless messages shouldnt propagate to other server", async (t) =
7676
},
7777
});
7878

79-
const anotherServer = await newHocuspocus({
79+
const anotherServer = await newHocuspocus(t, {
8080
extensions: [
8181
new Redis({
8282
...redisConnectionSettings,
@@ -90,7 +90,7 @@ test("client stateless messages shouldnt propagate to other server", async (t) =
9090
},
9191
});
9292

93-
const provider = newHocuspocusProvider(server, {
93+
const provider = newHocuspocusProvider(t, server, {
9494
onSynced() {
9595
provider.sendStateless(payloadToSend);
9696
},
@@ -102,7 +102,7 @@ test("server client stateless messages shouldnt propagate to other client", asyn
102102
await new Promise(async (resolve) => {
103103
const redisPrefix = crypto.randomUUID();
104104

105-
const server = await newHocuspocus({
105+
const server = await newHocuspocus(t, {
106106
extensions: [
107107
new Redis({
108108
...redisConnectionSettings,
@@ -115,7 +115,7 @@ test("server client stateless messages shouldnt propagate to other client", asyn
115115
},
116116
});
117117

118-
const anotherServer = await newHocuspocus({
118+
const anotherServer = await newHocuspocus(t, {
119119
extensions: [
120120
new Redis({
121121
...redisConnectionSettings,
@@ -128,13 +128,13 @@ test("server client stateless messages shouldnt propagate to other client", asyn
128128
},
129129
});
130130

131-
const provider2 = newHocuspocusProvider(anotherServer, {
131+
const provider2 = newHocuspocusProvider(t, anotherServer, {
132132
onStateless() {
133133
t.fail();
134134
},
135135
});
136136

137-
const provider = newHocuspocusProvider(server, {
137+
const provider = newHocuspocusProvider(t, server, {
138138
onSynced() {
139139
provider.sendStateless("ok");
140140
},

0 commit comments

Comments
 (0)