From aab90aef0d0361e28f1e9103d90527cde2e2010c Mon Sep 17 00:00:00 2001 From: inyourtime Date: Mon, 25 Nov 2024 16:23:01 +0700 Subject: [PATCH] chore: migrate from tap to node:test and c8 --- .taprc | 3 --- package.json | 4 ++-- test/basic.test.js | 4 ++-- test/custom-ajv.test.js | 12 ++++++------ test/expand.test.js | 4 ++-- test/fluent-schema.test.js | 6 +++--- test/make-test.js | 6 +++--- test/no-global.test.js | 6 +++--- 8 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 .taprc diff --git a/.taprc b/.taprc deleted file mode 100644 index 343ddd5..0000000 --- a/.taprc +++ /dev/null @@ -1,3 +0,0 @@ -disable-coverage: true -files: - - test/**/*.test.js diff --git a/package.json b/package.json index e332bbe..763983e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "lint": "standard | snazzy", "test": "npm run test:unit && npm run test:typescript", - "test:unit": "tap", + "test:unit": "c8 --100 node --test", "test:typescript": "tsd" }, "repository": { @@ -39,10 +39,10 @@ "@fastify/pre-commit": "^2.1.0", "@sinclair/typebox": "^0.34.3", "ajv-formats": "^3.0.1", + "c8": "^10.1.2", "fluent-json-schema": "^5.0.0", "snazzy": "^9.0.0", "standard": "^17.1.0", - "tap": "^18.7.1", "tsd": "^0.31.0" }, "pre-commit": [ diff --git a/test/basic.test.js b/test/basic.test.js index 420f615..276f4fe 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,6 +1,6 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const makeTest = require('./make-test') const { join } = require('node:path') @@ -325,7 +325,7 @@ const tests = [ ] tests.forEach(function (testConf) { - t.test(testConf.name, t => { + test(testConf.name, t => { const options = { schema: testConf.schema, data: testConf.data, diff --git a/test/custom-ajv.test.js b/test/custom-ajv.test.js index 06135e9..59bf6c4 100644 --- a/test/custom-ajv.test.js +++ b/test/custom-ajv.test.js @@ -1,6 +1,6 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const Ajv = require('ajv') const makeTest = require('./make-test') const { join } = require('node:path') @@ -242,7 +242,7 @@ const ajv = new Ajv({ }) tests.forEach(function (testConf) { - t.test(testConf.name, t => { + test(testConf.name, t => { const options = { schema: testConf.schema, data: testConf.data, @@ -284,7 +284,7 @@ const strictValidator = new Ajv({ }); [noCoercionTest].forEach(function (testConf) { - t.test(testConf.name, t => { + test(testConf.name, t => { const options = { schema: testConf.schema, data: testConf.data, @@ -297,7 +297,7 @@ const strictValidator = new Ajv({ }) }) -t.test('ajv enhancement', t => { +test('ajv enhancement', async t => { t.plan(2) const testCase = { schema: { @@ -317,7 +317,7 @@ t.test('ajv enhancement', t => { } } - t.test('return', t => { + await t.test('return', async t => { const options = { schema: testCase.schema, data: testCase.data, @@ -331,7 +331,7 @@ t.test('ajv enhancement', t => { makeTest(t, options, testCase.isOk, testCase.confExpected) }) - t.test('no return', t => { + await t.test('no return', async t => { const options = { schema: testCase.schema, data: testCase.data, diff --git a/test/expand.test.js b/test/expand.test.js index e33d065..0a74e80 100644 --- a/test/expand.test.js +++ b/test/expand.test.js @@ -1,6 +1,6 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const makeTest = require('./make-test') const { join } = require('node:path') @@ -74,7 +74,7 @@ const tests = [ ] tests.forEach(function (testConf) { - t.test(testConf.name, t => { + test(testConf.name, t => { const options = { schema: testConf.schema, data: testConf.data, diff --git a/test/fluent-schema.test.js b/test/fluent-schema.test.js index 054cd5b..6b1e4be 100644 --- a/test/fluent-schema.test.js +++ b/test/fluent-schema.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') if (parseInt(process.versions.node.split('.', 1)[0]) <= 8) { - t.skip('not supported') + test.skip('not supported') } else { run() } @@ -12,7 +12,7 @@ function run () { const S = require('fluent-json-schema') const makeTest = require('./make-test') - t.test('simple object - fluent-json-schema', t => { + test('simple object - fluent-json-schema', t => { const options = { schema: S.object().prop('PORT', S.string()), data: { diff --git a/test/make-test.js b/test/make-test.js index 52d79cb..1e78e19 100644 --- a/test/make-test.js +++ b/test/make-test.js @@ -8,13 +8,13 @@ function makeTest (t, options, isOk, confExpected, errorMessage) { try { const conf = envSchema(options) - t.strictSame(conf, confExpected) + t.assert.deepStrictEqual(conf, confExpected) } catch (err) { if (isOk) { - t.fail(err) + t.assert.fail(err) return } - t.strictSame(err.message, errorMessage) + t.assert.strictEqual(err.message, errorMessage) } } diff --git a/test/no-global.test.js b/test/no-global.test.js index 064dac7..d016935 100644 --- a/test/no-global.test.js +++ b/test/no-global.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const envSchema = require('../index') test('no globals', t => { @@ -29,10 +29,10 @@ test('no globals', t => { { const conf = envSchema(JSON.parse(JSON.stringify(options))) - t.strictSame(conf, { MONGO_URL: 'good', PORT: 3000 }) + t.assert.deepStrictEqual(conf, { MONGO_URL: 'good', PORT: 3000 }) } { const conf = envSchema(JSON.parse(JSON.stringify(options))) - t.strictSame(conf, { MONGO_URL: 'good', PORT: 3000 }) + t.assert.deepStrictEqual(conf, { MONGO_URL: 'good', PORT: 3000 }) } })