diff --git a/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.js b/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.js index 1a068d00ee..075c0de44d 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.js +++ b/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.js @@ -20,14 +20,16 @@ module.exports = function addImageDimensions(getImageDimensions) { const src = props.src; if (!src) { file.message('Missing src in image tag `' + source(node, file) + '`'); - } else if (props.width === undefined && props.height === undefined) { + } else { try { const dimensions = getImageDimensions(addImageDimensionsImpl.basePath, src); - props.width = '' + dimensions.width; - props.height = '' + dimensions.height; + if (props.width === undefined && props.height === undefined) { + props.width = '' + dimensions.width; + props.height = '' + dimensions.height; + } } catch(e) { 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 { file.fail(e.message); } diff --git a/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.spec.js b/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.spec.js index 432fad9347..411984a889 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.spec.js +++ b/aio/tools/transforms/angular-base-package/post-processors/add-image-dimensions.spec.js @@ -58,7 +58,7 @@ describe('addImageDimensions post-processor', () => { 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(() => { const error = new Error('no such file or directory'); error.code = 'ENOENT'; @@ -68,13 +68,8 @@ describe('addImageDimensions post-processor', () => { docType: 'a', renderedContent: '' }]; - processor.$process(docs); + expect(() => processor.$process(docs)).toThrowError('Unable to load src in image tag `` - doc (a) '); expect(getImageDimensionsSpy).toHaveBeenCalled(); - expect(docs).toEqual([jasmine.objectContaining({ - docType: 'a', - renderedContent: '' - })]); - expect(log.warn).toHaveBeenCalled(); }); it('should ignore images with width or height attributes', () => { @@ -87,7 +82,6 @@ describe('addImageDimensions post-processor', () => { ` }]; processor.$process(docs); - expect(getImageDimensionsSpy).not.toHaveBeenCalled(); expect(docs).toEqual([jasmine.objectContaining({ docType: 'a', renderedContent: `