Skip to content

Commit

Permalink
fix unit test (#202)
Browse files Browse the repository at this point in the history
remove semver
improve npm scripts
activate linting on ci
  • Loading branch information
Uzlopak committed Nov 30, 2022
1 parent f4e9c85 commit 61c2e70
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
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
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
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
@@ -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
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

0 comments on commit 61c2e70

Please sign in to comment.