From a8f0dbe4ba9727e34e642d1bcdddbecb371fe106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 6 Jul 2024 10:50:59 +0300 Subject: [PATCH 1/2] update to v5 (#124) * update to v5 fix workflow version fix field name pre-commit fix field test update update tap update update update update ci update npm update npm fix tests fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test fix test * add workflow * add workflow * add workflow --- .github/workflows/ci.yml | 87 ++--------------------------------- .taprc | 3 +- docker-compose.yml | 21 --------- package.json | 3 +- test/communication.test.js | 6 ++- test/consume-callback.test.js | 6 ++- test/consumer.test.js | 20 ++++++-- test/multiple-topics.test.js | 18 ++++++-- test/producer.test.js | 15 ++++-- 9 files changed, 54 insertions(+), 125 deletions(-) delete mode 100644 docker-compose.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 753d863..911ec8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,6 @@ name: CI on: push: - branches: - - main - - master - - next - - 'v*' paths-ignore: - 'docs/**' - '*.md' @@ -16,83 +11,11 @@ on: - '*.md' jobs: - dependency-review: - name: Dependency Review - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Check out repo - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Dependency review - uses: actions/dependency-review-action@v4 - - linter: - name: Lint Code - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Check out repo - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: lts/* - - - name: Install dependencies - run: npm i --ignore-scripts - - - name: Lint code - run: npm run lint - test: - runs-on: ubuntu-latest permissions: - contents: read - strategy: - matrix: - node-version: [14, 16, 18, 20] - steps: - - name: Check out repo - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Setup Node ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - - name: Start Kafka-instance - run: | - docker-compose up -d - - - name: Install dependencies - run: npm i - - - name: Run tests - run: npm test - - automerge: - name: Automerge Dependabot PRs - if: > - github.event_name == 'pull_request' && - github.event.pull_request.user.login == 'dependabot[bot]' - needs: test - permissions: - pull-requests: write contents: write - runs-on: ubuntu-latest - steps: - - uses: fastify/github-action-merge-dependabot@v3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - target: major + pull-requests: write + uses: fastify/workflows/.github/workflows/plugins-ci-kafka.yml@v5.0.0 + with: + license-check: true + lint: true diff --git a/.taprc b/.taprc index 4f1041a..343ddd5 100644 --- a/.taprc +++ b/.taprc @@ -1,4 +1,3 @@ -check-coverage: false - +disable-coverage: true files: - test/**/*.test.js diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 355c21d..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: "3.9" -services: - zookeeper: - image: confluentinc/cp-zookeeper - ports: - - "2181:2181" - environment: - ZOOKEEPER_CLIENT_PORT: 2181 - ZOOKEEPER_TICK_TIME: 2000 - kafka: - image: confluentinc/cp-kafka - links: - - zookeeper - ports: - - "9092:9092" - environment: - KAFKA_BROKER_ID: 1 - KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' - KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://localhost:9092' - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 diff --git a/package.json b/package.json index 8899a29..7b50f39 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "node-rdkafka": "3.0.1" }, "devDependencies": { - "@types/node": "^20.1.4", + "@fastify/pre-commit": "^2.1.0", + "@types/node": "^20.14.9", "abstract-logging": "2.0.1", "fastify": "^5.0.0-alpha.3", "standard": "^17.0.0", diff --git a/test/communication.test.js b/test/communication.test.js index 1b7273d..a21d6ce 100644 --- a/test/communication.test.js +++ b/test/communication.test.js @@ -20,8 +20,10 @@ test('communication', t => { const producerFastify = Fastify({ logger: true }) const consumerFastify = Fastify({ logger: true }) - t.teardown(() => producerFastify.close()) - t.teardown(() => consumerFastify.close()) + t.after(() => { + producerFastify.close() + consumerFastify.close() + }) consumerFastify .register(fastifyKafka, { ...options, producer: undefined }) diff --git a/test/consume-callback.test.js b/test/consume-callback.test.js index 156cff1..e4d7452 100644 --- a/test/consume-callback.test.js +++ b/test/consume-callback.test.js @@ -16,8 +16,10 @@ test('consume callback', t => { const producerFastify = Fastify() const consumerFastify = Fastify() - t.teardown(() => producerFastify.close()) - t.teardown(() => consumerFastify.close()) + t.after(() => { + producerFastify.close() + consumerFastify.close() + }) consumerFastify .register(fastifyKafka, { ...options, producer: undefined }) diff --git a/test/consumer.test.js b/test/consumer.test.js index b1905ee..93f125d 100644 --- a/test/consumer.test.js +++ b/test/consumer.test.js @@ -17,7 +17,9 @@ test('unreachable brokers', t => { const consumer = new Consumer(options, log, (err) => { t.ok(err) }, {}, { timeout: 200 }) - consumer.on('ready', t.error) + consumer.on('ready', (e) => { + t.error(e) + }) }) test('error event before connection', t => { @@ -35,8 +37,12 @@ test('error event after connection', t => { t.error(err) consumer.consumer.emit('event.error', new Error('Test Error')) }) - consumer.on('error', t.ok) - t.teardown(() => consumer.stop()) + consumer.on('error', (s) => { + t.ok(s) + }) + t.after(() => { + consumer.stop() + }) }) test('empty message with data event', t => { @@ -46,6 +52,10 @@ test('empty message with data event', t => { t.error(err) t.throws(() => consumer.consumer.emit('data')) }) - consumer.on('error', t.ok) - t.teardown(() => consumer.stop()) + consumer.on('error', (s) => { + t.ok(s) + }) + t.after(() => { + consumer.stop() + }) }) diff --git a/test/multiple-topics.test.js b/test/multiple-topics.test.js index 23f75ea..2ad1c97 100644 --- a/test/multiple-topics.test.js +++ b/test/multiple-topics.test.js @@ -17,15 +17,14 @@ test('multiple topics', t => { const producerFastify = Fastify() const consumerFastify = Fastify() - t.teardown(() => producerFastify.close()) - t.teardown(() => consumerFastify.close()) - consumerFastify .register(fastifyKafka, { ...options, producer: undefined }) .after(err => { t.error(err) - consumerFastify.kafka.consumer.on('error', t.fail) + consumerFastify.kafka.consumer.on('error', () => { + t.fail() + }) consumerFastify.kafka.subscribe([topicName1, topicName2]) consumerFastify.kafka.on(topicName1, (msg, commit) => { @@ -48,7 +47,9 @@ test('multiple topics', t => { .after(err => { t.error(err) - producerFastify.kafka.producer.on('error', t.fail) + producerFastify.kafka.producer.on('error', () => { + t.fail() + }) producerFastify.kafka.push({ topic: topicName1, payload: 'topic1', @@ -70,4 +71,11 @@ test('multiple topics', t => { t.error(err) }) }) + + t.after(() => { + producerFastify.kafka.producer.stop() + consumerFastify.kafka.consumer.stop() + producerFastify.close() + consumerFastify.close() + }) }) diff --git a/test/producer.test.js b/test/producer.test.js index 9f11705..8ebc030 100644 --- a/test/producer.test.js +++ b/test/producer.test.js @@ -12,12 +12,13 @@ const options = { } test('unreachable brokers', t => { - t.plan(2) + t.plan(1) const producer = new Producer(options, log, (err) => { t.ok(err) - producer.on('error', t.ok) - producer.push() }, {}, { timeout: 200 }) + producer.on('ready', (e) => { + t.error(e) + }) }) test('error event before connection', t => { @@ -35,11 +36,15 @@ test('error event after connection', t => { t.error(err) producer.producer.emit('event.error', new Error('Test Error')) }) - producer.on('error', t.ok) + producer.on('error', (e) => { + t.ok(e) + }) producer.push({ topic: 'test', payload: 'hello world!', key: 'testKey' }) - t.teardown(() => producer.stop()) + t.after(() => { + producer.stop() + }) }) From a38a9788d3d996458e798746ffc317b1fe6149da Mon Sep 17 00:00:00 2001 From: James Sumners Date: Wed, 10 Jul 2024 07:03:30 -0400 Subject: [PATCH 2/2] update fastify deps --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7b50f39..43a4368 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,9 @@ "@types/node": "^20.14.9", "abstract-logging": "2.0.1", "fastify": "^5.0.0-alpha.3", - "standard": "^17.0.0", - "tap": "^16.0.0", - "tsd": "^0.31.0" + "standard": "^17.1.0", + "tap": "^20.0.3", + "tsd": "^0.31.1" }, "tsd": { "directory": "test"