Skip to content
Snippets Groups Projects
Commit 727ab185 authored by Ian Savchenko's avatar Ian Savchenko Committed by Alvaro Cabrera Durán
Browse files

Many small fixes (#512)

* Treat dist dir as binary, so the line endings are not normalized by git

This allows to avoid annoying behaviour when you checkout repo and already have a diff which can't be reset

* add necessary dev dependencies

* clone should handle circular refs

* fix handling nested allOf and oneOf with partial schema inside

* improve noEmpty test helper

* handle alwaysFakeOptionals + additionalProperties: false

* Fix previously hidden failing test: can't alwaysFakeOptionals recursively

* make npm test do what is supposed to do
parent 5df8f20c
Branches
Tags
No related merge requests found
lib/** -diff
dist/** -diff
dist/** -diff binary
locale/* -diff
package-lock.json -diff
......@@ -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",
......
[
{
"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
}
]
}
]
......@@ -38,7 +38,7 @@
"additionalProperties": false
},
"set": {
"alwaysFakeOptionals": true
"optionalsProbability": 0.75
},
"skip": true,
"valid": true
......
[
{
"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
}
}
]
}
]
......@@ -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`);
}
});
......
......@@ -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);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment