Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unit test #202

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
with:
lint: true
license-check: true
3 changes: 3 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ ts: false
jsx: false
flow: false
coverage: true

files:
- test/**/*.js
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"main": "plugin.js",
"types": "plugin.d.ts",
"scripts": {
"test": "standard && tap test/*.js test/esm/*.js --no-check-coverage && npm run typescript",
"test:ci": "standard && tap test/*.js test/esm/*.js --no-check-coverage --coverage-report=lcovonly && npm run typescript",
"typescript": "tsd"
"lint": "standard",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
},
"repository": {
"type": "git",
Expand All @@ -29,7 +30,6 @@
"@types/node": "^18.0.0",
"fastify": "^4.0.1",
"proxyquire": "^2.1.3",
"semver": "^7.3.7",
"standard": "^17.0.0",
"tap": "^16.0.1",
"tsd": "^0.24.1"
Expand Down
24 changes: 8 additions & 16 deletions test/esm/index.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
'use strict'

const t = require('tap')
const semver = require('semver')

if (semver.lt(process.versions.node, '13.3.0')) {
t.skip('Skip because Node version <= 13.3.0')
t.end()
} else {
// Node v8 throw a `SyntaxError: Unexpected token import`
// even if this branch is never touch in the code,
// by using `eval` we can avoid this issue.
// eslint-disable-next-line
new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
process.nextTick(() => {
throw err
})
// Node v8 throw a `SyntaxError: Unexpected token import`
// even if this branch is never touch in the code,
// by using `eval` we can avoid this issue.
// eslint-disable-next-line
new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
process.nextTick(() => {
throw err
})
}
})
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ test('should check version when encapsulated', t => {
}))

fastify.ready(err => {
t.match(err.message, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d.\d' is installed/)
t.match(err.message, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/)
})
})

Expand Down