From cabce0fd09f6528f63f9780bed4fb175f2035319 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:14:10 +0100 Subject: [PATCH 01/37] feat: move template tests to node:test --- templates/app-esm/test/plugins/support.test.js | 7 ++++--- templates/app-esm/test/routes/example.test.js | 5 +++-- templates/app-esm/test/routes/root.test.js | 5 +++-- templates/app-ts-esm/test/helper.ts | 8 ++++---- templates/app-ts-esm/test/plugins/support.test.ts | 5 +++-- templates/app-ts-esm/test/routes/example.test.ts | 5 +++-- templates/app-ts-esm/test/routes/root.test.ts | 7 ++++--- templates/app-ts/test/helper.ts | 8 ++++---- templates/app-ts/test/plugins/support.test.ts | 6 ++++-- templates/app-ts/test/routes/example.test.ts | 5 +++-- templates/app-ts/test/routes/root.test.ts | 7 ++++--- templates/app/test/helper.js | 4 ++-- templates/app/test/plugins/support.test.js | 8 +++++--- templates/app/test/routes/example.test.js | 7 ++++--- templates/app/test/routes/root.test.js | 8 ++++---- templates/plugin/test/index.test.js | 7 +++---- 16 files changed, 57 insertions(+), 45 deletions(-) diff --git a/templates/app-esm/test/plugins/support.test.js b/templates/app-esm/test/plugins/support.test.js index e35dee6b..c4297e84 100644 --- a/templates/app-esm/test/plugins/support.test.js +++ b/templates/app-esm/test/plugins/support.test.js @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import Fastify from 'fastify' import Support from '../../plugins/support.js' @@ -7,7 +8,7 @@ test('support works standalone', async (t) => { fastify.register(Support) await fastify.ready() - t.equal(fastify.someSupport(), 'hugs') + assert.equal(fastify.someSupport(), 'hugs') }) // You can also use plugin with opts in fastify v2 @@ -19,6 +20,6 @@ test('support works standalone', async (t) => { // // fastify.ready((err) => { // t.error(err) -// t.equal(fastify.someSupport(), 'hugs') +// assert.equal(fastify.someSupport(), 'hugs') // }) // }) diff --git a/templates/app-esm/test/routes/example.test.js b/templates/app-esm/test/routes/example.test.js index d3317717..890e13e4 100644 --- a/templates/app-esm/test/routes/example.test.js +++ b/templates/app-esm/test/routes/example.test.js @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper.js' test('example is loaded', async (t) => { @@ -7,5 +8,5 @@ test('example is loaded', async (t) => { const res = await app.inject({ url: '/example' }) - t.equal(res.payload, 'this is an example') + assert.equal(res.payload, 'this is an example') }) diff --git a/templates/app-esm/test/routes/root.test.js b/templates/app-esm/test/routes/root.test.js index a2378ac8..743b610d 100644 --- a/templates/app-esm/test/routes/root.test.js +++ b/templates/app-esm/test/routes/root.test.js @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper.js' test('default root route', async (t) => { @@ -7,5 +8,5 @@ test('default root route', async (t) => { const res = await app.inject({ url: '/' }) - t.same(JSON.parse(res.payload), { root: true }) + assert.deepStrictEqual(JSON.parse(res.payload), { root: true }) }) diff --git a/templates/app-ts-esm/test/helper.ts b/templates/app-ts-esm/test/helper.ts index 3c3a6eba..4210f2b6 100644 --- a/templates/app-ts-esm/test/helper.ts +++ b/templates/app-ts-esm/test/helper.ts @@ -1,11 +1,11 @@ // This file contains code that we reuse between our tests. +import * as test from 'node:test'; import helper from 'fastify-cli/helper.js' import path from 'path' -import tap from 'tap'; import { fileURLToPath } from 'url' -export type Test = typeof tap['Test']['prototype']; +export type AfterFn = typeof test.after['prototype']; const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) @@ -18,7 +18,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (t: Test) { +async function build (after: AfterFn) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -28,7 +28,7 @@ async function build (t: Test) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - t.teardown(() => void app.close()) + after(() => void app.close()) return app } diff --git a/templates/app-ts-esm/test/plugins/support.test.ts b/templates/app-ts-esm/test/plugins/support.test.ts index 63725f79..c10957ba 100644 --- a/templates/app-ts-esm/test/plugins/support.test.ts +++ b/templates/app-ts-esm/test/plugins/support.test.ts @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import Fastify from 'fastify' import Support from '../../src/plugins/support.js' @@ -7,5 +8,5 @@ test('support works standalone', async (t) => { void fastify.register(Support) await fastify.ready() - t.equal(fastify.someSupport(), 'hugs') + assert.equal(fastify.someSupport(), 'hugs') }) diff --git a/templates/app-ts-esm/test/routes/example.test.ts b/templates/app-ts-esm/test/routes/example.test.ts index 63279968..87f26ab7 100644 --- a/templates/app-ts-esm/test/routes/example.test.ts +++ b/templates/app-ts-esm/test/routes/example.test.ts @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper.js' test('example is loaded', async (t) => { @@ -8,5 +9,5 @@ test('example is loaded', async (t) => { url: '/example' }) - t.equal(res.payload, 'this is an example') + assert.equal(res.payload, 'this is an example') }) diff --git a/templates/app-ts-esm/test/routes/root.test.ts b/templates/app-ts-esm/test/routes/root.test.ts index a2378ac8..9b27c414 100644 --- a/templates/app-ts-esm/test/routes/root.test.ts +++ b/templates/app-ts-esm/test/routes/root.test.ts @@ -1,11 +1,12 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper.js' test('default root route', async (t) => { - const app = await build(t) + const app = await build(t.after) const res = await app.inject({ url: '/' }) - t.same(JSON.parse(res.payload), { root: true }) + assert.deepStrictEqual(JSON.parse(res.payload), { root: true }) }) diff --git a/templates/app-ts/test/helper.ts b/templates/app-ts/test/helper.ts index 849731b7..89096a26 100644 --- a/templates/app-ts/test/helper.ts +++ b/templates/app-ts/test/helper.ts @@ -1,9 +1,9 @@ // This file contains code that we reuse between our tests. const helper = require('fastify-cli/helper.js') import * as path from 'path' -import * as tap from 'tap'; +import * as test from 'node:test'; -export type Test = typeof tap['Test']['prototype']; +export type AfterFn = typeof test.after['prototype']; const AppPath = path.join(__dirname, '..', 'src', 'app.ts') @@ -14,7 +14,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (t: Test) { +async function build (after: AfterFn) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -24,7 +24,7 @@ async function build (t: Test) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - t.teardown(() => void app.close()) + after(() => void app.close()) return app } diff --git a/templates/app-ts/test/plugins/support.test.ts b/templates/app-ts/test/plugins/support.test.ts index d67c06a1..d3b5c468 100644 --- a/templates/app-ts/test/plugins/support.test.ts +++ b/templates/app-ts/test/plugins/support.test.ts @@ -1,4 +1,6 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' + import Fastify from 'fastify' import Support from '../../src/plugins/support' @@ -7,5 +9,5 @@ test('support works standalone', async (t) => { void fastify.register(Support) await fastify.ready() - t.equal(fastify.someSupport(), 'hugs') + assert.equal(fastify.someSupport(), 'hugs') }) diff --git a/templates/app-ts/test/routes/example.test.ts b/templates/app-ts/test/routes/example.test.ts index 4db7e941..0c35dfef 100644 --- a/templates/app-ts/test/routes/example.test.ts +++ b/templates/app-ts/test/routes/example.test.ts @@ -1,4 +1,5 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper' test('example is loaded', async (t) => { @@ -8,5 +9,5 @@ test('example is loaded', async (t) => { url: '/example' }) - t.equal(res.payload, 'this is an example') + assert.equal(res.payload, 'this is an example') }) diff --git a/templates/app-ts/test/routes/root.test.ts b/templates/app-ts/test/routes/root.test.ts index 902b0f9a..75184e17 100644 --- a/templates/app-ts/test/routes/root.test.ts +++ b/templates/app-ts/test/routes/root.test.ts @@ -1,11 +1,12 @@ -import { test } from 'tap' +import { test } from 'node:test' +import * as assert from 'node:assert' import { build } from '../helper' test('default root route', async (t) => { - const app = await build(t) + const app = await build(t.after) const res = await app.inject({ url: '/' }) - t.same(JSON.parse(res.payload), { root: true }) + assert.deepStrictEqual(JSON.parse(res.payload), { root: true }) }) diff --git a/templates/app/test/helper.js b/templates/app/test/helper.js index 67c3fe4d..57d02a92 100644 --- a/templates/app/test/helper.js +++ b/templates/app/test/helper.js @@ -23,8 +23,8 @@ async function build (t) { // different from the production setup const app = await buildApplication(argv, config()) - // tear down our app after we are done - t.teardown(app.close.bind(app)) + //close the app after we are done + t.after(() => app.close()) return app } diff --git a/templates/app/test/plugins/support.test.js b/templates/app/test/plugins/support.test.js index 0019787f..e71ad244 100644 --- a/templates/app/test/plugins/support.test.js +++ b/templates/app/test/plugins/support.test.js @@ -1,6 +1,8 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') +const assert = require('node:assert') + const Fastify = require('fastify') const Support = require('../../plugins/support') @@ -9,7 +11,7 @@ test('support works standalone', async (t) => { fastify.register(Support) await fastify.ready() - t.equal(fastify.someSupport(), 'hugs') + assert.equal(fastify.someSupport(), 'hugs') }) // You can also use plugin with opts in fastify v2 @@ -21,6 +23,6 @@ test('support works standalone', async (t) => { // // fastify.ready((err) => { // t.error(err) -// t.equal(fastify.someSupport(), 'hugs') +// assert.equal(fastify.someSupport(), 'hugs') // }) // }) diff --git a/templates/app/test/routes/example.test.js b/templates/app/test/routes/example.test.js index 11cb01a6..4909a3a2 100644 --- a/templates/app/test/routes/example.test.js +++ b/templates/app/test/routes/example.test.js @@ -1,6 +1,7 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') +const assert = require('node:assert') const { build } = require('../helper') test('example is loaded', async (t) => { @@ -9,7 +10,7 @@ test('example is loaded', async (t) => { const res = await app.inject({ url: '/example' }) - t.equal(res.payload, 'this is an example') + assert.equal(res.payload, 'this is an example') }) // inject callback style: @@ -22,6 +23,6 @@ test('example is loaded', async (t) => { // url: '/example' // }, (err, res) => { // t.error(err) -// t.equal(res.payload, 'this is an example') +// assert.equal(res.payload, 'this is an example') // }) // }) diff --git a/templates/app/test/routes/root.test.js b/templates/app/test/routes/root.test.js index f4d3b19b..b287043b 100644 --- a/templates/app/test/routes/root.test.js +++ b/templates/app/test/routes/root.test.js @@ -1,7 +1,7 @@ 'use strict' -const { test } = require('tap') -const { build } = require('../helper') +const { test } = require('node:test') +const assert = require('node:assert') test('default root route', async (t) => { const app = await build(t) @@ -9,7 +9,7 @@ test('default root route', async (t) => { const res = await app.inject({ url: '/' }) - t.same(JSON.parse(res.payload), { root: true }) + assert.deepStrictEqual(JSON.parse(res.payload), { root: true }) }) // inject callback style: @@ -22,6 +22,6 @@ test('default root route', async (t) => { // url: '/' // }, (err, res) => { // t.error(err) -// t.same(JSON.parse(res.payload), { root: true }) +// assert.deepStrictEqual(JSON.parse(res.payload), { root: true }) // }) // }) diff --git a/templates/plugin/test/index.test.js b/templates/plugin/test/index.test.js index 5d004a0c..f66166b5 100644 --- a/templates/plugin/test/index.test.js +++ b/templates/plugin/test/index.test.js @@ -1,15 +1,14 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') +const assert = require('node:assert') test('should register the correct decorator', async t => { - t.plan(1) - const app = require('fastify')() app.register(require('..')) await app.ready() - t.same(app.exampleDecorator(), 'decorated') + assert.equal(app.exampleDecorator(), 'decorated') }) From 509e1d819a81e37b0f4dd7433f58eba45e004442 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:16:45 +0100 Subject: [PATCH 02/37] feat: remove tap dependency and fix tests --- generate.js | 4 +--- test/generate.test.js | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/generate.js b/generate.js index 6bc72f60..21df1887 100755 --- a/generate.js +++ b/generate.js @@ -28,9 +28,7 @@ const javascriptTemplate = { '@fastify/sensible': cliPkg.devDependencies['@fastify/sensible'], 'fastify-cli': '^' + cliPkg.version }, - devDependencies: { - tap: cliPkg.devDependencies.tap - }, + devDependencies: {}, logInstructions: function (pkg) { log('debug', 'saved package.json') log('info', `project ${pkg.name} generated successfully`) diff --git a/test/generate.test.js b/test/generate.test.js index 1ce62150..354941e3 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -106,7 +106,7 @@ function define (t) { }) test('should finish succesfully with javascript template', async (t) => { - t.plan(14 + Object.keys(expected).length) + t.plan(13 + Object.keys(expected).length) try { await generate(workdir, javascriptTemplate) await verifyPkg(t) @@ -117,7 +117,7 @@ function define (t) { }) test('--integrate option will enhance preexisting package.json and overwrite preexisting files', async (t) => { - t.plan(14 + Object.keys(expected).length) + t.plan(13 + Object.keys(expected).length) try { await generate(workdir, javascriptTemplate) await pUnlink(path.join(workdir, 'package.json')) @@ -168,8 +168,7 @@ function define (t) { t.equal(pkg.dependencies['fastify-plugin'], cliPkg.devDependencies['fastify-plugin'] || cliPkg.dependencies['fastify-plugin']) t.equal(pkg.dependencies['@fastify/autoload'], cliPkg.devDependencies['@fastify/autoload']) t.equal(pkg.dependencies['@fastify/sensible'], cliPkg.devDependencies['@fastify/sensible']) - t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap) - + const testGlob = pkg.scripts.test.split(' ', 2)[1].replace(/"/g, '') t.equal(minimatch.match(['test/services/plugins/more/test/here/ok.test.js'], testGlob).length, 1) resolve() From 1f466278666fb078adbfb581aaf647b68257ba1b Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:19:25 +0100 Subject: [PATCH 03/37] feat: remove tap dependency for typescript --- generate.js | 1 - test/generate-typescript.test.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/generate.js b/generate.js index 21df1887..6141b6d0 100755 --- a/generate.js +++ b/generate.js @@ -67,7 +67,6 @@ const typescriptTemplate = { 'ts-node': cliPkg.devDependencies['ts-node'], concurrently: cliPkg.devDependencies.concurrently, 'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'], - tap: cliPkg.devDependencies.tap, typescript: cliPkg.devDependencies.typescript }, nodemonConfig: { diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index 29729d4f..c64ce3b4 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(25 + Object.keys(expected).length) + t.plan(24 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -140,7 +140,6 @@ function define (t) { t.equal(pkg.devDependencies['@types/node'], cliPkg.devDependencies['@types/node']) t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) - t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) const testGlob = pkg.scripts.test.split(' ', 11)[10].replace(/"/g, '') From c1583676c3b0d16ffcfd831bb7eb1f18618c5f8d Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:21:07 +0100 Subject: [PATCH 04/37] feat: remove tap in js/esm --- test/generate-esm.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/generate-esm.test.js b/test/generate-esm.test.js index 2440bf5e..b616e6f8 100644 --- a/test/generate-esm.test.js +++ b/test/generate-esm.test.js @@ -114,7 +114,7 @@ function define (t) { }) test('should finish successfully with ESM javascript template', async (t) => { - t.plan(14 + Object.keys(expected).length) + t.plan(13 + Object.keys(expected).length) try { await generate(workdir, javascriptTemplate) await verifyPkg(t) @@ -125,7 +125,7 @@ function define (t) { }) test('--integrate option will enhance preexisting package.json and overwrite preexisting files', async (t) => { - t.plan(14 + Object.keys(expected).length) + t.plan(13 + Object.keys(expected).length) try { await generate(workdir, javascriptTemplate) await pUnlink(path.join(workdir, 'package.json')) @@ -176,7 +176,6 @@ function define (t) { t.equal(pkg.dependencies['fastify-plugin'], cliPkg.devDependencies['fastify-plugin'] || cliPkg.dependencies['fastify-plugin']) t.equal(pkg.dependencies['@fastify/autoload'], cliPkg.devDependencies['@fastify/autoload']) t.equal(pkg.dependencies['@fastify/sensible'], cliPkg.devDependencies['@fastify/sensible']) - t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap) // Test for "type:module" t.equal(pkg.type, 'module') From 5e72f0291b64c6867d2068cfa0ee7d731dcc7e49 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:22:16 +0100 Subject: [PATCH 05/37] feat: remove tap in ts/esm --- test/generate-typescript-esm.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/generate-typescript-esm.test.js b/test/generate-typescript-esm.test.js index 8a7e7f11..0b450b9c 100644 --- a/test/generate-typescript-esm.test.js +++ b/test/generate-typescript-esm.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(25 + Object.keys(expected).length) + t.plan(24 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -140,7 +140,6 @@ function define (t) { t.equal(pkg.devDependencies['@types/node'], cliPkg.devDependencies['@types/node']) t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) - t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) const testGlob = pkg.scripts.test.split(' ', 11)[10].replace(/"/g, '') From 322271c3f80fa6fc279182cf8ebb0a63b52dbc18 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:26:02 +0100 Subject: [PATCH 06/37] feat: remove tap in plugin generator --- generate-plugin.js | 1 - test/generate-plugin.test.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/generate-plugin.js b/generate-plugin.js index 5b8f1121..57b73393 100755 --- a/generate-plugin.js +++ b/generate-plugin.js @@ -33,7 +33,6 @@ const pluginTemplate = { fastify: cliPkg.devDependencies.fastify, 'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'], standard: cliPkg.devDependencies.standard, - tap: cliPkg.devDependencies.tap, 'ts-standard': cliPkg.devDependencies['ts-standard'], tsd: cliPkg.devDependencies.tsd, typescript: cliPkg.devDependencies.typescript diff --git a/test/generate-plugin.test.js b/test/generate-plugin.test.js index 8c92ee9e..1e84f95e 100644 --- a/test/generate-plugin.test.js +++ b/test/generate-plugin.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish succesfully', async (t) => { - t.plan(19 + Object.keys(expected).length) + t.plan(18 + Object.keys(expected).length) try { await generate(workdir, pluginTemplate) await verifyPkg(t) @@ -134,7 +134,6 @@ function define (t) { t.equal(pkg.devDependencies['@types/node'], cliPkg.devDependencies['@types/node']) t.equal(pkg.devDependencies.fastify, cliPkg.devDependencies.fastify) t.equal(pkg.devDependencies.standard, cliPkg.devDependencies.standard) - t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap) t.equal(pkg.devDependencies.tsd, cliPkg.devDependencies.tsd) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) t.same(pkg.tsd, pluginTemplate.tsd) From ed1ba7f749d73feea87d4ee325b0122dd290dfb4 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 08:30:34 +0100 Subject: [PATCH 07/37] fix: node:test test script is generated --- generate.js | 4 +--- test/generate.test.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/generate.js b/generate.js index 6141b6d0..a82daca2 100755 --- a/generate.js +++ b/generate.js @@ -17,7 +17,7 @@ const javascriptTemplate = { dir: 'app', main: 'app.js', scripts: { - test: 'tap "test/**/*.test.js"', + test: 'node --test test/**/*.test.js', start: 'fastify start -l info app.js', dev: 'fastify start -w -l info -P app.js' }, @@ -119,8 +119,6 @@ function generate (dir, template) { pkg.devDependencies = Object.assign(pkg.devDependencies || {}, template.devDependencies) - pkg.tap = template.tap - log('debug', 'edited package.json, saving') writeFile('package.json', JSON.stringify(pkg, null, 2), (err) => { if (err) { diff --git a/test/generate.test.js b/test/generate.test.js index 354941e3..59c3d04d 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -160,7 +160,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'tap "test/**/*.test.js"') + t.equal(pkg.scripts.test, 'node --test test/**/*.test.js') t.equal(pkg.scripts.start, 'fastify start -l info app.js') t.equal(pkg.scripts.dev, 'fastify start -w -l info -P app.js') t.equal(pkg.dependencies['fastify-cli'], '^' + cliPkg.version) @@ -169,7 +169,7 @@ function define (t) { t.equal(pkg.dependencies['@fastify/autoload'], cliPkg.devDependencies['@fastify/autoload']) t.equal(pkg.dependencies['@fastify/sensible'], cliPkg.devDependencies['@fastify/sensible']) - const testGlob = pkg.scripts.test.split(' ', 2)[1].replace(/"/g, '') + const testGlob = pkg.scripts.test.split(' ', 3)[2] t.equal(minimatch.match(['test/services/plugins/more/test/here/ok.test.js'], testGlob).length, 1) resolve() }) From 861ef0057851ea778239c28d475830a7ea89cc1f Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 09:55:32 +0100 Subject: [PATCH 08/37] feat: tsx runner for native ts tests --- generate.js | 5 +++-- package.json | 1 + templates/app-ts/test/helper.ts | 7 +++---- templates/app-ts/test/routes/example.test.ts | 2 +- templates/app-ts/test/routes/root.test.ts | 2 +- test/generate-typescript.test.js | 8 +++++--- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/generate.js b/generate.js index a82daca2..f39bc73c 100755 --- a/generate.js +++ b/generate.js @@ -47,7 +47,7 @@ const typescriptTemplate = { dir: 'app-ts', main: 'app.ts', scripts: { - test: 'npm run build:ts && tsc -p test/tsconfig.json && tap --ts "test/**/*.test.ts"', + test: 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts', start: 'npm run build:ts && fastify start -l info dist/app.js', 'build:ts': 'tsc', 'watch:ts': 'tsc -w', @@ -67,7 +67,8 @@ const typescriptTemplate = { 'ts-node': cliPkg.devDependencies['ts-node'], concurrently: cliPkg.devDependencies.concurrently, 'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'], - typescript: cliPkg.devDependencies.typescript + typescript: cliPkg.devDependencies.typescript, + tsx: cliPkg.devDependencies.tsx }, nodemonConfig: { watch: ['src/'], diff --git a/package.json b/package.json index 9589b51c..af4e353d 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "ts-node": "^10.4.0", "ts-standard": "^12.0.1", "tsd": "^0.28.0", + "tsx": "^4.5.0", "typescript": "^5.2.2", "walker": "^1.0.8" }, diff --git a/templates/app-ts/test/helper.ts b/templates/app-ts/test/helper.ts index 89096a26..8f986d41 100644 --- a/templates/app-ts/test/helper.ts +++ b/templates/app-ts/test/helper.ts @@ -1,9 +1,8 @@ // This file contains code that we reuse between our tests. const helper = require('fastify-cli/helper.js') import * as path from 'path' -import * as test from 'node:test'; -export type AfterFn = typeof test.after['prototype']; +export type TeardownFn = (after: () => void) => void; const AppPath = path.join(__dirname, '..', 'src', 'app.ts') @@ -14,7 +13,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (after: AfterFn) { +async function build (teardown: TeardownFn) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -24,7 +23,7 @@ async function build (after: AfterFn) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - after(() => void app.close()) + teardown(() => void app.close()) return app } diff --git a/templates/app-ts/test/routes/example.test.ts b/templates/app-ts/test/routes/example.test.ts index 0c35dfef..b62c65c6 100644 --- a/templates/app-ts/test/routes/example.test.ts +++ b/templates/app-ts/test/routes/example.test.ts @@ -3,7 +3,7 @@ import * as assert from 'node:assert' import { build } from '../helper' test('example is loaded', async (t) => { - const app = await build(t) + const app = await build(() => t.after()) const res = await app.inject({ url: '/example' diff --git a/templates/app-ts/test/routes/root.test.ts b/templates/app-ts/test/routes/root.test.ts index 75184e17..7f84d281 100644 --- a/templates/app-ts/test/routes/root.test.ts +++ b/templates/app-ts/test/routes/root.test.ts @@ -3,7 +3,7 @@ import * as assert from 'node:assert' import { build } from '../helper' test('default root route', async (t) => { - const app = await build(t.after) + const app = await build(() => t.after()) const res = await app.inject({ url: '/' diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index c64ce3b4..a1005d33 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(24 + Object.keys(expected).length) + t.plan(25 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -126,7 +126,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tap --ts "test/**/*.test.ts"') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -141,8 +141,10 @@ function define (t) { t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) + t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) - const testGlob = pkg.scripts.test.split(' ', 11)[10].replace(/"/g, '') + // bcs minimatch doesn't know about test/*/*.ts type of globs + const testGlob = pkg.scripts.test.split(' ', 11)[10].replace('*', '**') t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) resolve() From dbdeeb82f3d882027bbed78d76df7e181267163d Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 10:20:57 +0100 Subject: [PATCH 09/37] fix: teardown types --- templates/app-ts-esm/test/helper.ts | 11 ++++++----- templates/app-ts-esm/test/routes/root.test.ts | 2 +- templates/app-ts/test/helper.ts | 9 ++++++--- templates/app-ts/test/routes/root.test.ts | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/templates/app-ts-esm/test/helper.ts b/templates/app-ts-esm/test/helper.ts index 4210f2b6..9204d99d 100644 --- a/templates/app-ts-esm/test/helper.ts +++ b/templates/app-ts-esm/test/helper.ts @@ -1,11 +1,12 @@ // This file contains code that we reuse between our tests. -import * as test from 'node:test'; import helper from 'fastify-cli/helper.js' +import * as test from 'node:test' import path from 'path' import { fileURLToPath } from 'url' - -export type AfterFn = typeof test.after['prototype']; +export type TestContext = { + after: typeof test.after +}; const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) @@ -18,7 +19,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (after: AfterFn) { +async function build (t: TestContext) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -28,7 +29,7 @@ async function build (after: AfterFn) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - after(() => void app.close()) + t.after(() => void app.close()) return app } diff --git a/templates/app-ts-esm/test/routes/root.test.ts b/templates/app-ts-esm/test/routes/root.test.ts index 9b27c414..743b610d 100644 --- a/templates/app-ts-esm/test/routes/root.test.ts +++ b/templates/app-ts-esm/test/routes/root.test.ts @@ -3,7 +3,7 @@ import * as assert from 'node:assert' import { build } from '../helper.js' test('default root route', async (t) => { - const app = await build(t.after) + const app = await build(t) const res = await app.inject({ url: '/' diff --git a/templates/app-ts/test/helper.ts b/templates/app-ts/test/helper.ts index 8f986d41..70451775 100644 --- a/templates/app-ts/test/helper.ts +++ b/templates/app-ts/test/helper.ts @@ -1,8 +1,11 @@ // This file contains code that we reuse between our tests. const helper = require('fastify-cli/helper.js') import * as path from 'path' +import * as test from 'node:test' -export type TeardownFn = (after: () => void) => void; +export type TestContext = { + after: typeof test.after +}; const AppPath = path.join(__dirname, '..', 'src', 'app.ts') @@ -13,7 +16,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (teardown: TeardownFn) { +async function build (t: TestContext) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -23,7 +26,7 @@ async function build (teardown: TeardownFn) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - teardown(() => void app.close()) + t.after(() => void app.close()) return app } diff --git a/templates/app-ts/test/routes/root.test.ts b/templates/app-ts/test/routes/root.test.ts index 7f84d281..17554ecc 100644 --- a/templates/app-ts/test/routes/root.test.ts +++ b/templates/app-ts/test/routes/root.test.ts @@ -3,7 +3,7 @@ import * as assert from 'node:assert' import { build } from '../helper' test('default root route', async (t) => { - const app = await build(() => t.after()) + const app = await build(t) const res = await app.inject({ url: '/' From 67ca2f41ba73db081aeae283071a66976f06ad3d Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 10:41:51 +0100 Subject: [PATCH 10/37] fix: removes tap in esm --- generate.js | 16 ++-------------- test/generate-esm.test.js | 7 ++----- test/generate-typescript-esm.test.js | 7 ++++--- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/generate.js b/generate.js index f39bc73c..b01d47ef 100755 --- a/generate.js +++ b/generate.js @@ -160,18 +160,9 @@ function cli (args) { if (opts.esm) { template.dir = 'app-ts-esm' template.type = 'module' - template.tap = { - 'node-arg': [ - '--no-warnings', - '--experimental-loader', - 'ts-node/esm' - ], - coverage: false - } - // For coverage, NYC with Typescript ESM doesn't work https://github.com/tapjs/node-tap/issues/735 template.devDependencies.c8 = cliPkg.devDependencies.c8 - template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && c8 tap --ts "test/**/*.test.ts"' + template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/**/*.test.ts && c8 report' } } else { template = { ...javascriptTemplate } @@ -179,12 +170,9 @@ function cli (args) { if (opts.esm) { template.dir = 'app-esm' template.type = 'module' - template.tap = { - coverage: false - } template.devDependencies.c8 = cliPkg.devDependencies.c8 - template.scripts.test = 'c8 tap "test/**/*.test.js"' + template.scripts.test = 'node --test test/**/*.test.js' } if (opts.standardlint) { diff --git a/test/generate-esm.test.js b/test/generate-esm.test.js index b616e6f8..c742cdc2 100644 --- a/test/generate-esm.test.js +++ b/test/generate-esm.test.js @@ -30,11 +30,8 @@ const initVersion = execSync('npm get init-version').toString().trim() javascriptTemplate.dir = 'app-esm' javascriptTemplate.type = 'module' -javascriptTemplate.tap = { - coverage: false -} javascriptTemplate.devDependencies.c8 = cliPkg.devDependencies.c8 -javascriptTemplate.scripts.test = 'c8 tap "test/**/*.test.js"' +javascriptTemplate.scripts.test = 'node --test test/**/*.test.js' ;(function (cb) { const files = [] @@ -168,7 +165,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'c8 tap "test/**/*.test.js"') + t.equal(pkg.scripts.test, javascriptTemplate.scripts.test) t.equal(pkg.scripts.start, 'fastify start -l info app.js') t.equal(pkg.scripts.dev, 'fastify start -w -l info -P app.js') t.equal(pkg.dependencies['fastify-cli'], '^' + cliPkg.version) diff --git a/test/generate-typescript-esm.test.js b/test/generate-typescript-esm.test.js index 0b450b9c..f4b6b753 100644 --- a/test/generate-typescript-esm.test.js +++ b/test/generate-typescript-esm.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(24 + Object.keys(expected).length) + t.plan(25 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -126,7 +126,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tap --ts "test/**/*.test.ts"') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -141,8 +141,9 @@ function define (t) { t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) + t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) - const testGlob = pkg.scripts.test.split(' ', 11)[10].replace(/"/g, '') + const testGlob = pkg.scripts.test.split(' ', 11)[10].replace('*', '**') t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) resolve() From d86d7553eaf1c08a73fd10d4381c55ef323db063 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 10:47:13 +0100 Subject: [PATCH 11/37] fix: missing import --- templates/app/test/routes/root.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/app/test/routes/root.test.js b/templates/app/test/routes/root.test.js index b287043b..6fac9fc1 100644 --- a/templates/app/test/routes/root.test.js +++ b/templates/app/test/routes/root.test.js @@ -2,6 +2,7 @@ const { test } = require('node:test') const assert = require('node:assert') +const { build } = require('../helper') test('default root route', async (t) => { const app = await build(t) From 9c1f7bba678ffa51dde4b7000b3a4aa06da2caeb Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 10:51:06 +0100 Subject: [PATCH 12/37] fix: teardown --- templates/app-esm/test/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/app-esm/test/helper.js b/templates/app-esm/test/helper.js index c4e02dad..a301bf24 100644 --- a/templates/app-esm/test/helper.js +++ b/templates/app-esm/test/helper.js @@ -26,7 +26,7 @@ async function build (t) { const app = await helper.build(argv, config()) // tear down our app after we are done - t.teardown(app.close.bind(app)) + t.after(() => app.close(app)) return app } From e49ba629f3fe7755a8cdcfdf13599773a3597086 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 10:53:03 +0100 Subject: [PATCH 13/37] fix: teardown esm --- templates/app-esm/test/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/app-esm/test/helper.js b/templates/app-esm/test/helper.js index a301bf24..6fb94119 100644 --- a/templates/app-esm/test/helper.js +++ b/templates/app-esm/test/helper.js @@ -26,7 +26,7 @@ async function build (t) { const app = await helper.build(argv, config()) // tear down our app after we are done - t.after(() => app.close(app)) + t.after(() => app.close()) return app } From b5e9ce6417cb49f0c38f295417652f7be7151cac Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 14:19:42 +0100 Subject: [PATCH 14/37] fix: ts test script --- generate.js | 5 +++-- templates/app-ts-esm/test/helper.ts | 2 +- templates/app-ts/test/routes/example.test.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/generate.js b/generate.js index b01d47ef..aab35fdf 100755 --- a/generate.js +++ b/generate.js @@ -47,7 +47,7 @@ const typescriptTemplate = { dir: 'app-ts', main: 'app.ts', scripts: { - test: 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts', + test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --require tsx/cjs test/**/*.ts', start: 'npm run build:ts && fastify start -l info dist/app.js', 'build:ts': 'tsc', 'watch:ts': 'tsc -w', @@ -162,7 +162,8 @@ function cli (args) { template.type = 'module' template.devDependencies.c8 = cliPkg.devDependencies.c8 - template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/**/*.test.ts && c8 report' + // what to do with ts/esm and node --test... ? + template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --import tsx/esm test/**/*.ts' } } else { template = { ...javascriptTemplate } diff --git a/templates/app-ts-esm/test/helper.ts b/templates/app-ts-esm/test/helper.ts index 9204d99d..253bcf92 100644 --- a/templates/app-ts-esm/test/helper.ts +++ b/templates/app-ts-esm/test/helper.ts @@ -1,7 +1,7 @@ // This file contains code that we reuse between our tests. import helper from 'fastify-cli/helper.js' import * as test from 'node:test' -import path from 'path' +import * as path from 'path' import { fileURLToPath } from 'url' export type TestContext = { diff --git a/templates/app-ts/test/routes/example.test.ts b/templates/app-ts/test/routes/example.test.ts index b62c65c6..0c35dfef 100644 --- a/templates/app-ts/test/routes/example.test.ts +++ b/templates/app-ts/test/routes/example.test.ts @@ -3,7 +3,7 @@ import * as assert from 'node:assert' import { build } from '../helper' test('example is loaded', async (t) => { - const app = await build(() => t.after()) + const app = await build(t) const res = await app.inject({ url: '/example' From 05214422d42054a22a1e6f95ed3b6fcea2f42a6c Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 16:03:13 +0100 Subject: [PATCH 15/37] fix: all tests --- generate.js | 3 +-- templates/app-ts-esm/tsconfig.json | 4 ++-- test/generate-typescript-esm.test.js | 7 +++++-- test/generate-typescript.test.js | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/generate.js b/generate.js index aab35fdf..e920af9a 100755 --- a/generate.js +++ b/generate.js @@ -162,8 +162,7 @@ function cli (args) { template.type = 'module' template.devDependencies.c8 = cliPkg.devDependencies.c8 - // what to do with ts/esm and node --test... ? - template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --import tsx/esm test/**/*.ts' + template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts' } } else { template = { ...javascriptTemplate } diff --git a/templates/app-ts-esm/tsconfig.json b/templates/app-ts-esm/tsconfig.json index 4bd43976..cd4a3e52 100644 --- a/templates/app-ts-esm/tsconfig.json +++ b/templates/app-ts-esm/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "dist", "sourceMap": true, - "moduleResolution": "Node16", - "module": "ES2022", + "moduleResolution": "NodeNext", + "module": "NodeNext", "target": "ES2022", "esModuleInterop": true }, diff --git a/test/generate-typescript-esm.test.js b/test/generate-typescript-esm.test.js index f4b6b753..42d4a6dd 100644 --- a/test/generate-typescript-esm.test.js +++ b/test/generate-typescript-esm.test.js @@ -23,6 +23,9 @@ const strip = require('strip-ansi') const expected = {} const initVersion = execSync('npm get init-version').toString().trim() +typescriptTemplate.type = 'module' +typescriptTemplate.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts' + ;(function (cb) { const files = [] walker(appTemplateDir) @@ -126,7 +129,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -143,7 +146,7 @@ function define (t) { t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) - const testGlob = pkg.scripts.test.split(' ', 11)[10].replace('*', '**') + const testGlob = pkg.scripts.test.split(' ', 15)[14] t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) resolve() diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index a1005d33..bd40a7ec 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -126,7 +126,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && tsx --test test/*/*.ts') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --require tsx/cjs test/**/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -144,7 +144,7 @@ function define (t) { t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) // bcs minimatch doesn't know about test/*/*.ts type of globs - const testGlob = pkg.scripts.test.split(' ', 11)[10].replace('*', '**') + const testGlob = pkg.scripts.test.split(' ', 14)[13] t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) resolve() From 29d80b609951e1770f4bcfd6f978334e597c41e5 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 16:49:58 +0100 Subject: [PATCH 16/37] build: reorganized runners --- package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index af4e353d..d53f2d81 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,16 @@ "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "unit:template-ts-esm": " cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json tap templates/app-ts-esm/test/**/*.test.ts --no-coverage --node-arg=--loader=ts-node/esm --timeout 400 --jobs 1 --color -R specy", - "unit:cli": "tap \"test/**/*.test.{js,ts}\" --no-coverage --timeout 400 --jobs 1 --color -R specy", - "unit:templates-without-ts-esm": "tap \"templates/app/**/*.test.js\" \"templates/app-esm/**/*.test.js\" \"templates/app-ts/**/*.test.ts\" --no-coverage --timeout 400 --jobs 1 --color -R specy", + "unit:template-ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --import tsx/esm templates/app-ts-esm/test/**/*.test.ts", + "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", + "unit:templates-without-ts-esm": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs", + "unit:cjs": "node --test templates/app/test/**/*.test.js", + "unit:esm": "node --test templates/app-esm/test/**/*.test.js", + "unit:ts-cjs": "node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts || echo \"Needs fixing related to fastify-cli/helper import\"", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", - "test-no-coverage": "npm run unit:cli && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm && npm run test:typescript", + "test-no-coverage": "npm run unit:cli && npm run test:typescript", "test": "c8 --clean npm run test-no-coverage", + "posttest": "npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" }, "keywords": [ From cd107a8587a5ef973528e6bcaa828db3ea5baeb8 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 16:56:47 +0100 Subject: [PATCH 17/37] fix: cleanup --- test/generate-esm.test.js | 2 +- test/generate-typescript.test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/generate-esm.test.js b/test/generate-esm.test.js index c742cdc2..a31ef1d2 100644 --- a/test/generate-esm.test.js +++ b/test/generate-esm.test.js @@ -165,7 +165,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, javascriptTemplate.scripts.test) + t.equal(pkg.scripts.test, 'node --test test/**/*.test.js') t.equal(pkg.scripts.start, 'fastify start -l info app.js') t.equal(pkg.scripts.dev, 'fastify start -w -l info -P app.js') t.equal(pkg.dependencies['fastify-cli'], '^' + cliPkg.version) diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index bd40a7ec..f7a3ac03 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -143,7 +143,6 @@ function define (t) { t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) - // bcs minimatch doesn't know about test/*/*.ts type of globs const testGlob = pkg.scripts.test.split(' ', 14)[13] t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) From 3f431ff1f66ca2605e148ee9beaf250f7b8b1132 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 17:00:54 +0100 Subject: [PATCH 18/37] chore: avoid posttest and assign template tests to the end but without c8 blocking --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d53f2d81..89f70cb1 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,8 @@ "unit:esm": "node --test templates/app-esm/test/**/*.test.js", "unit:ts-cjs": "node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts || echo \"Needs fixing related to fastify-cli/helper import\"", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", - "test-no-coverage": "npm run unit:cli && npm run test:typescript", - "test": "c8 --clean npm run test-no-coverage", - "posttest": "npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", + "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", + "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" }, "keywords": [ From 1b263f31d9be0058e990c830ea55b8d9d8ec1ea8 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 17:15:50 +0100 Subject: [PATCH 19/37] fix: linted code --- templates/app/test/helper.js | 2 +- test/generate.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/app/test/helper.js b/templates/app/test/helper.js index 57d02a92..a5237509 100644 --- a/templates/app/test/helper.js +++ b/templates/app/test/helper.js @@ -23,7 +23,7 @@ async function build (t) { // different from the production setup const app = await buildApplication(argv, config()) - //close the app after we are done + // close the app after we are done t.after(() => app.close()) return app diff --git a/test/generate.test.js b/test/generate.test.js index 59c3d04d..f4f52d78 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -168,7 +168,7 @@ function define (t) { t.equal(pkg.dependencies['fastify-plugin'], cliPkg.devDependencies['fastify-plugin'] || cliPkg.dependencies['fastify-plugin']) t.equal(pkg.dependencies['@fastify/autoload'], cliPkg.devDependencies['@fastify/autoload']) t.equal(pkg.dependencies['@fastify/sensible'], cliPkg.devDependencies['@fastify/sensible']) - + const testGlob = pkg.scripts.test.split(' ', 3)[2] t.equal(minimatch.match(['test/services/plugins/more/test/here/ok.test.js'], testGlob).length, 1) resolve() From 65d4f2efea48a74da0b41db4957cd61879cdc2e6 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 17:21:19 +0100 Subject: [PATCH 20/37] ci: bump workflow version to 4 to drop 14 and 16 runtimes from testing --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b38f49a3..6a2f889c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4 with: lint: true auto-merge-exclude: 'help-me' From e63cf7194522b2f2d8fab66d43aad6ed2428017d Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 19:07:58 +0100 Subject: [PATCH 21/37] ci: empty commit to trigger workflow on a fork From 22bd31472a91189ac9a2efa4c5b83adcf563d369 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Mon, 27 Nov 2023 20:32:01 +0100 Subject: [PATCH 22/37] ci: revert to v3 of reusable workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a2f889c..b38f49a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 with: lint: true auto-merge-exclude: 'help-me' From 85647fa45a854d29e2ddc5be2985365ba7300282 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Tue, 28 Nov 2023 07:24:04 +0100 Subject: [PATCH 23/37] chore: fixes unit:ts-cjs script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89f70cb1..0e77e47a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "unit:templates-without-ts-esm": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs", "unit:cjs": "node --test templates/app/test/**/*.test.js", "unit:esm": "node --test templates/app-esm/test/**/*.test.js", - "unit:ts-cjs": "node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts || echo \"Needs fixing related to fastify-cli/helper import\"", + "unit:ts-cjs": "node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", From ee832d7080293ba67303e7011cf6886051db10d1 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Tue, 28 Nov 2023 08:33:22 +0100 Subject: [PATCH 24/37] feat: implements skipping test suites for incompatible runtime versions --- package.json | 8 ++++---- should-test-suite.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 should-test-suite.js diff --git a/package.json b/package.json index 0e77e47a..2b089312 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,12 @@ "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "unit:template-ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --import tsx/esm templates/app-ts-esm/test/**/*.test.ts", + "unit:template-ts-esm": "node should-test-suite.js unit:ts-esm || cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --import tsx/esm templates/app-ts-esm/test/**/*.test.ts", "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "unit:templates-without-ts-esm": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs", - "unit:cjs": "node --test templates/app/test/**/*.test.js", - "unit:esm": "node --test templates/app-esm/test/**/*.test.js", - "unit:ts-cjs": "node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts", + "unit:cjs": "node should-test-suite.js unit:cjs || node --test templates/app/test/**/*.test.js", + "unit:esm": "node should-test-suite.js unit:esm || node --test templates/app-esm/test/**/*.test.js", + "unit:ts-cjs": "node should-test-suite.js unit:ts-cjs || node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", diff --git a/should-test-suite.js b/should-test-suite.js new file mode 100644 index 00000000..9df584b5 --- /dev/null +++ b/should-test-suite.js @@ -0,0 +1,12 @@ +const suite = process.argv[2] + +function shouldTest(suiteName) { + const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] + const code = nodeMajorVersion < 18 ? 0 : 1 + if (!code) { + console.info(`Skipped template test suite for ${suiteName} on node ${nodeMajorVersion}`) + } + process.exit(code) +} + +shouldTest(process.argv[2]) \ No newline at end of file From 5420275a66ebac076616523a6616633cc8304af7 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Tue, 28 Nov 2023 08:41:16 +0100 Subject: [PATCH 25/37] ci: run templates on 20 only --- should-test-suite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/should-test-suite.js b/should-test-suite.js index 9df584b5..9366f8c0 100644 --- a/should-test-suite.js +++ b/should-test-suite.js @@ -2,7 +2,7 @@ const suite = process.argv[2] function shouldTest(suiteName) { const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] - const code = nodeMajorVersion < 18 ? 0 : 1 + const code = nodeMajorVersion < 20 ? 0 : 1 if (!code) { console.info(`Skipped template test suite for ${suiteName} on node ${nodeMajorVersion}`) } From d8b03ca12d1d171561bdb55a2530668b84e1ea5c Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Tue, 28 Nov 2023 08:42:48 +0100 Subject: [PATCH 26/37] fix: lint errs --- should-test-suite.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/should-test-suite.js b/should-test-suite.js index 9366f8c0..9b9dd881 100644 --- a/should-test-suite.js +++ b/should-test-suite.js @@ -1,6 +1,4 @@ -const suite = process.argv[2] - -function shouldTest(suiteName) { +function shouldTest (suiteName) { const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] const code = nodeMajorVersion < 20 ? 0 : 1 if (!code) { @@ -9,4 +7,4 @@ function shouldTest(suiteName) { process.exit(code) } -shouldTest(process.argv[2]) \ No newline at end of file +shouldTest(process.argv[2]) From 90512cf903d0161d87e274c4615306b3a2d0db91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aran=C4=91el=20=C5=A0arenac?= <11753867+big-kahuna-burger@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:05:56 +0100 Subject: [PATCH 27/37] add suites runner and correct skip logic (#1) * test: add a suite runner instead of using pattern directly in shell * ci: simplify * ci: flip logic * ci: correct the logic --- package.json | 14 +++++++------- should-skip-test-suites.js | 7 +++++++ should-test-suite.js | 10 ---------- suite-runner.js | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 should-skip-test-suites.js delete mode 100644 should-test-suite.js create mode 100644 suite-runner.js diff --git a/package.json b/package.json index 2b089312..4a812bae 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,15 @@ "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "unit:template-ts-esm": "node should-test-suite.js unit:ts-esm || cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --import tsx/esm templates/app-ts-esm/test/**/*.test.ts", - "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", - "unit:templates-without-ts-esm": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs", - "unit:cjs": "node should-test-suite.js unit:cjs || node --test templates/app/test/**/*.test.js", - "unit:esm": "node should-test-suite.js unit:esm || node --test templates/app-esm/test/**/*.test.js", - "unit:ts-cjs": "node should-test-suite.js unit:ts-cjs || node --test --require tsx/cjs templates/app-ts/test/**/*.test.ts", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", + "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:suites", + "unit:cjs": "c8 node suite-runner.js templates/app/test/**/*.test.js", + "unit:esm": "c8 node suite-runner.js templates/app-esm/test/**/*.test.js", + "unit:ts-cjs": "c8 node -r tsx/cjs suite-runner.js templates/app-ts/test/**/*.test.ts", + "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 c8 node -r tsx/cjs --import tsx/esm suite-runner.js templates/app-ts-esm/test/**/*.test.ts", + "unit:suites": "node should-skip-test-suites.js || (npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm)", + "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", - "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm", "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" }, "keywords": [ diff --git a/should-skip-test-suites.js b/should-skip-test-suites.js new file mode 100644 index 00000000..8053a82a --- /dev/null +++ b/should-skip-test-suites.js @@ -0,0 +1,7 @@ +const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] +const shouldRunSuites = nodeMajorVersion >= 20 +if (!shouldRunSuites) { + console.info(`Skipped templates test suites on node ${nodeMajorVersion}`) + process.exit(0) +} +process.exit(1) diff --git a/should-test-suite.js b/should-test-suite.js deleted file mode 100644 index 9b9dd881..00000000 --- a/should-test-suite.js +++ /dev/null @@ -1,10 +0,0 @@ -function shouldTest (suiteName) { - const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] - const code = nodeMajorVersion < 20 ? 0 : 1 - if (!code) { - console.info(`Skipped template test suite for ${suiteName} on node ${nodeMajorVersion}`) - } - process.exit(code) -} - -shouldTest(process.argv[2]) diff --git a/suite-runner.js b/suite-runner.js new file mode 100644 index 00000000..cacfb95a --- /dev/null +++ b/suite-runner.js @@ -0,0 +1,17 @@ +const { run } = require('node:test') +const { spec } = require('node:test/reporters') +const path = require('path') +const glob = require('glob') + +const pattern = process.argv[process.argv.length - 1] + +glob(pattern, (err, matches) => { + if (err) { + console.error(err) + process.exit(1) + } + const resolved = matches.map(file => path.resolve(file)) + run({ files: resolved }) + .compose(spec) + .pipe(process.stdout) +}) From 3406ae218fa47e8a8a7579fad4e52407b4f91f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aran=C4=91el=20=C5=A0arenac?= <11753867+big-kahuna-burger@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:34:55 +0100 Subject: [PATCH 28/37] ci: fix args expansion (#5) --- package.json | 8 ++++---- suite-runner.js | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4a812bae..0eb71404 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "lint:fix": "standard --fix", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:suites", - "unit:cjs": "c8 node suite-runner.js templates/app/test/**/*.test.js", - "unit:esm": "c8 node suite-runner.js templates/app-esm/test/**/*.test.js", - "unit:ts-cjs": "c8 node -r tsx/cjs suite-runner.js templates/app-ts/test/**/*.test.ts", - "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 c8 node -r tsx/cjs --import tsx/esm suite-runner.js templates/app-ts-esm/test/**/*.test.ts", + "unit:cjs": "c8 node suite-runner.js \"templates/app/test/**/*.test.js\"", + "unit:esm": "c8 node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", + "unit:ts-cjs": "c8 node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", + "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 c8 node -r tsx/cjs --import tsx/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", "unit:suites": "node should-skip-test-suites.js || (npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm)", "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", diff --git a/suite-runner.js b/suite-runner.js index cacfb95a..d6d429bf 100644 --- a/suite-runner.js +++ b/suite-runner.js @@ -5,13 +5,14 @@ const glob = require('glob') const pattern = process.argv[process.argv.length - 1] +console.info(`Running tests matching ${pattern}`) + glob(pattern, (err, matches) => { if (err) { console.error(err) process.exit(1) } const resolved = matches.map(file => path.resolve(file)) - run({ files: resolved }) - .compose(spec) - .pipe(process.stdout) + const testRs = run({ files: resolved }).compose(spec) + testRs.pipe(process.stdout) }) From 5914b35dd64cd71d41eb4a1822d75abf543bba08 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Tue, 28 Nov 2023 10:44:33 +0100 Subject: [PATCH 29/37] fix: remove problematic c8 on ts-esm tpl --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0eb71404..f1cf5f89 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,9 @@ "unit:cjs": "c8 node suite-runner.js \"templates/app/test/**/*.test.js\"", "unit:esm": "c8 node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", "unit:ts-cjs": "c8 node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", - "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 c8 node -r tsx/cjs --import tsx/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", - "unit:suites": "node should-skip-test-suites.js || (npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm)", + "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node -r tsx/cjs --import tsx/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", + "unit:suites": "node should-skip-test-suites.js || npm run all-suites", + "all-suites": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm", "unit:cli": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" From d305d3ffdc575b87afa3fa758a2705158729347f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aran=C4=91el=20=C5=A0arenac?= <11753867+big-kahuna-burger@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:12:20 +0100 Subject: [PATCH 30/37] drops c8 (#6) * ci: only ts * ci: no c8 * ci: c8 for javascript * ci: no c8 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f1cf5f89..65dcfa7f 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "lint:fix": "standard --fix", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:suites", - "unit:cjs": "c8 node suite-runner.js \"templates/app/test/**/*.test.js\"", - "unit:esm": "c8 node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", - "unit:ts-cjs": "c8 node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", + "unit:cjs": "node suite-runner.js \"templates/app/test/**/*.test.js\"", + "unit:esm": "node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", + "unit:ts-cjs": "node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node -r tsx/cjs --import tsx/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", "unit:suites": "node should-skip-test-suites.js || npm run all-suites", "all-suites": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm", From 891c677fb1c682a9493f8521074ceaf1b031be5b Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Sat, 2 Dec 2023 14:59:42 +0100 Subject: [PATCH 31/37] test: swap positions --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb27bb49..c8d31b7f 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint": "standard", "lint:fix": "standard --fix", "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", - "test": "c8 --clean npm run test:cli-and-typescript && npm run unit:suites", + "test": "npm run unit:suites && c8 --clean npm run test:cli-and-typescript", "unit:cjs": "node suite-runner.js \"templates/app/test/**/*.test.js\"", "unit:esm": "node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", "unit:ts-cjs": "node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", From 56100dd81e5dbeeb6a492b3e224413e2baaf6fbe Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Sat, 2 Dec 2023 15:04:26 +0100 Subject: [PATCH 32/37] test: add timeout --- suite-runner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/suite-runner.js b/suite-runner.js index d6d429bf..522f7fa0 100644 --- a/suite-runner.js +++ b/suite-runner.js @@ -6,13 +6,13 @@ const glob = require('glob') const pattern = process.argv[process.argv.length - 1] console.info(`Running tests matching ${pattern}`) - +const timeout = 5 * 60 * 1000 // 5 minutes glob(pattern, (err, matches) => { if (err) { console.error(err) process.exit(1) } const resolved = matches.map(file => path.resolve(file)) - const testRs = run({ files: resolved }).compose(spec) + const testRs = run({ files: resolved, timeout }).compose(spec) testRs.pipe(process.stdout) }) From 4522c26bd4480c50d358ccc57ab7062f7a3c6456 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 8 Dec 2023 18:24:33 +0100 Subject: [PATCH 33/37] fix: remove tsx dependency and use existing ts-node --- generate.js | 7 +++---- package.json | 5 ++--- test/configs/ts-esm.tsconfig.json | 6 +++++- test/generate-typescript-esm.test.js | 7 +++---- test/generate-typescript.test.js | 7 +++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/generate.js b/generate.js index e920af9a..81f95e1e 100755 --- a/generate.js +++ b/generate.js @@ -47,7 +47,7 @@ const typescriptTemplate = { dir: 'app-ts', main: 'app.ts', scripts: { - test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --require tsx/cjs test/**/*.ts', + test: 'npm run build:ts && 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': 'tsc', 'watch:ts': 'tsc -w', @@ -67,8 +67,7 @@ const typescriptTemplate = { 'ts-node': cliPkg.devDependencies['ts-node'], concurrently: cliPkg.devDependencies.concurrently, 'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'], - typescript: cliPkg.devDependencies.typescript, - tsx: cliPkg.devDependencies.tsx + typescript: cliPkg.devDependencies.typescript }, nodemonConfig: { watch: ['src/'], @@ -162,7 +161,7 @@ function cli (args) { template.type = 'module' template.devDependencies.c8 = cliPkg.devDependencies.c8 - template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts' + template.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --loader ts-node/esm test/**/*.ts' } } else { template = { ...javascriptTemplate } diff --git a/package.json b/package.json index c8d31b7f..3e537d99 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "test": "npm run unit:suites && c8 --clean npm run test:cli-and-typescript", "unit:cjs": "node suite-runner.js \"templates/app/test/**/*.test.js\"", "unit:esm": "node suite-runner.js \"templates/app-esm/test/**/*.test.js\"", - "unit:ts-cjs": "node -r tsx/cjs suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", - "unit:ts-esm": "cross-env TS_NODE_PROJECT=./templates/app-ts-esm/tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node -r tsx/cjs --import tsx/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", + "unit:ts-cjs": "cross-env TS_NODE_PROJECT=./test/configs/ts-cjs.tsconfig.json node -r ts-node/register suite-runner.js \"templates/app-ts/test/**/*.test.ts\"", + "unit:ts-esm": "cross-env TS_NODE_PROJECT=./test/configs/ts-esm.tsconfig.json FASTIFY_AUTOLOAD_TYPESCRIPT=1 node -r ts-node/register --loader ts-node/esm suite-runner.js \"templates/app-ts-esm/test/**/*.test.ts\"", "unit:suites": "node should-skip-test-suites.js || npm run all-suites", "all-suites": "npm run unit:cjs && npm run unit:esm && npm run unit:ts-cjs && npm run unit:ts-esm", "unit:cli-js": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", @@ -92,7 +92,6 @@ "ts-node": "^10.4.0", "ts-standard": "^12.0.1", "tsd": "^0.28.0", - "tsx": "^4.5.0", "typescript": "^5.2.2", "walker": "^1.0.8" }, diff --git a/test/configs/ts-esm.tsconfig.json b/test/configs/ts-esm.tsconfig.json index b52b3ee8..76d2dcb0 100644 --- a/test/configs/ts-esm.tsconfig.json +++ b/test/configs/ts-esm.tsconfig.json @@ -8,5 +8,9 @@ "target": "ES2022", "esModuleInterop": true }, - "include": ["src/**/*.ts"] + "include": ["src/**/*.ts"], + "ts-node": { + "esm": true, + "experimentalSpecifierResolution": "node" + } } diff --git a/test/generate-typescript-esm.test.js b/test/generate-typescript-esm.test.js index 42d4a6dd..a611e692 100644 --- a/test/generate-typescript-esm.test.js +++ b/test/generate-typescript-esm.test.js @@ -24,7 +24,7 @@ const expected = {} const initVersion = execSync('npm get init-version').toString().trim() typescriptTemplate.type = 'module' -typescriptTemplate.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts' +typescriptTemplate.scripts.test = 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --loader ts-node/esm test/**/*.ts' ;(function (cb) { const files = [] @@ -104,7 +104,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(25 + Object.keys(expected).length) + t.plan(24 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -129,7 +129,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --import tsx/esm test/**/*.ts') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --loader ts-node/esm test/**/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -144,7 +144,6 @@ function define (t) { t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) - t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) const testGlob = pkg.scripts.test.split(' ', 15)[14] diff --git a/test/generate-typescript.test.js b/test/generate-typescript.test.js index f7a3ac03..bb027976 100644 --- a/test/generate-typescript.test.js +++ b/test/generate-typescript.test.js @@ -101,7 +101,7 @@ function define (t) { }) test('should finish successfully with typescript template', async (t) => { - t.plan(25 + Object.keys(expected).length) + t.plan(24 + Object.keys(expected).length) try { await generate(workdir, typescriptTemplate) await verifyPkg(t) @@ -126,7 +126,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.ok(pkg.license === 'ISC' || pkg.license === 'MIT') - t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test --require tsx/cjs test/**/*.ts') + t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register test/**/*.ts') t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js') t.equal(pkg.scripts['build:ts'], 'tsc') t.equal(pkg.scripts['watch:ts'], 'tsc -w') @@ -141,11 +141,10 @@ function define (t) { t.equal(pkg.devDependencies['ts-node'], cliPkg.devDependencies['ts-node']) t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently) t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) - t.equal(pkg.devDependencies.tsx, cliPkg.devDependencies.tsx) const testGlob = pkg.scripts.test.split(' ', 14)[13] - t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1) + t.equal(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1, 'should match glob') resolve() }) }) From 74a17bf2ef284f5ef01c37d8a5327c119518f5ab Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 8 Dec 2023 18:27:48 +0100 Subject: [PATCH 34/37] fix: remove extra conf --- test/configs/ts-esm.tsconfig.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/configs/ts-esm.tsconfig.json b/test/configs/ts-esm.tsconfig.json index 76d2dcb0..b52b3ee8 100644 --- a/test/configs/ts-esm.tsconfig.json +++ b/test/configs/ts-esm.tsconfig.json @@ -8,9 +8,5 @@ "target": "ES2022", "esModuleInterop": true }, - "include": ["src/**/*.ts"], - "ts-node": { - "esm": true, - "experimentalSpecifierResolution": "node" - } + "include": ["src/**/*.ts"] } From 085f5ac19c3042c09a2a6217f6c351c2b925c0aa Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 8 Dec 2023 18:32:07 +0100 Subject: [PATCH 35/37] feat(script): drop dependency to del-cli and use --noEmit flag with tsc --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 3e537d99..c0fdbe7f 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "unit:cli-ts": "cross-env TS_NODE_PROJECT=./test/configs/ts-cjs.tsconfig.json tap \"test/**/*.test.ts\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "unit:cli": "npm run unit:cli-js && npm run unit:cli-ts", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", - "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" + "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json --noEmit" }, "keywords": [ "fastify", @@ -79,7 +79,6 @@ "c8": "^7.13.0", "concurrently": "^8.2.2", "cross-env": "^7.0.3", - "del-cli": "^3.0.1", "fastify-tsconfig": "^2.0.0", "minimatch": "^5.1.0", "proxyquire": "^2.1.3", From 25076f52f52e95b266105519397281b79ead9527 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 8 Dec 2023 18:45:21 +0100 Subject: [PATCH 36/37] test: add compilation test for ts-esm template --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0fdbe7f..c8231560 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "unit:cli-ts": "cross-env TS_NODE_PROJECT=./test/configs/ts-cjs.tsconfig.json tap \"test/**/*.test.ts\" --no-coverage --timeout 400 --jobs 1 --color -R specy", "unit:cli": "npm run unit:cli-js && npm run unit:cli-ts", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", - "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json --noEmit" + "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json --noEmit && tsc --project templates/app-ts-esm/tsconfig.json --noEmit" }, "keywords": [ "fastify", From c440373f2577b21ddb22d02822a76d1c6fbc831b Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Sat, 9 Dec 2023 16:17:37 +0100 Subject: [PATCH 37/37] test: adds fault exit code to suite runner on test:fail event being emitted --- suite-runner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/suite-runner.js b/suite-runner.js index 522f7fa0..81bcfe68 100644 --- a/suite-runner.js +++ b/suite-runner.js @@ -13,6 +13,10 @@ glob(pattern, (err, matches) => { process.exit(1) } const resolved = matches.map(file => path.resolve(file)) - const testRs = run({ files: resolved, timeout }).compose(spec) + const testRs = run({ files: resolved, timeout }) + .on('test:fail', () => { + process.exitCode = 1 + }) + .compose(spec) testRs.pipe(process.stdout) })