2020-08-18 08:07:57 -04:00
|
|
|
import {
|
|
|
|
assertStrictEquals,
|
|
|
|
unitTest,
|
|
|
|
assertMatch,
|
|
|
|
unreachable,
|
|
|
|
} from "./test_util.ts";
|
2019-08-27 11:33:39 -04:00
|
|
|
|
|
|
|
const openErrorStackPattern = new RegExp(
|
|
|
|
`^.*
|
2020-07-19 13:49:44 -04:00
|
|
|
at unwrapResponse \\(.*dispatch_json\\.js:.*\\)
|
|
|
|
at sendAsync \\(.*dispatch_json\\.js:.*\\)
|
|
|
|
at async Object\\.open \\(.*files\\.js:.*\\).*$`,
|
2020-07-14 15:24:17 -04:00
|
|
|
"ms",
|
2019-08-27 11:33:39 -04:00
|
|
|
);
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { read: true } },
|
|
|
|
async function sendAsyncStackTrace(): Promise<void> {
|
|
|
|
await Deno.open("nonexistent.txt")
|
|
|
|
.then(unreachable)
|
|
|
|
.catch((error): void => {
|
|
|
|
assertMatch(error.stack, openErrorStackPattern);
|
|
|
|
});
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-10-25 13:23:16 -04:00
|
|
|
|
2020-06-02 00:24:44 -04:00
|
|
|
declare global {
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
2020-06-02 00:24:44 -04:00
|
|
|
namespace Deno {
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
var core: any; // eslint-disable-line no-var
|
2020-06-02 00:24:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 09:38:34 -04:00
|
|
|
unitTest(function malformedJsonControlBuffer(): void {
|
2020-08-18 08:07:57 -04:00
|
|
|
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);
|
2020-08-25 18:22:15 -04:00
|
|
|
assertStrictEquals(resObj.err.kind, "SyntaxError");
|
2020-08-18 08:07:57 -04:00
|
|
|
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.kind, "TypeError");
|
|
|
|
assertMatch(resObj.err.message, /\bpromiseId\b/);
|
2019-10-25 13:23:16 -04:00
|
|
|
});
|