Skip to content

Commit

Permalink
Complain if an asset loading during the regular population comes out …
Browse files Browse the repository at this point in the history
…with conflicting types
  • Loading branch information
papandreou committed Mar 30, 2018
1 parent dde0466 commit 6a2f39b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ async function hyperlink({
function handleError(error) {
const message = error.message || error;
const asset = error.asset || (error.relation && error.relation.to);

const report = {
ok: false,
name: `Failed loading ${error.relation ? 'relation' : (asset && asset.urlOrDescription || 'asset')}`,
Expand Down
50 changes: 50 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,56 @@ describe('hyperlink', function () {
});
});

it('should complain if an asset loaded has an unexpected Content-Type', async function () {
httpception([
{
request: 'GET https://example.com/',
response: {
statusCode: 200,
headers: {
'Content-Type': 'text/html; charset=UTF-8'
},
body: `
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
</body>
</html>
`
}
},
{
request: 'GET https://example.com/styles.css',
response: {
headers: {
'Content-Type': 'image/png'
},
body: 'div { color: maroon; }'
}
}
]);

const t = new TapRender();
sinon.spy(t, 'push');
await hyperlink({
root: 'https://example.com/',
inputUrls: [ 'https://example.com/' ]
}, t);

expect(t.close(), 'to satisfy', {fail: 1});
expect(t.push, 'to have a call satisfying', () => {
t.push(null, {
ok: false,
operator: 'error',
actual: 'https://example.com/styles.css: Asset is used as both Css and Png',
at: 'https://example.com/ (5:58) <link rel="stylesheet" href="styles.css">'
});
});
});

it('should complain if an asset being HEADed has an unexpected Content-Type', async function () {
httpception([
{
Expand Down

0 comments on commit 6a2f39b

Please sign in to comment.