Skip to content

Commit

Permalink
Add tests for missing or invalid content-type headers
Browse files Browse the repository at this point in the history
  • Loading branch information
brandones committed Jun 26, 2020
1 parent 492f9c3 commit 5b674cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions test/browser/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ suite('SystemJS Standard Tests', function() {
});
});

test('Errors for bad Content-Type headers', function () {
return System.import('fixtures/content-type-none.json')
.catch(function (err) {
assert.ok(/missing.*content-type.*error#4/i.test(err));
})
.then(function () {
return System.import('fixtures/content-type-xml.json')
})
.catch(function (err) {
assert.ok(/unknown module type.*xml.*error#4/i.test(err));
})
});

if (typeof Worker !== 'undefined')
test('Using SystemJS in a Web Worker', function () {
const worker = new Worker('./browser/worker.js');
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/browser/content-type-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ok": "content but",
"no": "content-type"
}
3 changes: 3 additions & 0 deletions test/fixtures/browser/content-type-xml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"strange": "content-type header"
}
9 changes: 6 additions & 3 deletions test/server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ http.createServer(async function (req, res) {
let mime;
if (filePath.endsWith('javascript.css'))
mime = 'application/javascript';
else if (filePath.endsWith('content-type-xml.json'))
mime = 'application/xml';
else
mime = mimes[path.extname(filePath)] || 'text/plain';

res.writeHead(200, {
'content-type': mime
});
const headers = filePath.endsWith('content-type-none.json') ?
{} : { 'content-type': mime }

res.writeHead(200, headers);
fileStream.pipe(res);
await once(fileStream, 'end');
res.end();
Expand Down

0 comments on commit 5b674cf

Please sign in to comment.