diff --git a/.gitattributes b/.gitattributes index f15f4c37d57aa3de748013d103806f5dc6b1b8c0..0b3baca9dad56ef3cba020327d987302070b1493 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ lib/** -diff -dist/** -diff +dist/** -diff binary locale/* -diff package-lock.json -diff diff --git a/package.json b/package.json index 1ca1d336b471541757be7a365b0dcb8482610088..bc95547001f6ef0918ae4ed78622a6a29e870161 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build:node": "bili src/index.js --minimal --format es --format cjs", "build": "npm run build:browser && npm run build:node", "dev": "npm test -- -w", - "test": "npm run test:unit --", + "test": "npm run lint && npm run test:unit -- && npm run test:schema", "test:ci": "npm run coverage:all && npm run report -- -r lcov", "test:all": "npm run test:run tests && npm run report -- -r html", "test:run": "NODE_ENV=test _mocha --exit --recursive --watch-extensions js,json -r esm -bR spec", diff --git a/tests/schema/core/issues/all-of-one-of-nested.json b/tests/schema/core/issues/all-of-one-of-nested.json new file mode 100644 index 0000000000000000000000000000000000000000..674e211888def9da6c4910362273d864c84c05bc --- /dev/null +++ b/tests/schema/core/issues/all-of-one-of-nested.json @@ -0,0 +1,41 @@ +[ + { + "description": "allOf and oneOff nested", + "schemas": [{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "date_of_birth": { + "type": "string", + "minimum": 10, + "maximum": 10 + }, + "age_group": { + "type": "string", + "minLength": 5, + "maxLength": 5 + } + }, + + "allOf": [{ + "oneOf": [{ + "required": [ + "age_group" + ] + }, { + "required": [ + "date_of_birth" + ] + }] + }] + }], + "tests": [ + { + "description": "should combine recursively", + "schema": "schemas.0", + "valid": true + } + ] + } +] diff --git a/tests/schema/core/issues/issue-345.json b/tests/schema/core/issues/issue-345.json index e66eee57bad77334ea6b8664645f757a41e7b8d8..cd13636b8558dd24177c796453182f546b29b65d 100644 --- a/tests/schema/core/issues/issue-345.json +++ b/tests/schema/core/issues/issue-345.json @@ -38,7 +38,7 @@ "additionalProperties": false }, "set": { - "alwaysFakeOptionals": true + "optionalsProbability": 0.75 }, "skip": true, "valid": true diff --git a/tests/schema/core/option/alwaysFakeOptionalsNoAdditional.json b/tests/schema/core/option/alwaysFakeOptionalsNoAdditional.json new file mode 100644 index 0000000000000000000000000000000000000000..cac7b1689bcf30a8b0995fd55e98083126520ed3 --- /dev/null +++ b/tests/schema/core/option/alwaysFakeOptionalsNoAdditional.json @@ -0,0 +1,33 @@ +[ + { + "description": "alwaysFakeOptionals option with additionalProperties: false", + "tests": [ + { + "description": "should handle alwaysFakeOptionals option (= true) for objects", + "schema": { + "type": "object", + "properties": { + "optionalProperty1": { "type": "number", "default": 1 }, + "optionalProperty2": { "type": "number", "default": 1 }, + "optionalProperty3": { "type": "number", "default": 1 }, + "optionalProperty4": { "type": "number", "default": 1 }, + "optionalProperty5": { "type": "number", "default": 1 } + }, + "additionalProperties": false + }, + "valid": true, + "equal": { + "optionalProperty1": 1, + "optionalProperty2": 1, + "optionalProperty3": 1, + "optionalProperty4": 1, + "optionalProperty5": 1 + }, + "set": { + "alwaysFakeOptionals": true, + "useDefaultValue": true + } + } + ] + } +] diff --git a/tests/schema/helpers.js b/tests/schema/helpers.js index 8573eb6de54fb8ac813bb15f4a74c067d60a89eb..02546f83ff5a35bae91daeb7def3200e8f76c004 100644 --- a/tests/schema/helpers.js +++ b/tests/schema/helpers.js @@ -82,7 +82,7 @@ export function tryTest(test, refs, schema) { test.notEmpty.forEach(x => { const value = pick(sample, x); - if (value.length === 0) { + if (value === undefined || (Array.isArray(value) && !value.length)) { throw new Error(`${x} should not be empty`); } }); diff --git a/tests/unit/core/utils.spec.js b/tests/unit/core/utils.spec.js index ac59813e9bebe4a10c4c6479120fb46c478308e2..dcef485936080b96d936fbc85fb875954468a199 100644 --- a/tests/unit/core/utils.spec.js +++ b/tests/unit/core/utils.spec.js @@ -101,4 +101,26 @@ describe('Utils', () => { }); }); }); + + describe('clone function', () => { + it('should handle circular refs in objects', () => { + const a = {}; + const b = { + a, + }; + a.b = b; + + const clone = utils.clone(a); + expect(clone.b.a).to.eql(clone); + }); + + it('should handle circular refs in arrays', () => { + const a = []; + const b = [a]; + a.push(b); + + const clone = utils.clone(a); + expect(clone[0][0]).to.eql(clone); + }); + }); });