fix(visitor): remove error method from context
BREAKING CHANGE: rule errors must be grouped and returned in the rule result, fixing #114 and keeping the context immutable.
This commit is contained in:
parent
247e1ab03d
commit
842006c34a
|
@ -1,6 +1,6 @@
|
|||
import Ajv from 'ajv';
|
||||
import { JSONPath } from 'jsonpath-plus';
|
||||
import { Logger, logWithLevel } from 'noicejs';
|
||||
import { Logger } from 'noicejs';
|
||||
|
||||
import { doesExist, hasItems } from '../utils';
|
||||
import { VisitorError } from './VisitorError';
|
||||
|
@ -63,14 +63,6 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
|
|||
return this.ajv.compile(schema);
|
||||
}
|
||||
|
||||
public error(...errors: Array<VisitorError>) {
|
||||
for (const err of errors) {
|
||||
logWithLevel(this.logger, err.level, err.data, err.msg);
|
||||
}
|
||||
|
||||
this.errorBuffer.push(...errors);
|
||||
}
|
||||
|
||||
public mergeResult(other: VisitorResult): this {
|
||||
this.changeBuffer.push(...other.changes);
|
||||
this.errorBuffer.push(...other.errors);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
import { ConsoleLogger } from 'noicejs';
|
||||
import { mock, spy } from 'sinon';
|
||||
import { mock } from 'sinon';
|
||||
|
||||
import { createRuleSelector, resolveRules, visitRules } from '../../src/rule';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule';
|
||||
|
@ -203,7 +203,6 @@ describeLeaks('rule visitor', async () => {
|
|||
},
|
||||
logger: new ConsoleLogger(),
|
||||
});
|
||||
const errorSpy = spy(ctx, 'error');
|
||||
|
||||
const data = {
|
||||
foo: 3,
|
||||
|
@ -227,6 +226,5 @@ describeLeaks('rule visitor', async () => {
|
|||
|
||||
const results = await rule.visit(ctx, data);
|
||||
expect(results.errors.length).to.equal(0);
|
||||
expect(errorSpy).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue