build(aio): allow render-examples to complete even if examples are broken

By setting `renderExamples.ignoreBrokenExamples = true` the doc-gen will
not fail if there is something wrong with an example. Instead it will
just log a warning.
This commit is contained in:
Peter Bacon Darwin
2017-10-30 21:25:48 +00:00
committed by Victor Berchet
parent feae55b264
commit 3a03ff6b2d
2 changed files with 57 additions and 30 deletions

View File

@ -2,7 +2,7 @@ var testPackage = require('../../helpers/test-package');
var Dgeni = require('dgeni');
describe('renderExamples processor', () => {
var injector, processor, exampleMap, collectExamples;
var injector, processor, exampleMap, collectExamples, log;
beforeEach(function() {
const dgeni = new Dgeni([testPackage('examples-package', true)]);
@ -12,6 +12,7 @@ describe('renderExamples processor', () => {
processor = injector.get('renderExamples');
collectExamples = injector.get('collectExamples');
exampleMap = injector.get('exampleMap');
log = injector.get('log');
collectExamples.exampleFolders = ['examples'];
exampleMap['examples'] = {
@ -97,6 +98,25 @@ describe('renderExamples processor', () => {
'Badly formed example: <' + CODE_TAG + ' path="test/url"></p> - closing tag does not match opening tag.\n' +
' - Perhaps you forgot to put a blank line before the example?');
});
it('should not throw if `ignoreBrokenExamples` is set to true', () => {
processor.ignoreBrokenExamples = true;
const docs = [
{ renderedContent: `<${CODE_TAG} path="test/url"></p></${CODE_TAG}>`},
{ renderedContent: `<${CODE_TAG} path="test/url" region="missing"></${CODE_TAG}>`},
{ renderedContent: `<${CODE_TAG} path="missing/url"></${CODE_TAG}>`}
];
expect(() => processor.$process(docs)).not.toThrow();
expect(log.warn).toHaveBeenCalledWith(
'Badly formed example: <' + CODE_TAG + ' path="test/url"></p> - closing tag does not match opening tag.\n' +
' - Perhaps you forgot to put a blank line before the example? - doc');
expect(log.warn).toHaveBeenCalledWith(
'Missing example region... relativePath: "test/url", region: "missing". - doc\n' +
'Regions available are: "", "region-1" - doc');
expect(log.warn).toHaveBeenCalledWith(
'Missing example file... relativePath: "missing/url". - doc\n' +
'Example files can be found in the following relative paths: "examples" - doc');
});
})
);
});