summaryrefslogtreecommitdiff
path: root/js/unit_tests.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/unit_tests.ts')
-rw-r--r--js/unit_tests.ts15
1 files changed, 7 insertions, 8 deletions
diff --git a/js/unit_tests.ts b/js/unit_tests.ts
index bbe93f5e1..17ddd5256 100644
--- a/js/unit_tests.ts
+++ b/js/unit_tests.ts
@@ -3,8 +3,7 @@
// But it can also be run manually:
// ./deno tests.ts
-import { test, assert, assertEqual } from "./testing/testing.ts";
-import { readFileSync } from "deno";
+import { test, testPerm, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
import "./compiler_test.ts";
@@ -15,7 +14,7 @@ test(async function tests_test() {
});
test(async function tests_readFileSync() {
- const data = readFileSync("package.json");
+ const data = deno.readFileSync("package.json");
if (!data.byteLength) {
throw Error(
`Expected positive value for data.byteLength ${data.byteLength}`
@@ -32,7 +31,7 @@ test(function tests_readFileSync_NotFound() {
let caughtError = false;
let data;
try {
- data = readFileSync("bad_filename");
+ data = deno.readFileSync("bad_filename");
} catch (e) {
caughtError = true;
assert(e instanceof deno.NotFound);
@@ -48,14 +47,14 @@ test(function writeFileSyncSuccess() {
const dataWritten = enc.encode("Hello");
const filename = "TEMPDIR/test.txt";
deno.writeFileSync(filename, dataWritten, 0o666);
- const dataRead = readFileSync(filename);
+ const dataRead = deno.readFileSync(filename);
assertEqual(dataRead, dataWritten);
});
*/
// For this test to pass we need --allow-write permission.
// Otherwise it will fail with deno.PermissionDenied instead of deno.NotFound.
-test(function writeFileSyncFail() {
+testPerm({ write: true }, function writeFileSyncFail() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const filename = "/baddir/test.txt";
@@ -71,7 +70,7 @@ test(function writeFileSyncFail() {
assert(caughtError);
});
-test(async function tests_fetch() {
+testPerm({ net: true }, async function tests_fetch() {
const response = await fetch("http://localhost:4545/package.json");
const json = await response.json();
assertEqual(json.name, "deno");
@@ -84,7 +83,7 @@ test(async function tests_writeFileSync() {
// TODO need ability to get tmp dir.
const fn = "/tmp/test.txt";
writeFileSync("/tmp/test.txt", data, 0o666);
- const dataRead = readFileSync("/tmp/test.txt");
+ const dataRead = deno.readFileSync("/tmp/test.txt");
const dec = new TextDecoder("utf-8");
const actual = dec.decode(dataRead);
assertEqual("Hello", actual);