Skip to content

Commit

Permalink
Add some initial tests for JSON modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed May 8, 2019
1 parent b7aa0fb commit 535c067
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules: Content-Type</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
function check(t, v) {
t.step(() => {
assert_equals(typeof v, "object");
assert_array_equals(Object.keys(v), ["test"]);
assert_equals(v.test, true);
t.done();
});
}
const t1 = async_test("text/json");
const t2 = async_test("application/json");
const t3 = async_test("text/html+json");
const t4 = async_test("image/svg+json");
</script>
<script type="module" onerror="t1.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=text/json";
check(t1, v);
</script>
<script type="module" onerror="t2.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=application/json";
check(t2, v);
</script>
<script type="module" onerror="t3.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=text/html+json";
check(t3, v);
</script>
<script type="module" onerror="t4.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/module.json&ct=image/svg+json";
check(t4, v);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
const t = async_test();
</script>
<script type="module" onerror="t.step(() => assert_unreached(event))">
import v from "./module.json";
t.step(() => {
assert_equals(typeof v, "object");
assert_array_equals(Object.keys(v), ["test"]);
assert_equals(v.test, true);
t.done();
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules: Content-Type</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
setup({
allow_uncaught_exception: true,
});
async_test(t => {
window.addEventListener("error", t.step_func_done(e => {
assert_true(e instanceof ErrorEvent, "ErrorEvent");
assert_equals(e.filename, new URL("parse-error.json", location).href);
assert_true(e.error instanceof SyntaxError, "SyntaxError");
}));
});
</script>
<script type="module">
import v from "./parse-error.json";
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules: UTF-8 decoding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
function check(t, v) {
t.step(() => {
assert_equals(typeof v, "object");
assert_array_equals(Object.keys(v), ["test"]);
assert_equals(v.test, "\u2026");
t.done();
});
}
const t1 = async_test("utf-8");
const t2 = async_test("shift-jis");
const t3 = async_test("windows-1252");
const t4 = async_test("utf-7");
</script>
<script type="module" onerror="t1.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=utf-8";
check(t1, v);
</script>
<script type="module" onerror="t2.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=shift-jis";
check(t2, v);
</script>
<script type="module" onerror="t3.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=windows-1252";
check(t3, v);
</script>
<script type="module" onerror="t4.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=json-module/utf8.json&ct=text/json%3Bcharset=utf-7";
check(t4, v);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": ""
}

0 comments on commit 535c067

Please sign in to comment.