diff --git a/package.json b/package.json index 9589b51c..0a351078 100644 --- a/package.json +++ b/package.json @@ -10,11 +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: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", + "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-without-ts-esm && npm run unit:template-ts-esm && npm run test:typescript", + "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" }, 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/configs/ts-cjs.tsconfig.json b/test/configs/ts-cjs.tsconfig.json new file mode 100644 index 00000000..5e0e7973 --- /dev/null +++ b/test/configs/ts-cjs.tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../node_modules/fastify-tsconfig/tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "sourceMap": true + }, + "include": ["src/**/*.ts"] +} diff --git a/test/configs/ts-esm.tsconfig.json b/test/configs/ts-esm.tsconfig.json new file mode 100644 index 00000000..b52b3ee8 --- /dev/null +++ b/test/configs/ts-esm.tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../node_modules/fastify-tsconfig/tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "sourceMap": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "target": "ES2022", + "esModuleInterop": true + }, + "include": ["src/**/*.ts"] +} diff --git a/test/print-plugins.test.js b/test/print-plugins.test.js index f9626a7d..da1450ef 100644 --- a/test/print-plugins.test.js +++ b/test/print-plugins.test.js @@ -10,7 +10,11 @@ const printPlugins = require('../print-plugins') const test = tap.test -test('should print plugins', async t => { +const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env +const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE + +// This test should be skipped when coverage reporting is used since outputs won't match +test('should print plugins', { skip: SHOULD_SKIP }, async t => { t.plan(3) const spy = sinon.spy() @@ -25,8 +29,8 @@ test('should print plugins', async t => { t.match(spy.args[0][1], /bound root \d+ ms\n├── bound _after \d+ ms\n├─┬ function \(fastify, options, next\) { -- fastify\.decorate\('test', true\) \d+ ms\n│ ├── bound _after \d+ ms\n│ ├── bound _after \d+ ms\n│ └── bound _after \d+ ms\n└── bound _after \d+ ms\n/) }) -// This never exits in CI for some reason -test('should plugins routes via cli', { skip: process.env.CI }, async t => { +// This test should be skipped when coverage reporting is used since outputs won't match +test('should plugins routes via cli', { skip: SHOULD_SKIP }, async t => { t.plan(1) const { stdout } = await exec('node cli.js print-plugins ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 }) t.match( @@ -91,7 +95,8 @@ test('should exit without error on help', t => { t.end() }) -test('should print plugins of server with an async/await plugin', async t => { +// This test should be skipped when coverage reporting is used since outputs won't match +test('should print plugins of server with an async/await plugin', { skip: SHOULD_SKIP }, async t => { const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0] if (nodeMajorVersion < 7) { t.pass('Skip because Node version < 7') diff --git a/test/print-routes.test.js b/test/print-routes.test.js index 91ca16d4..67bd8867 100644 --- a/test/print-routes.test.js +++ b/test/print-routes.test.js @@ -9,6 +9,8 @@ const exec = util.promisify(require('node:child_process').exec) const printRoutes = require('../print-routes') const test = tap.test +const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env +const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE test('should print routes', async t => { t.plan(2) @@ -25,7 +27,7 @@ test('should print routes', async t => { }) // This never exits in CI for some reason -test('should print routes via cli', { skip: process.env.CI }, async t => { +test('should print routes via cli', { skip: SHOULD_SKIP }, async t => { t.plan(1) const { stdout } = await exec('node cli.js print-routes ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 }) t.same(