1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-03 17:08:35 -05:00
denoland-deno/cli/tests/unit/dispatch_json_test.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

import { assertMatch, assertStrictEquals, unitTest } from "./test_util.ts";
declare global {
// deno-lint-ignore no-namespace
namespace Deno {
// deno-lint-ignore no-explicit-any
var core: any; // eslint-disable-line no-var
}
}
2020-03-20 09:38:34 -04:00
unitTest(function malformedJsonControlBuffer(): void {
const opId = Deno.core.ops()["op_open_sync"];
const argsBuf = new Uint8Array([1, 2, 3, 4, 5]);
const resBuf = Deno.core.send(opId, argsBuf);
const resText = new TextDecoder().decode(resBuf);
const resObj = JSON.parse(resText);
assertStrictEquals(resObj.ok, undefined);
assertStrictEquals(resObj.err.className, "SyntaxError");
assertMatch(resObj.err.message, /\bexpected value\b/);
});
unitTest(function invalidPromiseId(): void {
const opId = Deno.core.ops()["op_open_async"];
const reqBuf = new Uint8Array([0, 0, 0, 0, 0, 0, 0]);
const resBuf = Deno.core.send(opId, reqBuf);
const resText = new TextDecoder().decode(resBuf);
const resObj = JSON.parse(resText);
console.error(resText);
assertStrictEquals(resObj.ok, undefined);
assertStrictEquals(resObj.err.className, "TypeError");
assertMatch(resObj.err.message, /\bpromiseId\b/);
});