Skip to content

Commit d4dd427

Browse files
committed
Fix linter errors after adding eslint plugins
- Replace conditional expect calls with proper async/await patterns - Use toStrictEqual with expect.objectContaining for cleaner assertions - Add return statements in promise chains to satisfy always-return rule - Fix toThrow() calls to include error message matchers - Refactor tests to avoid expect inside loops and callbacks - Update error message matchers to match actual error formats"
1 parent a41d004 commit d4dd427

File tree

22 files changed

+492
-351
lines changed

22 files changed

+492
-351
lines changed

.github/actions/setup/action.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ inputs:
77
node-version:
88
description: 'Node.js version'
99
required: true
10-
default: '22'
10+
default: '24'
1111

1212
runs:
1313
using: composite
1414
steps:
1515
- name: Setup Node.js
16-
uses: actions/setup-node@v4
16+
uses: actions/setup-node@v6
1717
with:
1818
cache: 'npm'
1919
node-version: ${{ inputs.node-version }}
2020

2121
- name: Setup turbo
2222
uses: actions/cache@v4
2323
with:
24-
path: .turbo
25-
key: ${{ inputs.node-version }}-turbo-${{ github.sha }}
24+
path: |
25+
.turbo
26+
**/.turbo
27+
key: ${{ runner.os }}-turbo-${{ github.sha }}
2628
restore-keys: |
27-
${{ inputs.node-version }}-turbo-
29+
${{ runner.os }}-turbo-
2830
2931
- name: Install global dependencies
3032
shell: bash

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
test:
3737
name: Test
3838
runs-on: ubuntu-latest
39+
needs: build
3940

4041
concurrency:
4142
group: ${{ github.event_name }}-${{ github.ref }}-${{ matrix.node-version }}
@@ -75,4 +76,5 @@ jobs:
7576
with:
7677
node-version: ${{ matrix.node-version }}
7778

78-
- run: npm run test:all
79+
- run: npm run build
80+
- run: npm run test

.oxlintrc.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
}
1111
],
1212
"unicorn/require-post-message-target-origin": "off",
13-
"yoda": "deny"
13+
"yoda": "deny",
14+
"vitest/consistent-test-it": ["error", { "fn": "test" }],
15+
"vitest/max-nested-describe": ["error", 0]
1416
},
15-
"ignorePatterns": [
16-
"**/node_modules/**",
17-
"**/dist/**"
18-
],
17+
"plugins": ["node", "import", "vitest", "promise", "typescript"],
18+
"ignorePatterns": ["**/node_modules/**", "**/dist/**"],
1919
"categories": {
2020
"correctness": "error",
2121
"suspicious": "warn",

e2e/topic/read-write-tx.test.ts

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { afterEach, beforeEach, expect, inject, test } from 'vitest'
2+
3+
import { create } from '@bufbuild/protobuf'
4+
import { CreateTopicRequestSchema, DropTopicRequestSchema, TopicServiceDefinition } from '@ydbjs/api/topic'
25
import { Driver } from '@ydbjs/core'
6+
import { query } from '@ydbjs/query'
7+
import type { TopicMessage } from '@ydbjs/topic/message'
38
import { createTopicReader, createTopicTxReader } from '@ydbjs/topic/reader'
49
import { createTopicTxWriter, createTopicWriter } from '@ydbjs/topic/writer'
5-
import { CreateTopicRequestSchema, DropTopicRequestSchema, TopicServiceDefinition } from '@ydbjs/api/topic'
6-
import { create } from '@bufbuild/protobuf'
7-
import { query } from '@ydbjs/query'
810

911
// #region setup
1012
declare module 'vitest' {
@@ -42,15 +44,17 @@ beforeEach(async () => {
4244
name: testConsumerName,
4345
},
4446
],
45-
})
47+
}),
48+
{ signal: AbortSignal.timeout(1000) }
4649
)
4750
})
4851

