Skip to content

Commit

Permalink
fix: better skip logic (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
big-kahuna-burger authored Nov 30, 2023
1 parent 0f974bc commit 957bd8d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions templates/app-ts-esm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"moduleResolution": "Node16",
"module": "ES2022",
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ES2022",
"esModuleInterop": true
},
Expand Down
8 changes: 8 additions & 0 deletions test/configs/ts-cjs.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../node_modules/fastify-tsconfig/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true
},
"include": ["src/**/*.ts"]
}
12 changes: 12 additions & 0 deletions test/configs/ts-esm.tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
13 changes: 9 additions & 4 deletions test/print-plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion test/print-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 957bd8d

Please sign in to comment.