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

feat: converted all the tap tests with node:test #739

Merged
merged 3 commits into from
Sep 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,3 @@ yarn.lock
# editor files
.vscode
.idea

#tap files
.tap/
7 changes: 0 additions & 7 deletions .taprc

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "standard",
"lint:fix": "standard --fix",
"test:typescript": "tsd",
"test:unit": "tap",
"test:unit": "c8 node --test",
"test": "npm run test:unit && npm run test:typescript"
},
"precommit": [
Expand All @@ -40,13 +40,13 @@
"@fastify/pre-commit": "^2.1.0",
"@sinclair/typebox": "^0.33.4",
"benchmark": "^2.1.4",
"c8": "^10.1.2",
"cli-select": "^1.1.2",
"compile-json-stringify": "^0.1.2",
"fast-json-stringify": ".",
"is-my-json-valid": "^2.20.6",
"simple-git": "^3.23.0",
"standard": "^17.1.0",
"tap": "^19.2.5",
"tsd": "^0.31.0",
"webpack": "^5.90.3"
},
Expand Down
40 changes: 20 additions & 20 deletions test/additionalProperties.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('node:test')
const build = require('..')

test('additionalProperties', (t) => {
Expand All @@ -19,7 +19,7 @@ test('additionalProperties', (t) => {
})

const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true } }
t.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
t.assert.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
})

test('additionalProperties should not change properties', (t) => {
Expand All @@ -38,7 +38,7 @@ test('additionalProperties should not change properties', (t) => {
})

const obj = { foo: '42', ofoo: 42 }
t.equal(stringify(obj), '{"foo":"42","ofoo":42}')
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":42}')
})

test('additionalProperties should not change properties and patternProperties', (t) => {
Expand All @@ -62,7 +62,7 @@ test('additionalProperties should not change properties and patternProperties',
})

const obj = { foo: '42', ofoo: 42, test: '42' }
t.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
})

test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
Expand All @@ -75,7 +75,7 @@ test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
})

const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
t.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
})

test('additionalProperties - string coerce', (t) => {
Expand All @@ -90,7 +90,7 @@ test('additionalProperties - string coerce', (t) => {
})

const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
t.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
t.assert.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
})

test('additionalProperties - number skip', (t) => {
Expand All @@ -106,7 +106,7 @@ test('additionalProperties - number skip', (t) => {

// const obj = { foo: true, ofoo: '42', xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
const obj = { foo: true, ofoo: '42' }
t.equal(stringify(obj), '{"foo":1,"ofoo":42}')
t.assert.equal(stringify(obj), '{"foo":1,"ofoo":42}')
})

test('additionalProperties - boolean coerce', (t) => {
Expand All @@ -121,7 +121,7 @@ test('additionalProperties - boolean coerce', (t) => {
})

const obj = { foo: 'true', ofoo: 0, arrfoo: [1, 2], objfoo: { a: true } }
t.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
})

test('additionalProperties - object coerce', (t) => {
Expand All @@ -141,7 +141,7 @@ test('additionalProperties - object coerce', (t) => {
})

const obj = { objfoo: { answer: 42 } }
t.equal(stringify(obj), '{"objfoo":{"answer":42}}')
t.assert.equal(stringify(obj), '{"objfoo":{"answer":42}}')
})

test('additionalProperties - array coerce', (t) => {
Expand All @@ -159,10 +159,10 @@ test('additionalProperties - array coerce', (t) => {
})

const coercibleValues = { arrfoo: [1, 2] }
t.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
t.assert.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')

const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
t.throws(() => stringify(incoercibleValues))
t.assert.throws(() => stringify(incoercibleValues))
})

test('additionalProperties with empty schema', (t) => {
Expand All @@ -173,7 +173,7 @@ test('additionalProperties with empty schema', (t) => {
})

const obj = { a: 1, b: true, c: null }
t.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
t.assert.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
})

test('additionalProperties with nested empty schema', (t) => {
Expand All @@ -187,7 +187,7 @@ test('additionalProperties with nested empty schema', (t) => {
})

const obj = { data: { a: 1, b: true, c: null } }
t.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
t.assert.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
})

test('nested additionalProperties', (t) => {
Expand All @@ -207,7 +207,7 @@ test('nested additionalProperties', (t) => {
})

const obj = [{ ap: { value: 'string' } }]
t.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
t.assert.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
})

test('very nested additionalProperties', (t) => {
Expand Down Expand Up @@ -244,7 +244,7 @@ test('very nested additionalProperties', (t) => {
})

const obj = [{ ap: { nested: { moarNested: { finally: { value: 'str' } } } } }]
t.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
t.assert.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
})

test('nested additionalProperties set to true', (t) => {
Expand All @@ -261,7 +261,7 @@ test('nested additionalProperties set to true', (t) => {
})

const obj = { ap: { value: 'string', someNumber: 42 } }
t.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
t.assert.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
})

test('field passed to fastSafeStringify as undefined should be removed', (t) => {
Expand All @@ -278,7 +278,7 @@ test('field passed to fastSafeStringify as undefined should be removed', (t) =>
})

const obj = { ap: { value: 'string', someNumber: undefined } }
t.equal(stringify(obj), '{"ap":{"value":"string"}}')
t.assert.equal(stringify(obj), '{"ap":{"value":"string"}}')
})

test('property without type but with enum, will acts as additionalProperties', (t) => {
Expand All @@ -294,7 +294,7 @@ test('property without type but with enum, will acts as additionalProperties', (
})

const obj = { ap: { additional: 'field' } }
t.equal(stringify(obj), '{"ap":{"additional":"field"}}')
t.assert.equal(stringify(obj), '{"ap":{"additional":"field"}}')
})

test('property without type but with enum, will acts as additionalProperties without overwriting', (t) => {
Expand All @@ -311,7 +311,7 @@ test('property without type but with enum, will acts as additionalProperties wit
})

const obj = { ap: { additional: 'field' } }
t.equal(stringify(obj), '{"ap":{}}')
t.assert.equal(stringify(obj), '{"ap":{}}')
})

test('function and symbol references are not serialized as undefined', (t) => {
Expand All @@ -328,5 +328,5 @@ test('function and symbol references are not serialized as undefined', (t) => {
})

const obj = { str: 'x', test: 'test', meth: () => 'x', sym: Symbol('x') }
t.equal(stringify(obj), '{"str":"x","test":"test"}')
t.assert.equal(stringify(obj), '{"str":"x","test":"test"}')
})
Loading