1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-02 09:34:19 -04:00
denoland-deno/cli/tests/unit/dispatch_json_test.ts
Bartek Iwańczuk 6c4da0e429
refactor: remove dispatch_json.js from cli/rt and cli/tsc (#7521)
Instead use Deno.core.jsonOpSync and Deno.core.jsonOpAsync
2020-09-16 22:22:43 +02:00

50 lines
1.5 KiB
TypeScript

import {
assertStrictEquals,
unitTest,
assertMatch,
} from "./test_util.ts";
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Deno {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var core: any; // eslint-disable-line no-var
}
}
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 argsObj = {
promiseId: "1. NEIN!",
path: "/tmp/P.I.S.C.I.X/yeah",
mode: 0o666,
options: {
read: true,
write: true,
create: true,
truncate: false,
append: false,
createNew: false,
},
};
const argsText = JSON.stringify(argsObj);
const argsBuf = new TextEncoder().encode(argsText);
const resBuf = Deno.core.send(opId, argsBuf);
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/);
});