4952
afterEach(async () => {
5053
await topicService.dropTopic(
5154
create(DropTopicRequestSchema, {
5255
path: testTopicName,
53-
})
56+
}),
57+
{ signal: AbortSignal.timeout(1000) }
5458
)
5559
})
5660
// #endregion
@@ -68,6 +72,7 @@ test('writes and reads in tx', async () => {
6872
await writer.close()
6973

7074
// Begin a transaction
75+
let batchInsideTx: TopicMessage[] | undefined
7176
await yql.begin({ idempotent: true }, async (tx) => {
7277
let readerTx = createTopicTxReader(tx, driver, {
7378
topic: testTopicName,
@@ -86,17 +91,20 @@ test('writes and reads in tx', async () => {
8691
// Read messages inside the transaction.
8792
// Expect to see the message written outside the transaction (1).
8893
// Expect NOT to see the message written in the transaction (2).
89-
for await (let batch of readerTx.read()) {
90-
expect(batch).toHaveLength(1)
91-
92-
let message = batch[0]!
93-
expect(message.seqNo).toBe(1n)
94-
expect(message.offset).toBe(0n)
95-
expect(message.payload).toStrictEqual(Buffer.from('written', 'utf-8'))
94+
for await (let batch of readerTx.read({ signal: AbortSignal.timeout(5000) })) {
95+
batchInsideTx = batch
9696
break
9797
}
9898
})
9999

100+
expect(batchInsideTx).toStrictEqual([
101+
expect.objectContaining({
102+
seqNo: 1n,
103+
offset: 0n,
104+
payload: Buffer.from('written', 'utf-8'),
105+
}),
106+
])
107+
100108
await using reader = createTopicReader(driver, {
101109
topic: testTopicName,
102110
consumer: testConsumerName,
@@ -105,16 +113,20 @@ test('writes and reads in tx', async () => {
105113
// Read messages outside of the transaction.
106114
// Expect to see the message written in the transaction (2).
107115
// Expect NOT to see the message written outside the transaction (1).
108-
for await (let batch of reader.read()) {
109-
expect(batch).toHaveLength(1)
110-
111-
let message = batch[0]!
112-
expect(message.seqNo).toBe(2n)
113-
expect(message.offset).toBe(1n)
114-
expect(message.payload).toStrictEqual(Buffer.from('written in tx', 'utf-8'))
116+
let batchOutsideTx: TopicMessage[] | undefined
117+
for await (let batch of reader.read({ signal: AbortSignal.timeout(5000) })) {
118+
batchOutsideTx = batch
115119
await reader.commit(batch)
116120
break
117121
}
122+
123+
expect(batchOutsideTx).toStrictEqual([
124+
expect.objectContaining({
125+
seqNo: 2n,
126+
offset: 1n,
127+
payload: Buffer.from('written in tx', 'utf-8'),
128+
}),
129+
])
118130
})
119131

120132
test('rollbacks reads', async () => {
@@ -129,31 +141,24 @@ test('rollbacks reads', async () => {
129141
writer.write(Buffer.from('written', 'utf-8'), { seqNo: 1n })
130142
await writer.close()
131143

132-
await yql
133-
.begin({ idempotent: true }, async (tx) => {
144+
await expect(async () => {
145+
await yql.begin({ idempotent: true }, async (tx) => {
134146
let readerTx = createTopicTxReader(tx, driver, {
135147
topic: testTopicName,
136148
consumer: testConsumerName,
137149
})
138150

139-
140-
// Read messages inside the transaction.
141-
// Expect to see the message written outside the transaction (1).
142-
for await (let batch of readerTx.read()) {
143-
expect(batch).toHaveLength(1)
144-
expect(batch[0]?.payload).toStrictEqual(Buffer.from('written', 'utf-8'))
151+
for await (let _ of readerTx.read()) {
145152
break
146153
}
147154

148155
// Simulate a transaction failure. User error is always non-retriable.
149156
throw new Error('User error')
150157
})
151-
.catch((error) => {
152-
expect(error).toBeInstanceOf(Error)
153-
expect(error.message).toBe('Transaction failed.')
154-
expect((error as Error).cause).toBeInstanceOf(Error)
155-
expect(((error as Error).cause as Error).message).toBe('User error')
156-
})
158+
}).rejects.toMatchObject({
159+
message: 'Transaction failed.',
160+
cause: expect.objectContaining({ message: 'User error' }),
161+
})
157162

158163
await using reader = createTopicReader(driver, {
159164
topic: testTopicName,
@@ -162,16 +167,20 @@ test('rollbacks reads', async () => {
162167

163168
// Read messages outside of the transaction.
164169
// Expect to see the message written outside the transaction (1).
170+
let committedBatch: Array<TopicMessage> | undefined
165171
for await (let batch of reader.read()) {
166-
expect(batch).toHaveLength(1)
167-
168-
let message = batch[0]!
169-
expect(message.seqNo).toBe(1n)
170-
expect(message.offset).toBe(0n)
171-
expect(message.payload).toStrictEqual(Buffer.from('written', 'utf-8'))
172+
committedBatch = batch
172173
await reader.commit(batch)
173174
break
174175
}
176+
177+
expect(committedBatch).toStrictEqual([
178+
expect.objectContaining({
179+
seqNo: 1n,
180+
offset: 0n,
181+
payload: Buffer.from('written', 'utf-8'),
182+
}),
183+
])
175184
})
176185

177186
test('rollbacks writes', async () => {
@@ -182,8 +191,8 @@ test('rollbacks writes', async () => {
182191
consumer: testConsumerName,
183192
})
184193

185-
await yql
186-
.begin({ idempotent: true }, async (tx) => {
194+
await expect(async () => {
195+
await yql.begin({ idempotent: true }, async (tx) => {
187196
let writerTx = createTopicTxWriter(tx, driver, {
188197
topic: testTopicName,
189198
producer: testProducerName,
@@ -196,17 +205,18 @@ test('rollbacks writes', async () => {
196205
// Simulate a transaction failure. User error is always non-retriable.
197206
throw new Error('User error')
198207
})
199-
.catch((error) => {
200-
expect(error).toBeInstanceOf(Error)
201-
expect(error.message).toBe('Transaction failed.')
202-
expect((error as Error).cause).toBeInstanceOf(Error)
203-
expect(((error as Error).cause as Error).message).toBe('User error')
204-
})
208+
}).rejects.toMatchObject({
209+
message: 'Transaction failed.',
210+
cause: expect.objectContaining({ message: 'User error' }),
211+
})
205212

206213
// Read messages outside of the transaction.
207214
// Expect NOT to see the message written inside the transaction (2).
215+
let observedBatch: Array<TopicMessage> | undefined
208216
for await (let batch of reader.read({ waitMs: 1000 })) {
209-
expect(batch).toHaveLength(0)
217+
observedBatch = batch
210218
break
211219
}
220+
221+
expect(observedBatch).toStrictEqual([])
212222
})

e2e/topic/read-write.test.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { afterEach, assert, beforeEach, inject, test } from "vitest";
1+
import { afterEach, assert, beforeEach, inject, test } from 'vitest'
22
import { Driver } from '@ydbjs/core'
33
import { createTopicReader } from '@ydbjs/topic/reader'
44
import { createTopicWriter } from '@ydbjs/topic/writer'
5-
import { CreateTopicRequestSchema, DropTopicRequestSchema, TopicServiceDefinition } from "@ydbjs/api/topic";
6-
import { create } from "@bufbuild/protobuf";
7-
import { once } from "node:events";
5+
import { CreateTopicRequestSchema, DropTopicRequestSchema, TopicServiceDefinition } from '@ydbjs/api/topic'
6+
import { create } from '@bufbuild/protobuf'
7+
import { once } from 'node:events'
88

99
// #region setup
1010
declare module 'vitest' {
@@ -14,7 +14,7 @@ declare module 'vitest' {
1414
}
1515

1616
let driver = new Driver(inject('connectionString'), {
17-
'ydb.sdk.enable_discovery': false
17+
'ydb.sdk.enable_discovery': false,
1818
})
1919

2020
await driver.ready()
@@ -47,9 +47,11 @@ beforeEach(async () => {
4747
})
4848

4949
afterEach(async () => {
50-
await topicService.dropTopic(create(DropTopicRequestSchema, {
51-
path: testTopicName,
52-
}))
50+
await topicService.dropTopic(
51+
create(DropTopicRequestSchema, {
52+
path: testTopicName,
53+
})
54+
)
5355
})
5456
// #endregion
5557

@@ -65,32 +67,33 @@ test('writes and reads messages from a topic', async () => {
6567
})
6668

6769
// Write a message to the topic
68-
writer.write(Buffer.from('Hello, world!', "utf-8"))
70+
writer.write(Buffer.from('Hello, world!', 'utf-8'))
6971

7072
await writer.flush()
7173

7274
// Read the message from the topic
7375
for await (let batch of reader.read()) {
74-
assert.equal(batch.length, 1, 'Expected one message in batch');
75-
let message = batch[0]!;
76+
assert.equal(batch.length, 1, 'Expected one message in batch')
77+
let message = batch[0]!
7678
assert.equal(Buffer.from(message.payload).toString('utf-8'), 'Hello, world!')
7779

7880
await reader.commit(batch)
7981

8082
break
8183
}
82-
});
84+
})
8385

86+
// oxlint-disable-next-line eslint-plugin-jest(expect-expect)
8487
test('writes and reads concurrently', { timeout: 60_000 }, async (tc) => {
85-
const BATCH_SIZE = 1024;
86-
const MESSAGE_SIZE = 16 * 1024;
87-
const TOTAL_BATCHES = 16;
88-
const TOTAL_TRAFFIC = TOTAL_BATCHES * BATCH_SIZE * MESSAGE_SIZE;
88+
const BATCH_SIZE = 1024
89+
const MESSAGE_SIZE = 16 * 1024
90+
const TOTAL_BATCHES = 16
91+
const TOTAL_TRAFFIC = TOTAL_BATCHES * BATCH_SIZE * MESSAGE_SIZE
8992

9093
await using writer = createTopicWriter(driver, {
9194
topic: testTopicName,
9295
producer: testProducerName,
93-
maxInflightCount: TOTAL_BATCHES * BATCH_SIZE
96+
maxInflightCount: TOTAL_BATCHES * BATCH_SIZE,
9497
})
9598

9699
await using reader = createTopicReader(driver, {
@@ -121,7 +124,7 @@ test('writes and reads concurrently', { timeout: 60_000 }, async (tc) => {
121124
let start = performance.now()
122125
await writer.flush()
123126
console.log(`Write took ${performance.now() - start} ms`)
124-
console.log(`Throughput: ${(wb / (performance.now() - start)) * 1000 / 1024 / 1024} MiB/s`)
127+
console.log(`Throughput: ${((wb / (performance.now() - start)) * 1000) / 1024 / 1024} MiB/s`)
125128
})()
126129

127130
// Read messages from the topic
@@ -140,7 +143,7 @@ test('writes and reads concurrently', { timeout: 60_000 }, async (tc) => {
140143
}
141144

142145
console.log(`Read took ${performance.now() - start} ms`)
143-
console.log(`Throughput: ${(rb / (performance.now() - start)) * 1000 / 1024 / 1024} MiB/s`)
146+
console.log(`Throughput: ${((rb / (performance.now() - start)) * 1000) / 1024 / 1024} MiB/s`)
144147
})()
145148

146149
let start = Date.now()
@@ -149,5 +152,5 @@ test('writes and reads concurrently', { timeout: 60_000 }, async (tc) => {
149152
await reader.close()
150153

151154
console.log(`Wrote ${wb} bytes and read ${rb} bytes in ${Date.now() - start} ms.`)
152-
console.log(`Throughput: ${(rb / (Date.now() - start)) * 1000 / 1024 / 1024} MiB/s`)
155+
console.log(`Throughput: ${((rb / (Date.now() - start)) * 1000) / 1024 / 1024} MiB/s`)
153156
})

examples/sls/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
4242
handler({})
4343
.then((result) => {
4444
console.log('Result:', result)
45+
return result
4546
})
4647
.catch((error) => {
4748
console.error('Error:', error)

0 commit comments

Comments
 (0)