Skip to content

Commit

Permalink
Add tests for MIME types
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank3K committed Nov 30, 2023
1 parent 229cf19 commit fded911
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/base3/test3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!doctype html>
File: /base3/test3.html
<script src="dest.js"></script>
<script src="mime.js"></script>
1 change: 1 addition & 0 deletions test/fixtures/demo.abc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
1 change: 1 addition & 0 deletions test/fixtures/demo.fgh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
3 changes: 3 additions & 0 deletions test/fixtures/demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prop": 123
}
14 changes: 14 additions & 0 deletions test/frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
width: 200px;
border: 1px solid #ccc;
}
iframe.auto-height {
height: auto;
}
td[colspan="3"] iframe {
width: 100%;
}
th {
padding-top: 1rem;
letter-spacing: 1px;
Expand Down Expand Up @@ -54,4 +60,12 @@
<td><iframe src="./base1/test2.html"></iframe></td>
<td><iframe src="./base2/test2.html"></iframe></td>
</tr>
<tr>
<th></th>
<th colspan="3">MIME types</th>
</tr>
<tr>
<td>test3.html</td>
<td colspan="3"><iframe src="./test3.html" class="auto-height"></iframe></td>
</tr>
</table>
24 changes: 24 additions & 0 deletions test/mime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

async function getMimeType(path) {
const response = await fetch(path);
return response.headers.get("Content-Type");
}

async function checkMimes() {
const paths = [
"fixtures/demo.json",
"fixtures/demo.abc",
"fixtures/demo.fgh",
];
for (const path of paths) {
const mimeType = await getMimeType(path);
document.body.innerHTML += '<br>"' + path + '": ' + mimeType;
}
}

if (document.readyState === "loading") {
window.addEventListener("DOMContentLoaded", checkMimes);
} else {
checkMimes();
}
5 changes: 4 additions & 1 deletion test/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export default {
open: true,
openPage: '/frames.html',
historyApiFallback: '/fallback.html',
contentBase: ['.', 'base1', 'base2'],
contentBase: ['.', 'base1', 'base2', 'base3'],
onListening: testOnListening(),
mimeTypes: {
'text/x-abc': ['abc'],
}
})
]
}

0 comments on commit fded911

Please sign in to comment.