Skip to content

Commit 957bd8d

Browse files
fix: better skip logic (#681)
1 parent 0f974bc commit 957bd8d

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
"scripts": {
1111
"lint": "standard",
1212
"lint:fix": "standard --fix",
13-
"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",
14-
"unit:cli": "tap \"test/**/*.test.{js,ts}\" --no-coverage --timeout 400 --jobs 1 --color -R specy",
15-
"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",
13+
"unit:templates": "npm run unit:ts-esm && npm run unit:ts-cjs && npm run unit:esm && npm run unit:cjs",
14+
"unit:cjs": "tap \"templates/app/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy",
15+
"unit:esm": "tap \"templates/app-esm/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy",
16+
"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",
17+
"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",
18+
"unit:cli-js": "tap \"test/**/*.test.js\" --no-coverage --timeout 400 --jobs 1 --color -R specy",
19+
"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",
20+
"unit:cli": "npm run unit:cli-js && npm run unit:cli-ts",
1621
"pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'",
17-
"test-no-coverage": "npm run unit:cli && npm run unit:templates-without-ts-esm && npm run unit:template-ts-esm && npm run test:typescript",
22+
"test-no-coverage": "npm run unit:cli && npm run unit:templates && npm run test:typescript",
1823
"test": "c8 --clean npm run test-no-coverage",
1924
"test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist"
2025
},

templates/app-ts-esm/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"compilerOptions": {
44
"outDir": "dist",
55
"sourceMap": true,
6-
"moduleResolution": "Node16",
7-
"module": "ES2022",
6+
"moduleResolution": "NodeNext",
7+
"module": "NodeNext",
88
"target": "ES2022",
99
"esModuleInterop": true
1010
},

test/configs/ts-cjs.tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../node_modules/fastify-tsconfig/tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"sourceMap": true
6+
},
7+
"include": ["src/**/*.ts"]
8+
}

test/configs/ts-esm.tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../node_modules/fastify-tsconfig/tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"sourceMap": true,
6+
"moduleResolution": "NodeNext",
7+
"module": "NodeNext",
8+
"target": "ES2022",
9+
"esModuleInterop": true
10+
},
11+
"include": ["src/**/*.ts"]
12+
}

test/print-plugins.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const printPlugins = require('../print-plugins')
1010

1111
const test = tap.test
1212

13-
test('should print plugins', async t => {
13+
const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env
14+
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
15+
16+
// This test should be skipped when coverage reporting is used since outputs won't match
17+
test('should print plugins', { skip: SHOULD_SKIP }, async t => {
1418
t.plan(3)
1519

1620
const spy = sinon.spy()
@@ -25,8 +29,8 @@ test('should print plugins', async t => {
2529
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/)
2630
})
2731

28-
// This never exits in CI for some reason
29-
test('should plugins routes via cli', { skip: process.env.CI }, async t => {
32+
// This test should be skipped when coverage reporting is used since outputs won't match
33+
test('should plugins routes via cli', { skip: SHOULD_SKIP }, async t => {
3034
t.plan(1)
3135
const { stdout } = await exec('node cli.js print-plugins ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 })
3236
t.match(
@@ -91,7 +95,8 @@ test('should exit without error on help', t => {
9195
t.end()
9296
})
9397

94-
test('should print plugins of server with an async/await plugin', async t => {
98+
// This test should be skipped when coverage reporting is used since outputs won't match
99+
test('should print plugins of server with an async/await plugin', { skip: SHOULD_SKIP }, async t => {
95100
const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0]
96101
if (nodeMajorVersion < 7) {
97102
t.pass('Skip because Node version < 7')

test/print-routes.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const exec = util.promisify(require('node:child_process').exec)
99
const printRoutes = require('../print-routes')
1010

1111
const test = tap.test
12+
const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env
13+
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
1214

1315
test('should print routes', async t => {
1416
t.plan(2)
@@ -25,7 +27,7 @@ test('should print routes', async t => {
2527
})
2628

2729
// This never exits in CI for some reason
28-
test('should print routes via cli', { skip: process.env.CI }, async t => {
30+
test('should print routes via cli', { skip: SHOULD_SKIP }, async t => {
2931
t.plan(1)
3032
const { stdout } = await exec('node cli.js print-routes ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 })
3133
t.same(

0 commit comments

Comments
 (0)