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/generate.js b/generate.js index 6bc72f60..81f95e1e 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' }, @@ -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`) @@ -49,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 && 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', @@ -69,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: { @@ -122,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) { @@ -164,18 +159,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 && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --loader ts-node/esm test/**/*.ts' } } else { template = { ...javascriptTemplate } @@ -183,12 +169,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/package.json b/package.json index 0a351078..c8231560 100644 --- a/package.json +++ b/package.json @@ -10,18 +10,19 @@ "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "unit:templates": "npm run unit:ts-esm && npm run unit:ts-cjs && npm run unit:esm && npm run unit:cjs", - "unit:cjs": "tap \"templates/app/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", - "unit:esm": "tap \"templates/app-esm/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy", - "unit:ts-cjs": "cross-env TS_NODE_PROJECT=./test/configs/ts-cjs.tsconfig.json tap \"templates/app-ts/**/*.test.ts\" --no-coverage --timeout 400 --jobs 1 --color -R specy", - "unit:ts-esm": "cross-env TS_NODE_PROJECT=./test/configs/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", + "pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'", + "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": "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", "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", - "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 && npm run test:typescript", - "test": "c8 --clean npm run test-no-coverage", - "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist" + "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 && tsc --project templates/app-ts-esm/tsconfig.json --noEmit" }, "keywords": [ "fastify", @@ -78,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", 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/suite-runner.js b/suite-runner.js new file mode 100644 index 00000000..81bcfe68 --- /dev/null +++ b/suite-runner.js @@ -0,0 +1,22 @@ +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] + +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, timeout }) + .on('test:fail', () => { + process.exitCode = 1 + }) + .compose(spec) + testRs.pipe(process.stdout) +}) diff --git a/templates/app-esm/test/helper.js b/templates/app-esm/test/helper.js index c4e02dad..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.teardown(app.close.bind(app)) + t.after(() => app.close()) return app } 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..253bcf92 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 helper from 'fastify-cli/helper.js' -import path from 'path' -import tap from 'tap'; +import * as test from 'node:test' +import * as path from 'path' import { fileURLToPath } from 'url' - -export type Test = typeof tap['Test']['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 (t: Test) { +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 (t: Test) { const app = await helper.build(argv, await config()) // Tear down our app after we are done - t.teardown(() => void app.close()) + t.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..743b610d 100644 --- a/templates/app-ts-esm/test/routes/root.test.ts +++ b/templates/app-ts-esm/test/routes/root.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('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/test/helper.ts b/templates/app-ts/test/helper.ts index 849731b7..70451775 100644 --- a/templates/app-ts/test/helper.ts +++ b/templates/app-ts/test/helper.ts @@ -1,9 +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 tap from 'tap'; +import * as test from 'node:test' -export type Test = typeof tap['Test']['prototype']; +export type TestContext = { + after: typeof test.after +}; const AppPath = path.join(__dirname, '..', 'src', 'app.ts') @@ -14,7 +16,7 @@ async function config () { } // Automatically build and tear down our instance -async function build (t: Test) { +async function build (t: TestContext) { // you can set all the options supported by the fastify CLI command const argv = [AppPath] @@ -24,7 +26,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()) + t.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..17554ecc 100644 --- a/templates/app-ts/test/routes/root.test.ts +++ b/templates/app-ts/test/routes/root.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('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/test/helper.js b/templates/app/test/helper.js index 67c3fe4d..a5237509 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..6fac9fc1 100644 --- a/templates/app/test/routes/root.test.js +++ b/templates/app/test/routes/root.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('default root route', async (t) => { @@ -9,7 +10,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 +23,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') }) diff --git a/test/generate-esm.test.js b/test/generate-esm.test.js index 2440bf5e..a31ef1d2 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 = [] @@ -114,7 +111,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 +122,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,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, '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) @@ -176,7 +173,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') 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) diff --git a/test/generate-typescript-esm.test.js b/test/generate-typescript-esm.test.js index 8a7e7f11..a611e692 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 --loader ts-node/esm test/**/*.ts' + ;(function (cb) { const files = [] walker(appTemplateDir) @@ -101,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) @@ -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 && tap --ts "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 --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') @@ -140,10 +143,9 @@ 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, '') + 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 29729d4f..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 && tap --ts "test/**/*.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') @@ -140,12 +140,11 @@ 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, '') + 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() }) }) diff --git a/test/generate.test.js b/test/generate.test.js index 1ce62150..f4f52d78 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')) @@ -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) @@ -168,9 +168,8 @@ 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, '') + 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() })