Skip to content

Commit

Permalink
Handle errors in inline assets better and improve CSS debug descripti…
Browse files Browse the repository at this point in the history
…on. semver-patch
  • Loading branch information
Munter committed Mar 6, 2017
1 parent 5c0c582 commit 00b4506
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/relationDebugDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ module.exports = function relationDebugDescription(relation) {

var offsets = [linesBefore.length, charsBefore.length + 1].join(':');

var details;
var details = '';

if (asset.type === 'Html') {
details = relation.node.outerHTML.split('>' + relation.node.innerHTML + '<').join('>...<');
var node = relation.node;

if (relation.from.isInline) {
details += 'inlined ' + relation.from.type + ': ';
}

// DOM node
if (node.outerHTML) {
details += node.outerHTML.split('>' + node.innerHTML + '<').join('>...<');
}

// CSS node
if (relation.propertyNode) {
details += relation.propertyNode.value;
}

if (asset.url.indexOf('file:') === 0) {
return [asset.urlOrDescription, offsets].join(':') + ' ' + details;
} else {
return asset.urlOrDescription + ' (' + offsets + ') ' + details;
}

return asset.urlOrDescription + ' (' + offsets + ') ' + details;
}

return asset.urlOrDescription;
Expand Down
15 changes: 15 additions & 0 deletions test/relationDebugDescription-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ describe('relationDebugDescription', function () {

expect(result, 'to end with', 'index.html (8:14) <a href="foo.html">...</a>');
});

it('should handle relations to inline assets', function () {
return new AssetGraph({ root: __dirname })
.loadAssets({
type: 'Html',
url: 'file://' + __dirname + '/index.html',
text: '<!doctype html><html><head><style>body { background: url(https://mntr.dk/invalid.png); }</style></head><body></body></html>'
})
.populate({ followRelations: { crossOrigin: false }})
.queue(function (assetGraph) {
var relation = assetGraph.findRelations({}, true)[1];
var result = relationDebugDescription(relation);
expect(result, 'to end with', 'index.html:1:58 inlined Css: url(https://mntr.dk/invalid.png)');
});
});
});

0 comments on commit 00b4506

Please sign in to comment.