Skip to content

Commit

Permalink
Revert "Remove tests which cover the compatibility check"
Browse files Browse the repository at this point in the history
This reverts commit 6d10c78.
  • Loading branch information
papandreou committed Apr 4, 2019
1 parent 13e5f47 commit 7bc868c
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,113 @@ 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: 'content-type-mismatch',
name: 'content-type-mismatch https://example.com/styles.css',
actual: 'Asset is used as both Css and Png',
at:
'https://example.com/ (5:44) <link rel="stylesheet" href="styles.css">'
});
});
});

it('should complain if an asset being HEADed 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></head>
<body>
<img src="hey.png">
</body>
</html>
`
}
},
{
request: 'HEAD https://example.com/hey.png',
response: {
headers: {
'Content-Type': 'text/plain'
}
}
}
]);

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: 'content-type-mismatch',
name: 'content-type-mismatch https://example.com/hey.png',
actual: 'Asset is used as both Image and Text',
at: 'https://example.com/ (6:25) <img src="hey.png">'
});
});
});

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

0 comments on commit 7bc868c

Please sign in to comment.