build(docs-infra): log warning rather than error if content errors are not fatal (#24320)

PR Close #24320
This commit is contained in:
Pete Bacon Darwin
2018-06-06 12:22:25 +01:00
committed by Victor Berchet
parent 68d37ef0c1
commit 700e55ce14
2 changed files with 31 additions and 16 deletions

View File

@ -67,10 +67,11 @@ describe('checkContentRules processor', function() {
expect(descriptionSpy3).toHaveBeenCalledWith(docs[0], 'description', 'test doc 1');
});
it('should log errors if the rule returns error messages', () => {
it('should log warnings if the rule returns error messages and `failOnContentErrors` is false', () => {
const nameSpy1 = jasmine.createSpy('name 1').and.returnValue('name error message');
const descriptionSpy1 = jasmine.createSpy('description 1').and.returnValue('description error message');
processor.failOnContentErrors = false;
processor.docTypeRules = {
'test1': {
name: [nameSpy1],
@ -85,6 +86,32 @@ describe('checkContentRules processor', function() {
processor.$process(docs);
expect(logger.warn).toHaveBeenCalledTimes(2);
expect(logger.warn).toHaveBeenCalledWith('Content contains errors');
expect(logger.warn).toHaveBeenCalledWith(`name error message
description error message
- doc "test-1" (test1) `);
});
it('should log errors and then throw if `failOnContentErrors` is true and errors are found', () => {
const nameSpy1 = jasmine.createSpy('name 1').and.returnValue('name error message');
const descriptionSpy1 = jasmine.createSpy('description 1').and.returnValue('description error message');
processor.failOnContentErrors = true;
processor.docTypeRules = {
'test1': {
name: [nameSpy1],
description: [descriptionSpy1]
}
};
const docs = [
{ docType: 'test1', description: 'test doc 1', name: 'test-1' },
{ docType: 'test2', description: 'test doc 2', name: 'test-2' }
];
expect(() => processor.$process(docs)).toThrowError('Stopping due to content errors.');
expect(logger.error).toHaveBeenCalledTimes(2);
expect(logger.error).toHaveBeenCalledWith('Content contains errors');
expect(logger.error).toHaveBeenCalledWith(`name error message
@ -92,17 +119,4 @@ describe('checkContentRules processor', function() {
- doc "test-1" (test1) `);
});
it('should throw an error if `failOnContentErrors` is true and errors are found', () => {
const errorRule = jasmine.createSpy('error rule').and.returnValue('some error');
processor.docTypeRules = {
'test': { description: [errorRule] }
};
processor.failOnContentErrors = true;
const docs = [
{ docType: 'test', description: 'test doc' },
];
expect(() => processor.$process(docs)).toThrowError('Stopping due to content errors.');
});
});