Skip to content

Commit cd52873

Browse files
authored
fix: minor improvements (#2672)
1 parent b79d7ae commit cd52873

6 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/core/handlers/GraphQLHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function isDocumentNode(
120120
}
121121

122122
function isDocumentTypeDecoration(
123-
value: any,
123+
value: unknown,
124124
): value is DocumentTypeDecoration<any, any> {
125125
return value instanceof String
126126
}

src/core/sse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class ServerSentEventClient<
333333
}
334334

335335
if (message.event) {
336-
frames.push(`event:${message.event?.toString()}`)
336+
frames.push(`event:${message.event.toString()}`)
337337
}
338338

339339
if (message.data != null) {

src/core/utils/internal/parseGraphQLRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function extractMultipartVariables<VariablesType extends GraphQLVariables>(
8484

8585
for (const path of paths) {
8686
if (!(path in target)) {
87-
throw new Error(`Property '${paths}' is not in operations.`)
87+
throw new Error(`Property '${path}' is not in operations.`)
8888
}
8989

9090
target = target[path]

src/core/utils/internal/parseMultipartData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export function parseMultipartData<T extends DefaultRequestMultipartBody>(
6262
return undefined
6363
}
6464

65-
const boundaryRegExp = new RegExp(`--+${boundary}`)
65+
const boundaryRegExp = new RegExp(
66+
`--+${boundary.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`,
67+
)
6668
const fields = data
6769
.split(boundaryRegExp)
6870
.filter((chunk) => chunk.startsWith('\r\n') && chunk.endsWith('\r\n'))

src/core/ws/WebSocketIndexedDBClientStore.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export class WebSocketIndexedDBClientStore implements WebSocketClientStore {
5656
promise.resolve(request.result)
5757
}
5858
request.onerror = () => {
59-
// eslint-disable-next-line no-console
60-
console.log(request.error)
59+
console.error(request.error)
6160
promise.reject(
6261
new Error(
6362
`Failed to get all WebSocket clients. There is likely an additional output above.`,

test/browser/ws-api/ws.clients.browser.test.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,19 @@ test('returns the number of active clients in the same runtime', async ({
4444
})
4545

4646
// Must return 1 after a single client joined.
47-
expect(
48-
await page.evaluate(() => {
49-
return window.link.clients.size
50-
}),
51-
).toBe(1)
47+
await expect(
48+
page.waitForFunction(() => window.link.clients.size === 1),
49+
).resolves.toBeTruthy()
5250

5351
await page.evaluate(async () => {
5452
const ws = new WebSocket('wss://example.com')
5553
await new Promise((done) => (ws.onopen = done))
5654
})
5755

5856
// Must return 2 now that another client has joined.
59-
expect(
60-
await page.evaluate(() => {
61-
return window.link.clients.size
62-
}),
63-
).toBe(2)
57+
await expect(
58+
page.waitForFunction(() => window.link.clients.size === 2),
59+
).resolves.toBeTruthy()
6460
})
6561

6662
test('returns the number of active clients across different runtimes', async ({
@@ -94,17 +90,25 @@ test('returns the number of active clients across different runtimes', async ({
9490
await new Promise((done) => (ws.onopen = done))
9591
})
9692

97-
expect(await pageOne.evaluate(() => window.link.clients.size)).toBe(1)
98-
expect(await pageTwo.evaluate(() => window.link.clients.size)).toBe(1)
93+
await expect(
94+
pageOne.waitForFunction(() => window.link.clients.size === 1),
95+
).resolves.toBeTruthy()
96+
await expect(
97+
pageTwo.waitForFunction(() => window.link.clients.size === 1),
98+
).resolves.toBeTruthy()
9999

100100
await pageTwo.bringToFront()
101101
await pageTwo.evaluate(async () => {
102102
const ws = new WebSocket('wss://example.com')
103103
await new Promise((done) => (ws.onopen = done))
104104
})
105105

106-
expect(await pageTwo.evaluate(() => window.link.clients.size)).toBe(2)
107-
expect(await pageOne.evaluate(() => window.link.clients.size)).toBe(2)
106+
await expect(
107+
pageTwo.waitForFunction(() => window.link.clients.size === 2),
108+
).resolves.toBeTruthy()
109+
await expect(
110+
pageOne.waitForFunction(() => window.link.clients.size === 2),
111+
).resolves.toBeTruthy()
108112
})
109113

110114
test('broadcasts messages across runtimes', async ({
@@ -198,7 +202,9 @@ test('clears the list of clients when the worker is stopped', async ({
198202
})
199203

200204
// Must return the number of joined clients.
201-
expect(await page.evaluate(() => window.link.clients.size)).toBe(1)
205+
await expect(
206+
page.waitForFunction(() => window.link.clients.size === 1),
207+
).resolves.toBeTruthy()
202208

203209
await page.evaluate(() => {
204210
window.worker.stop()
@@ -239,7 +245,9 @@ test('clears the list of clients when the page is reloaded', async ({
239245
})
240246

241247
// Must return the number of joined clients.
242-
expect(await page.evaluate(() => window.link.clients.size)).toBe(1)
248+
await expect(
249+
page.waitForFunction(() => window.link.clients.size === 1),
250+
).resolves.toBeTruthy()
243251

244252
await page.reload()
245253
await enableMocking()

0 commit comments

Comments
 (0)