Skip to content

Commit 68fbf19

Browse files
authored
BREAKING CHANGE: upgrade to fastify v5 (#30)
1 parent 27a5a76 commit 68fbf19

File tree

6 files changed

+39
-50
lines changed

6 files changed

+39
-50
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
contents: read
3737
strategy:
3838
matrix:
39-
node-version: [14, 16, 18, 20]
39+
node-version: [20, 22]
4040
services:
4141
opensearch:
42-
image: opensearchproject/opensearch:2.13.0
42+
image: opensearchproject/opensearch:2.19.0
4343
ports:
4444
- 9200:9200
4545
options: >-

.taprc

Lines changed: 0 additions & 2 deletions
This file was deleted.

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
opensearch:
3+
image: opensearchproject/opensearch:2.19.0
4+
ports:
5+
- 9200:9200
6+
environment:
7+
- discovery.type=single-node
8+
- DISABLE_SECURITY_PLUGIN=true

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function fastifyOpensearch (fastify, options) {
4040
}
4141

4242
module.exports = fp(fastifyOpensearch, {
43-
fastify: '4.x',
43+
fastify: '5.x',
4444
name: '@fastify/opensearch'
4545
})
4646
module.exports.default = fastifyOpensearch

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"scripts": {
99
"lint": "eslint",
1010
"lint:fix": "eslint --fix",
11+
"infra:up": "docker-compose up -d",
12+
"infra:down": "docker-compose down",
1113
"test": "npm run test:unit && npm run test:typescript",
12-
"test:unit": "tap",
14+
"test:unit": "c8 --100 node --test",
1315
"test:typescript": "tsd"
1416
},
1517
"repository": {
@@ -41,16 +43,16 @@
4143
}
4244
],
4345
"dependencies": {
44-
"@opensearch-project/opensearch": "^2.5.0",
45-
"fastify-plugin": "^4.0.0"
46+
"@opensearch-project/opensearch": "^3.3.0",
47+
"fastify-plugin": "^5.0.1"
4648
},
4749
"devDependencies": {
4850
"@fastify/pre-commit": "^2.0.2",
4951
"@types/node": "^22.0.0",
52+
"c8": "^10.1.3",
5053
"eslint": "^9.17.0",
51-
"fastify": "^4.0.0-rc.2",
54+
"fastify": "^5.2.1",
5255
"neostandard": "^0.12.0",
53-
"tap": "^16.0.0",
5456
"tsd": "^0.31.0"
5557
},
5658
"publishConfig": {

test/index.test.js

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,58 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const { Client } = require('@opensearch-project/opensearch')
55
const Fastify = require('fastify')
66
const fastifyOpensearch = require('..')
77
const isOpensearchClient = require('..').isOpensearchClient
88

99
test('with reachable cluster', async t => {
1010
const fastify = Fastify()
11-
t.teardown(() => fastify.close())
11+
t.after(() => fastify.close())
1212
fastify.register(fastifyOpensearch, { node: 'http://localhost:9200' })
1313

1414
await fastify.ready()
15-
t.equal(fastify.opensearch.name, 'opensearch-js')
15+
t.assert.deepStrictEqual(fastify.opensearch.name, 'opensearch-js')
1616
})
1717

18-
test('with unreachable cluster', async t => {
18+
test('with unreachable cluster', t => {
1919
const fastify = Fastify()
20-
t.teardown(() => fastify.close())
20+
t.after(() => fastify.close())
2121
fastify.register(fastifyOpensearch, { node: 'http://localhost:9201' })
2222

23-
try {
24-
await fastify.ready()
25-
t.fail('should not boot successfully')
26-
} catch (err) {
27-
t.ok(err)
28-
}
23+
return t.assert.rejects(fastify.ready())
2924
})
3025

3126
test('with unreachable cluster and healthcheck disabled', async t => {
3227
const fastify = Fastify()
33-
t.teardown(() => fastify.close())
28+
t.after(() => fastify.close())
3429
fastify.register(fastifyOpensearch, {
3530
node: 'http://localhost:9201',
3631
healthcheck: false
3732
})
3833

39-
try {
40-
await fastify.ready()
41-
t.equal(fastify.opensearch.name, 'opensearch-js')
42-
} catch {
43-
t.fail('should not error')
44-
}
34+
await fastify.ready()
35+
t.assert.deepStrictEqual(fastify.opensearch.name, 'opensearch-js')
4536
})
4637

4738
test('namespaced', async t => {
4839
const fastify = Fastify()
49-
t.teardown(() => fastify.close())
40+
t.after(() => fastify.close())
5041
fastify.register(fastifyOpensearch, {
5142
node: 'http://localhost:9200',
5243
namespace: 'cluster'
5344
})
5445

5546
await fastify.ready()
56-
t.strictEqual(fastify.opensearch.cluster.name, 'opensearch-js')
57-
t.equal(isOpensearchClient(fastify.opensearch), false)
58-
t.equal(isOpensearchClient(fastify.opensearch.cluster), true)
47+
t.assert.deepStrictEqual(fastify.opensearch.cluster.name, 'opensearch-js')
48+
t.assert.deepStrictEqual(isOpensearchClient(fastify.opensearch), false)
49+
t.assert.deepStrictEqual(isOpensearchClient(fastify.opensearch.cluster), true)
5950
await fastify.close()
6051
})
6152

6253
test('namespaced (errored)', async t => {
6354
const fastify = Fastify()
64-
t.teardown(() => fastify.close())
55+
t.after(() => fastify.close())
6556
fastify.register(fastifyOpensearch, {
6657
node: 'http://localhost:9200',
6758
namespace: 'cluster'
@@ -72,12 +63,7 @@ test('namespaced (errored)', async t => {
7263
namespace: 'cluster'
7364
})
7465

75-
try {
76-
await fastify.ready()
77-
t.fail('should not boot successfully')
78-
} catch (err) {
79-
t.ok(err)
80-
}
66+
await t.assert.rejects(fastify.ready())
8167
})
8268

8369
test('custom client', async t => {
@@ -87,24 +73,19 @@ test('custom client', async t => {
8773
})
8874

8975
const fastify = Fastify()
90-
t.teardown(() => fastify.close())
76+
t.after(() => fastify.close())
9177
fastify.register(fastifyOpensearch, { client })
9278

9379
await fastify.ready()
94-
t.equal(isOpensearchClient(fastify.opensearch), true)
95-
t.strictEqual(fastify.opensearch.name, 'custom')
80+
t.assert.deepStrictEqual(isOpensearchClient(fastify.opensearch), true)
81+
t.assert.deepStrictEqual(fastify.opensearch.name, 'custom')
9682
await fastify.close()
9783
})
9884

99-
test('Missing configuration', async t => {
85+
test('Missing configuration', t => {
10086
const fastify = Fastify()
101-
t.teardown(() => fastify.close())
87+
t.after(() => fastify.close())
10288
fastify.register(fastifyOpensearch)
10389

104-
try {
105-
await fastify.ready()
106-
t.fail('should not boot successfully')
107-
} catch (err) {
108-
t.ok(err)
109-
}
90+
return t.assert.rejects(fastify.ready())
11091
})

0 commit comments

Comments
 (0)