Validate on top-level settings and use pre-compiled ajv

This commit is contained in:
Shin'ya Ueoka 2019-12-03 18:11:32 +09:00
parent 2318e3a555
commit 776977e0dc
11 changed files with 397 additions and 487 deletions

View file

@ -16,16 +16,6 @@ describe('BlacklistItem', () => {
expect(item.partial).to.be.true;
expect(item.keys).to.deep.equal(['j', 'k']);
});
it('throws a TypeError', () => {
expect(() => BlacklistItem.fromJSON(null)).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON(100)).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON({})).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON({url: 'google.com'})).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON({keys: ['a']})).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON({url: 'google.com', keys: 10})).to.throw(TypeError);
expect(() => BlacklistItem.fromJSON({url: 'google.com', keys: ['a', 'b', 3]})).to.throw(TypeError);
});
});
describe('#matches', () => {
@ -118,14 +108,6 @@ describe('Blacklist', () => {
let blacklist = Blacklist.fromJSON([]);
expect(blacklist.toJSON()).to.deep.equals([]);
});
it('throws a TypeError', () => {
expect(() => Blacklist.fromJSON(null)).to.throw(TypeError);
expect(() => Blacklist.fromJSON(100)).to.throw(TypeError);
expect(() => Blacklist.fromJSON({})).to.throw(TypeError);
expect(() => Blacklist.fromJSON([100])).to.throw(TypeError);
expect(() => Blacklist.fromJSON([{}])).to.throw(TypeError);
})
});
describe('#includesEntireBlacklist', () => {

View file

@ -19,7 +19,6 @@ describe('Keymaps', () => {
});
it('throws a TypeError by invalid settings', () => {
expect(() => Keymaps.fromJSON(null)).to.throw(TypeError);
expect(() => Keymaps.fromJSON({
k: { type: "invalid.operation" },
})).to.throw(TypeError);

View file

@ -26,19 +26,6 @@ describe('Search', () => {
});
it('throws a TypeError by invalid settings', () => {
expect(() => Search.fromJSON(null)).to.throw(TypeError);
expect(() => Search.fromJSON({})).to.throw(TypeError);
expect(() => Search.fromJSON([])).to.throw(TypeError);
expect(() => Search.fromJSON({
default: 123,
engines: {}
})).to.throw(TypeError);
expect(() => Search.fromJSON({
default: 'google',
engines: {
'google': 123456,
}
})).to.throw(TypeError);
expect(() => Search.fromJSON({
default: 'wikipedia',
engines: {