From b23e87dd980348114e89de81f87c1f4a4806fd04 Mon Sep 17 00:00:00 2001 From: Ajay Pillai Date: Wed, 11 Nov 2026 09:56:57 +0530 Subject: [PATCH 1/3] fix: skip redundant build before CommonJS TypeScript tests Remove the production build step from the generated CommonJS TypeScript test script. The test helper loads src/app.ts directly through ts-node, and the test TypeScript configuration already checks the application source without emitting files. Signed-off-by: Ajay Pillai --- generate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate.js b/generate.js index 535a13c3..d3f9996a 100755 --- a/generate.js +++ b/generate.js @@ -48,7 +48,7 @@ const typescriptTemplate = { main: 'app.ts', scripts: { clean: 'node -e "require(\'fs\').rmSync(\'dist\', {recursive: true, force: true})"', - test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"', + test: 'tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"', start: 'npm run build:ts && fastify start -l info dist/app.js', 'build:ts': 'npm run clean && tsc', 'watch:ts': 'tsc -w', From 4da92a7276a61fde48d55f901ba340897c2a614f Mon Sep 17 00:00:00 2001 From: AJAY PILLAI Date: Wed, 11 Nov 2026 10:36:14 +0530 Subject: [PATCH 2/3] fix: support TypeScript 6 in CommonJS app tests and builds Signed-off-by: AJAY PILLAI --- templates/app-ts/test/tsconfig.json | 2 +- templates/app-ts/tsconfig.json | 2 ++ test/generate-typescript.test.js | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/templates/app-ts/test/tsconfig.json b/templates/app-ts/test/tsconfig.json index 384d1712..d5c6e8ef 100644 --- a/templates/app-ts/test/tsconfig.json +++ b/templates/app-ts/test/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "baseUrl": ".", + "rootDir": "..", "noEmit": true }, "include": ["../src/**/*.ts", "**/*.ts"] diff --git a/templates/app-ts/tsconfig.json b/templates/app-ts/tsconfig.json index 50dd0995..15edbefd 100644 --- a/templates/app-ts/tsconfig.json +++ b/templates/app-ts/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "fastify-tsconfig", "compilerOptions": { + "types": ["node"], + "rootDir": "src", "outDir": "dist", "sourceMap": true }, diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index 80e52a38..18b8e1e1 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -103,7 +103,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(26 + Object.keys(expected).length) + t.plan(28 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -128,7 +128,7 @@ function define (t) { // by default this will be ISC but since we have a MIT licensed pkg file in upper dir, npm will set the license to MIT in this case // so for local tests we need to accept MIT as well t.assert.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.assert.strictEqual(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"') + t.assert.strictEqual(pkg.scripts.test, 'tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"') t.assert.strictEqual(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.assert.strictEqual(pkg.scripts.clean, 'node -e "require(\'fs\').rmSync(\'dist\', {recursive: true, force: true})"') t.assert.strictEqual(pkg.scripts['build:ts'], 'npm run clean && tsc') @@ -146,7 +146,7 @@ function define (t) { t.assert.strictEqual(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) t.assert.strictEqual(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) - const testGlob = pkg.scripts.test.split(' ', 14)[13].replaceAll('"', '') + const testGlob = pkg.scripts.test.split(' ').at(-1).replaceAll('"', '') t.assert.strictEqual(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1, 'should match glob') resolve() @@ -162,6 +162,8 @@ function define (t) { const tsConfig = JSON.parse(data) t.assert.strictEqual(tsConfig.extends, 'fastify-tsconfig') + t.assert.deepStrictEqual(tsConfig.compilerOptions.types, ['node']) + t.assert.strictEqual(tsConfig.compilerOptions.rootDir, 'src') t.assert.strictEqual(tsConfig.compilerOptions.outDir, 'dist') t.assert.deepStrictEqual(tsConfig.include, ['src/**/*.ts']) }) From c0781bc84c0ef3f770057aefea5ffd83ab86621a Mon Sep 17 00:00:00 2001 From: AJAY PILLAI Date: Wed, 11 Nov 2026 10:45:52 +0530 Subject: [PATCH 3/3] docs: explain CommonJS TypeScript test and build scripts Signed-off-by: AJAY PILLAI --- templates/app-ts/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/app-ts/README.md b/templates/app-ts/README.md index 2d5e417c..06390acb 100644 --- a/templates/app-ts/README.md +++ b/templates/app-ts/README.md @@ -16,7 +16,13 @@ For production mode ### `npm run test` -Run the test cases. +Type check the application source and tests, then run the test cases directly +against the TypeScript source without generating production files in `dist`. + +### `npm run build:ts` + +Compile the application source to `dist`. This production build runs independently +of the tests and is also run by `npm start`. ## Learn More