diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-22 13:19:32 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-22 18:39:07 -0400 |
commit | 7d7263c48f4280f8da5496273e85fb1a8fb79547 (patch) | |
tree | 709df115d6d2daf5a753a31a69bac637d65a33a7 /js/unit_tests.ts | |
parent | e7cab715749e4c5000c24ffeade1ef915d15a68d (diff) |
Implement writeFileSync
In collaboration with Tommy Savaria <tommy.savaria@protonmail.ch>
Diffstat (limited to 'js/unit_tests.ts')
-rw-r--r-- | js/unit_tests.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/js/unit_tests.ts b/js/unit_tests.ts index f203444fa..6eebf8860 100644 --- a/js/unit_tests.ts +++ b/js/unit_tests.ts @@ -5,6 +5,7 @@ import { test, assert, assertEqual } from "./testing/testing.ts"; import { readFileSync } from "deno"; +import * as deno from "deno"; import "./compiler_test.ts"; @@ -109,6 +110,35 @@ test(function tests_readFileSync_NotFound() { }); */ +/* TODO(ry) Add this once we can create a tmpDir to write the file into. +test(function writeFileSyncSuccess() { + const enc = new TextEncoder(); + const dataWritten = enc.encode("Hello"); + const filename = "TEMPDIR/test.txt"; + deno.writeFileSync(filename, dataWritten, 0o666); + const dataRead = 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() { + const enc = new TextEncoder(); + const data = enc.encode("Hello"); + const filename = "/baddir/test.txt"; + // The following should fail because /baddir doesn't exist (hopefully). + let caughtError = false; + try { + deno.writeFileSync(filename, data); + } catch (e) { + caughtError = true; + // TODO assertEqual(e, deno.NotFound); + assertEqual(e.name, "deno.NotFound"); + } + assert(caughtError); +}); + test(async function tests_fetch() { const response = await fetch("http://localhost:4545/package.json"); const json = await response.json(); |