From e2411d5292779e5d26619fedec44ef820c0b6e6f Mon Sep 17 00:00:00 2001 From: Cristian Barlutiu Date: Mon, 18 Mar 2024 17:57:59 +0100 Subject: [PATCH] Update for Fastify v5 --- .github/workflows/ci.yml | 2 +- .taprc | 8 -------- package.json | 28 ++++++++++++++++------------ test/base.test.js | 22 +++++++++++++--------- 4 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 .taprc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0610c55..582175c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0 with: lint: true license-check: true diff --git a/.taprc b/.taprc deleted file mode 100644 index fec4f69..0000000 --- a/.taprc +++ /dev/null @@ -1,8 +0,0 @@ -ts: false -jsx: false -flow: false -coverage: true -jobs: 1 - -files: - - test/**/*.test.js diff --git a/package.json b/package.json index 587f0b1..53173dc 100644 --- a/package.json +++ b/package.json @@ -26,21 +26,21 @@ }, "homepage": "https://github.com/fastify/fastify-websocket#readme", "devDependencies": { - "@fastify/pre-commit": "^2.0.2", + "@fastify/pre-commit": "^2.1.0", "@fastify/type-provider-typebox": "^4.0.0", - "@types/node": "^20.1.0", - "@types/ws": "^8.2.2", - "fastify": "^4.25.0", + "@types/node": "^20.11.28", + "@types/ws": "^8.5.10", + "fastify": "^4.26.2", "fastify-tsconfig": "^2.0.0", - "split2": "^4.1.0", - "standard": "^17.0.0", - "tap": "^16.0.0", - "tsd": "^0.30.1" + "split2": "^4.2.0", + "standard": "^17.1.0", + "tap": "^18.7.1", + "tsd": "^0.30.7" }, "dependencies": { - "duplexify": "^4.1.2", - "fastify-plugin": "^4.0.0", - "ws": "^8.0.0" + "duplexify": "^4.1.3", + "fastify-plugin": "^4.5.1", + "ws": "^8.16.0" }, "publishConfig": { "access": "public" @@ -48,5 +48,9 @@ "pre-commit": [ "lint", "test" - ] + ], + "tap": { + "jobs": 1, + "files": ["test/**/*.test.js"] + } } diff --git a/test/base.test.js b/test/base.test.js index e03a14a..492006c 100644 --- a/test/base.test.js +++ b/test/base.test.js @@ -90,7 +90,6 @@ test('Should run custom errorHandler on wildcard route handler error', async (t) fastify.get('/*', { websocket: true }, (conn) => { conn.pipe(conn) - t.teardown(() => conn.destroy()) return Promise.reject(new Error('Fail')) }) @@ -98,11 +97,14 @@ test('Should run custom errorHandler on wildcard route handler error', async (t) const ws = new WebSocket('ws://localhost:' + fastify.server.address().port) const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' }) - t.teardown(() => client.destroy()) await p + + t.teardown(() => client.destroy()) }) test('Should run custom errorHandler on error inside websocket handler', async (t) => { + t.plan(1) + const fastify = Fastify() t.teardown(() => fastify.close()) @@ -122,29 +124,30 @@ test('Should run custom errorHandler on error inside websocket handler', async ( fastify.get('/', { websocket: true }, function wsHandler (conn) { conn.pipe(conn) - t.teardown(() => conn.destroy()) throw new Error('Fail') }) await fastify.listen({ port: 0 }) const ws = new WebSocket('ws://localhost:' + fastify.server.address().port) const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' }) - t.teardown(() => client.destroy()) await p + + t.teardown(() => client.destroy()) }) test('Should run custom errorHandler on error inside async websocket handler', async (t) => { + t.plan(1) + const fastify = Fastify() t.teardown(() => fastify.close()) let _resolve - const p = new Promise((resolve) => { - _resolve = resolve - }) + const promise = new Promise((resolve) => { _resolve = resolve }) const options = { errorHandler: function (error) { + console.log('Error received') t.equal(error.message, 'Fail') _resolve() } @@ -154,15 +157,16 @@ test('Should run custom errorHandler on error inside async websocket handler', a fastify.get('/', { websocket: true }, async function wsHandler (conn) { conn.pipe(conn) - t.teardown(() => conn.destroy()) throw new Error('Fail') }) await fastify.listen({ port: 0 }) const ws = new WebSocket('ws://localhost:' + fastify.server.address().port) const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' }) + + await promise + t.teardown(() => client.destroy()) - await p }) test('Should be able to pass custom options to websocket-stream', async (t) => {