From bc10ffa6f90df75b646cf1e5c67ccfb1df168946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBugs5382=E2=80=9D?= Date: Mon, 4 Mar 2024 17:07:03 -0500 Subject: [PATCH 1/3] feat: fastify-cli, vite, and typescript - small app and unit tests to test functionality --- test/vitest/basic/app.ts | 11 +++++++++ test/vitest/basic/foo/typescript.ts | 11 +++++++++ test/vitest/fastify-cli.test.ts | 37 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test/vitest/basic/app.ts create mode 100644 test/vitest/basic/foo/typescript.ts create mode 100644 test/vitest/fastify-cli.test.ts diff --git a/test/vitest/basic/app.ts b/test/vitest/basic/app.ts new file mode 100644 index 00000000..2988beaa --- /dev/null +++ b/test/vitest/basic/app.ts @@ -0,0 +1,11 @@ +import {FastifyInstance, FastifyServerOptions} from 'fastify' +import {join} from "path"; +const fastifyAutoLoad = require('../../../index') + +export default async (fastify: FastifyInstance, opts?: FastifyServerOptions) => { + void fastify.register(fastifyAutoLoad, { + dir: join(__dirname, 'foo') + }) + + return fastify +} diff --git a/test/vitest/basic/foo/typescript.ts b/test/vitest/basic/foo/typescript.ts new file mode 100644 index 00000000..637cfb3b --- /dev/null +++ b/test/vitest/basic/foo/typescript.ts @@ -0,0 +1,11 @@ +import { FastifyPluginCallback } from 'fastify' + +const plugin: FastifyPluginCallback = function (fastify, opts, next): void { + fastify.get('/typescript', (request, reply): void => { + reply.send({ script: 'type' }) + }) + + next() +} + +export default plugin diff --git a/test/vitest/fastify-cli.test.ts b/test/vitest/fastify-cli.test.ts new file mode 100644 index 00000000..eb57f9e0 --- /dev/null +++ b/test/vitest/fastify-cli.test.ts @@ -0,0 +1,37 @@ +'use strict' + +import { describe, test, expect, beforeEach, afterEach } from 'vitest' +import fastify, {FastifyInstance} from 'fastify' +import buildApp from './basic/app' + +let server: FastifyInstance + +beforeEach(async () => { + server = await buildApp(fastify(), {}) + await server.ready() +}) +afterEach(async () => { + // called once after all tests run + await server.close() +}) + +describe("vitest test suite using fastify-cli startup", function () { + + test("Test the root route", async function () { + const response = await server.inject({ + method: 'GET', + url: '/' + }) + expect(response.statusCode).toEqual(200) + expect(JSON.parse(response.payload)).toEqual({ hello: 'world' }) + }) + + test("Test /foo route", async function () { + const response = await server.inject({ + method: 'GET', + url: '/foo' + }) + expect(response.statusCode).toBe(200) + expect(JSON.parse(response.payload)).toEqual({ foo: 'foo' }) + }) +}) From 5d241a12a1200867d45ac85dbd8dd640a151d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBugs5382=E2=80=9D?= Date: Tue, 5 Mar 2024 19:07:09 -0500 Subject: [PATCH 2/3] test: update unit testing - testing with fastify-cli within itself fails, but outside of it works --- .taprc | 5 --- package.json | 44 ++++++++++---------- scripts/unit-typescript-esm.js | 1 + scripts/unit-typescript-swc-node-register.js | 1 + scripts/unit-typescript-swc.js | 1 + scripts/unit-typescript-tsm.js | 2 + test/vitest/basic/app.ts | 11 ----- test/vitest/basic/foo/typescript.ts | 11 ----- test/vitest/fastify-cli.test.ts | 37 ---------------- 9 files changed, 27 insertions(+), 86 deletions(-) delete mode 100644 .taprc delete mode 100644 test/vitest/basic/app.ts delete mode 100644 test/vitest/basic/foo/typescript.ts delete mode 100644 test/vitest/fastify-cli.test.ts diff --git a/.taprc b/.taprc deleted file mode 100644 index 2cc1400a..00000000 --- a/.taprc +++ /dev/null @@ -1,5 +0,0 @@ -ts: true -jsx: false -flow: false -coverage: true -check-coverage: false diff --git a/package.json b/package.json index 1b679b64..bd565a12 100644 --- a/package.json +++ b/package.json @@ -44,31 +44,31 @@ }, "homepage": "https://github.com/fastify/fastify-autoload#readme", "devDependencies": { - "@fastify/pre-commit": "^2.0.2", - "@fastify/url-data": "^5.0.0", - "@swc-node/register": "^1.5.1", - "@swc/core": "^1.2.129", + "@fastify/pre-commit": "^2.1.0", + "@fastify/url-data": "^5.4.0", + "@swc-node/register": "^1.8.0", + "@swc/core": "^1.4.2", "@swc/register": "^0.1.9", - "@types/jest": "^29.0.0", - "@types/node": "^20.1.0", - "@types/tap": "^15.0.5", - "fastify": "^4.0.0-rc.2", - "fastify-plugin": "^4.0.0", - "jest": "^28.1.3", + "@types/jest": "^29.5.12", + "@types/node": "^20.11.24", + "@types/tap": "^15.0.11", + "fastify": "^4.26.2", + "fastify-plugin": "^4.5.1", + "jest": "^29.7.0", "snazzy": "^9.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", - "ts-jest": "^28.0.7", - "ts-node": "^10.4.0", + "standard": "^17.1.0", + "tap": "^18.7.0", + "ts-jest": "^29.1.2", + "ts-node": "^10.9.2", "ts-node-dev": "^2.0.0", - "tsd": "^0.29.0", - "tsm": "^2.2.1", - "tsx": "^3.7.1", - "typescript": "^5.0.2", - "esbuild": "^0.19.2", - "esbuild-register": "^3.4.1", - "vite": "^5.0.0", - "vitest": "^0.34.1" + "tsd": "^0.30.7", + "tsm": "^2.3.0", + "tsx": "^4.7.1", + "typescript": "^5.3.3", + "esbuild": "^0.20.1", + "esbuild-register": "^3.5.0", + "vite": "^5.1.5", + "vitest": "^1.3.1" }, "dependencies": {}, "standard": { diff --git a/scripts/unit-typescript-esm.js b/scripts/unit-typescript-esm.js index d9d6caec..89e6c934 100644 --- a/scripts/unit-typescript-esm.js +++ b/scripts/unit-typescript-esm.js @@ -6,6 +6,7 @@ const args = [ 'tap', '--node-arg=--loader=ts-node/esm', '--node-arg=--experimental-specifier-resolution=node', + '--', '--no-coverage', 'test/typescript-esm/*.ts' ] diff --git a/scripts/unit-typescript-swc-node-register.js b/scripts/unit-typescript-swc-node-register.js index 2fbf7738..e8488bf8 100644 --- a/scripts/unit-typescript-swc-node-register.js +++ b/scripts/unit-typescript-swc-node-register.js @@ -5,6 +5,7 @@ const { exec } = require('node:child_process') const args = [ 'tap', '--node-arg=--require=@swc-node/register', + '--', '--no-coverage', 'test/typescript/*.ts' ] diff --git a/scripts/unit-typescript-swc.js b/scripts/unit-typescript-swc.js index 4648e021..d6efeb5c 100644 --- a/scripts/unit-typescript-swc.js +++ b/scripts/unit-typescript-swc.js @@ -5,6 +5,7 @@ const { exec } = require('node:child_process') const args = [ 'tap', '--node-arg=--require=@swc/register', + '--', '--no-coverage', 'test/typescript/*.ts' ] diff --git a/scripts/unit-typescript-tsm.js b/scripts/unit-typescript-tsm.js index f2eb48bc..9a24cb76 100644 --- a/scripts/unit-typescript-tsm.js +++ b/scripts/unit-typescript-tsm.js @@ -4,8 +4,10 @@ const { exec } = require('node:child_process') const args = [ 'tap', + '--', '--no-ts', '--node-arg=--require=tsm', + '--', '--no-coverage', 'test/typescript/*.ts' ] diff --git a/test/vitest/basic/app.ts b/test/vitest/basic/app.ts deleted file mode 100644 index 2988beaa..00000000 --- a/test/vitest/basic/app.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {FastifyInstance, FastifyServerOptions} from 'fastify' -import {join} from "path"; -const fastifyAutoLoad = require('../../../index') - -export default async (fastify: FastifyInstance, opts?: FastifyServerOptions) => { - void fastify.register(fastifyAutoLoad, { - dir: join(__dirname, 'foo') - }) - - return fastify -} diff --git a/test/vitest/basic/foo/typescript.ts b/test/vitest/basic/foo/typescript.ts deleted file mode 100644 index 637cfb3b..00000000 --- a/test/vitest/basic/foo/typescript.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { FastifyPluginCallback } from 'fastify' - -const plugin: FastifyPluginCallback = function (fastify, opts, next): void { - fastify.get('/typescript', (request, reply): void => { - reply.send({ script: 'type' }) - }) - - next() -} - -export default plugin diff --git a/test/vitest/fastify-cli.test.ts b/test/vitest/fastify-cli.test.ts deleted file mode 100644 index eb57f9e0..00000000 --- a/test/vitest/fastify-cli.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -'use strict' - -import { describe, test, expect, beforeEach, afterEach } from 'vitest' -import fastify, {FastifyInstance} from 'fastify' -import buildApp from './basic/app' - -let server: FastifyInstance - -beforeEach(async () => { - server = await buildApp(fastify(), {}) - await server.ready() -}) -afterEach(async () => { - // called once after all tests run - await server.close() -}) - -describe("vitest test suite using fastify-cli startup", function () { - - test("Test the root route", async function () { - const response = await server.inject({ - method: 'GET', - url: '/' - }) - expect(response.statusCode).toEqual(200) - expect(JSON.parse(response.payload)).toEqual({ hello: 'world' }) - }) - - test("Test /foo route", async function () { - const response = await server.inject({ - method: 'GET', - url: '/foo' - }) - expect(response.statusCode).toBe(200) - expect(JSON.parse(response.payload)).toEqual({ foo: 'foo' }) - }) -}) From e003c0621c8b73453b05664bb9828390ef015003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBugs5382=E2=80=9D?= Date: Thu, 7 Mar 2024 09:08:22 -0500 Subject: [PATCH 3/3] feat: remove type/tap --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index bd565a12..66a6f30b 100644 --- a/package.json +++ b/package.json @@ -51,13 +51,12 @@ "@swc/register": "^0.1.9", "@types/jest": "^29.5.12", "@types/node": "^20.11.24", - "@types/tap": "^15.0.11", "fastify": "^4.26.2", "fastify-plugin": "^4.5.1", "jest": "^29.7.0", "snazzy": "^9.0.0", "standard": "^17.1.0", - "tap": "^18.7.0", + "tap": "^18.0.0", "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "ts-node-dev": "^2.0.0",