Skip to content

Commit 50cb9e7

Browse files
committed
Lint tests
Disallows focused tests to avoid accidentally committing a test that disables all others in the same file.
1 parent d0288b3 commit 50cb9e7

File tree

9 files changed

+225
-16
lines changed

9 files changed

+225
-16
lines changed

.eslintrc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
],
77
"plugins": [
88
"prettier",
9-
"standard"
9+
"standard",
10+
"jest"
1011
],
1112
"parserOptions": {
1213
"ecmaVersion": 2020
@@ -34,9 +35,18 @@
3435
"^testIfKafka_*"
3536
]
3637
}
37-
]
38+
],
39+
"jest/no-focused-tests": "error",
40+
"jest/no-commented-out-tests": "error",
41+
"jest/no-deprecated-functions": "error",
42+
"jest/no-jasmine-globals": "error",
43+
"jest/no-jest-import": "error",
44+
"jest/no-test-prefixes": "error",
45+
"jest/valid-describe-callback": "error",
46+
"jest/valid-expect": "error",
47+
"jest/valid-expect-in-promise": "error"
3848
},
3949
"env": {
40-
"jest": true,
50+
"jest": true
4151
}
4252
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"eslint-config-prettier": "^6.0.0",
5353
"eslint-config-standard": "^13.0.1",
5454
"eslint-plugin-import": "^2.18.2",
55+
"eslint-plugin-jest": "^26.1.0",
5556
"eslint-plugin-node": "^11.0.0",
5657
"eslint-plugin-prettier": "^3.1.0",
5758
"eslint-plugin-promise": "^4.2.1",

src/consumer/__tests__/commitOffsets.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,35 @@ describe('Consumer', () => {
4242

4343
describe('when commitOffsets', () => {
4444
it('throws an error if any of the topics is invalid', async () => {
45-
expect(consumer.commitOffsets([{ topic: null }])).rejects.toThrow(
45+
await expect(consumer.commitOffsets([{ topic: null }])).rejects.toThrow(
4646
KafkaJSNonRetriableError,
4747
'Invalid topic null'
4848
)
4949
})
5050

5151
it('throws an error if any of the partitions is not a number', async () => {
52-
expect(consumer.commitOffsets([{ topic: topicName, partition: 'ABC' }])).rejects.toThrow(
52+
await expect(
53+
consumer.commitOffsets([{ topic: topicName, partition: 'ABC' }])
54+
).rejects.toThrow(
5355
KafkaJSNonRetriableError,
5456
'Invalid partition, expected a number received ABC'
5557
)
5658
})
5759

5860
it('throws an error if any of the offsets is not a number', async () => {
59-
expect(
61+
await expect(
6062
consumer.commitOffsets([{ topic: topicName, partition: 0, offset: 'ABC' }])
6163
).rejects.toThrow(KafkaJSNonRetriableError, 'Invalid offset, expected a long received ABC')
6264
})
6365

6466
it('throws an error if any of the offsets is not an absolute offset', async () => {
65-
expect(
67+
await expect(
6668
consumer.commitOffsets([{ topic: topicName, partition: 0, offset: '-1' }])
6769
).rejects.toThrow(KafkaJSNonRetriableError, 'Offset must not be a negative number')
6870
})
6971

7072
it('throws an error if called before consumer run', async () => {
71-
expect(
73+
await expect(
7274
consumer.commitOffsets([{ topic: topicName, partition: 0, offset: '1' }])
7375
).rejects.toThrow(
7476
KafkaJSNonRetriableError,

src/consumer/__tests__/runner.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('Consumer > Runner', () => {
268268
throw error
269269
})
270270

271-
expect(runner.commitOffsets(offsets)).rejects.toThrow(error.message)
271+
await expect(runner.commitOffsets(offsets)).rejects.toThrow(error.message)
272272
expect(consumerGroup.joinAndSync).toHaveBeenCalledTimes(0)
273273

274274
await sleep(100)
@@ -336,14 +336,14 @@ describe('Consumer > Runner', () => {
336336

337337
it('a triggered rejoin failing should cause a crash', async () => {
338338
const unknownError = new KafkaJSProtocolError(createErrorFromCode(UNKNOWN))
339-
consumerGroup.joinAndSync.mockImplementationOnce(() => {
339+
consumerGroup.joinAndSync.mockImplementationOnce(async () => {
340340
throw unknownError
341341
})
342-
consumerGroup.commitOffsets.mockImplementationOnce(() => {
342+
consumerGroup.commitOffsets.mockImplementationOnce(async () => {
343343
throw rebalancingError()
344344
})
345345

346-
expect(runner.commitOffsets(offsets)).rejects.toThrow(rebalancingError().message)
346+
await expect(runner.commitOffsets(offsets)).rejects.toThrow(rebalancingError().message)
347347

348348
await sleep(100)
349349

src/consumer/batch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = class Batch {
4242
}
4343

4444
/**
45-
* If the batch contained raw messages (i.e was not truely empty) but all messages were filtered out due to
45+
* If the batch contained raw messages (i.e was not truly empty) but all messages were filtered out due to
4646
* log compaction, control records or other reasons
4747
*/
4848
isEmptyDueToFiltering() {

src/network/requestQueue/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('Network > RequestQueue', () => {
196196
}
197197
})
198198

199-
expect(requestQueue.canSendSocketRequestImmediately())
199+
expect(requestQueue.canSendSocketRequestImmediately()).toBe(true)
200200

201201
const before = Date.now()
202202
const throttledUntilBefore = requestQueue.throttledUntil

src/utils/waitFor.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('Utils > waitFor', () => {
88
conditionValid = true
99
}, 6)
1010

11-
await expect(waitFor(() => conditionValid, { delay: 5 }))
11+
await expect(waitFor(() => conditionValid, { delay: 5 })).resolves.toBe(true)
1212
})
1313

1414
it('rejects the promise if the callback fail', async () => {

testHelpers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable jest/valid-describe-callback */
2+
// Disabled to allow for higher order test functions where
3+
// `callback` is parameterized instead of a static function
14
const fs = require('fs')
25
const execa = require('execa')
36
const uuid = require('uuid/v4')

0 commit comments

Comments
 (0)