Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate from tap to node:test and c8 #117

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,3 @@ yarn.lock
# editor files
.vscode
.idea

#tap files
.tap/
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"lint": "standard",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:unit": "c8 --100 node --test",
"test:typescript": "tsd"
},
"repository": {
Expand All @@ -33,11 +33,11 @@
"fastify-plugin": "^5.0.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"c8": "^10.1.2",
"fastify": "^5.0.0",
"standard": "^17.1.0",
"tap": "^18.7.2",
"tsd": "^0.31.0"
},
"publishConfig": {
Expand Down
44 changes: 22 additions & 22 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { Client } = require('@elastic/elasticsearch')
const Fastify = require('fastify')
const fastifyElasticsearch = require('..')
const isElasticsearchClient = require('..').isElasticsearchClient

test('with reachable cluster', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, { node: 'http://localhost:9200' })

await fastify.ready()
t.equal(fastify.elastic.name, 'elasticsearch-js')
t.assert.equal(fastify.elastic.name, 'elasticsearch-js')
})

test('with unreachable cluster', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, { node: 'http://localhost:9201' })

try {
await fastify.ready()
t.fail('should not boot successfully')
t.assert.fail('should not boot successfully')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
})

test('with unreachable cluster and healthcheck disabled', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, {
node: 'http://localhost:9201',
healthcheck: false
})

try {
await fastify.ready()
t.equal(fastify.elastic.name, 'elasticsearch-js')
t.assert.equal(fastify.elastic.name, 'elasticsearch-js')
} catch (err) {
t.fail('should not error')
t.assert.fail('should not error')
}
})

test('namespaced', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, {
node: 'http://localhost:9200',
namespace: 'cluster'
})

await fastify.ready()
t.equal(fastify.elastic.cluster.name, 'elasticsearch-js')
t.equal(isElasticsearchClient(fastify.elastic), false)
t.equal(isElasticsearchClient(fastify.elastic.cluster), true)
t.assert.equal(fastify.elastic.cluster.name, 'elasticsearch-js')
t.assert.equal(isElasticsearchClient(fastify.elastic), false)
t.assert.equal(isElasticsearchClient(fastify.elastic.cluster), true)
await fastify.close()
})

test('namespaced (errored)', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, {
node: 'http://localhost:9200',
namespace: 'cluster'
Expand All @@ -74,9 +74,9 @@ test('namespaced (errored)', async t => {

try {
await fastify.ready()
t.fail('should not boot successfully')
t.assert.fail('should not boot successfully')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
})

Expand All @@ -87,24 +87,24 @@ test('custom client', async t => {
})

const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch, { client })

await fastify.ready()
t.equal(isElasticsearchClient(fastify.elastic), true)
t.equal(fastify.elastic.name, 'custom')
t.assert.equal(isElasticsearchClient(fastify.elastic), true)
t.assert.equal(fastify.elastic.name, 'custom')
await fastify.close()
})

test('Missing configuration', async t => {
const fastify = Fastify()
t.teardown(() => fastify.close())
t.after(() => fastify.close())
fastify.register(fastifyElasticsearch)

try {
await fastify.ready()
t.fail('should not boot successfully')
t.assert.fail('should not boot successfully')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
})