build(aio): fail doc-gen if referenced images are missing
This commit is contained in:
parent
9d97163c64
commit
c453b7bcfa
@ -20,14 +20,16 @@ module.exports = function addImageDimensions(getImageDimensions) {
|
|||||||
const src = props.src;
|
const src = props.src;
|
||||||
if (!src) {
|
if (!src) {
|
||||||
file.message('Missing src in image tag `' + source(node, file) + '`');
|
file.message('Missing src in image tag `' + source(node, file) + '`');
|
||||||
} else if (props.width === undefined && props.height === undefined) {
|
} else {
|
||||||
try {
|
try {
|
||||||
const dimensions = getImageDimensions(addImageDimensionsImpl.basePath, src);
|
const dimensions = getImageDimensions(addImageDimensionsImpl.basePath, src);
|
||||||
props.width = '' + dimensions.width;
|
if (props.width === undefined && props.height === undefined) {
|
||||||
props.height = '' + dimensions.height;
|
props.width = '' + dimensions.width;
|
||||||
|
props.height = '' + dimensions.height;
|
||||||
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e.code === 'ENOENT') {
|
if (e.code === 'ENOENT') {
|
||||||
file.message('Unable to load src in image tag `' + source(node, file) + '`');
|
file.fail('Unable to load src in image tag `' + source(node, file) + '`');
|
||||||
} else {
|
} else {
|
||||||
file.fail(e.message);
|
file.fail(e.message);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ describe('addImageDimensions post-processor', () => {
|
|||||||
expect(log.warn).toHaveBeenCalled();
|
expect(log.warn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log a warning for images whose source cannot be loaded', () => {
|
it('should fail for images whose source cannot be loaded', () => {
|
||||||
getImageDimensionsSpy.and.callFake(() => {
|
getImageDimensionsSpy.and.callFake(() => {
|
||||||
const error = new Error('no such file or directory');
|
const error = new Error('no such file or directory');
|
||||||
error.code = 'ENOENT';
|
error.code = 'ENOENT';
|
||||||
@ -68,13 +68,8 @@ describe('addImageDimensions post-processor', () => {
|
|||||||
docType: 'a',
|
docType: 'a',
|
||||||
renderedContent: '<img src="missing">'
|
renderedContent: '<img src="missing">'
|
||||||
}];
|
}];
|
||||||
processor.$process(docs);
|
expect(() => processor.$process(docs)).toThrowError('Unable to load src in image tag `<img src="missing">` - doc (a) ');
|
||||||
expect(getImageDimensionsSpy).toHaveBeenCalled();
|
expect(getImageDimensionsSpy).toHaveBeenCalled();
|
||||||
expect(docs).toEqual([jasmine.objectContaining({
|
|
||||||
docType: 'a',
|
|
||||||
renderedContent: '<img src="missing">'
|
|
||||||
})]);
|
|
||||||
expect(log.warn).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore images with width or height attributes', () => {
|
it('should ignore images with width or height attributes', () => {
|
||||||
@ -87,7 +82,6 @@ describe('addImageDimensions post-processor', () => {
|
|||||||
`
|
`
|
||||||
}];
|
}];
|
||||||
processor.$process(docs);
|
processor.$process(docs);
|
||||||
expect(getImageDimensionsSpy).not.toHaveBeenCalled();
|
|
||||||
expect(docs).toEqual([jasmine.objectContaining({
|
expect(docs).toEqual([jasmine.objectContaining({
|
||||||
docType: 'a',
|
docType: 'a',
|
||||||
renderedContent: `
|
renderedContent: `
|
||||||
|
Loading…
x
Reference in New Issue
Block a user