diff options
Diffstat (limited to 'cli/tests/unit')
-rw-r--r-- | cli/tests/unit/broadcast_channel_test.ts | 27 | ||||
-rw-r--r-- | cli/tests/unit/utime_test.ts | 39 | ||||
-rw-r--r-- | cli/tests/unit/version_test.ts | 3 |
3 files changed, 68 insertions, 1 deletions
diff --git a/cli/tests/unit/broadcast_channel_test.ts b/cli/tests/unit/broadcast_channel_test.ts new file mode 100644 index 000000000..cfa62c856 --- /dev/null +++ b/cli/tests/unit/broadcast_channel_test.ts @@ -0,0 +1,27 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../test_util/std/async/deferred.ts"; + +Deno.test("broadcastchannel worker", async () => { + const intercom = new BroadcastChannel("intercom"); + let count = 0; + + const url = new URL("../workers/broadcast_channel.ts", import.meta.url); + const worker = new Worker(url.href, { type: "module", name: "worker" }); + worker.onmessage = () => intercom.postMessage(++count); + + const promise = deferred(); + + intercom.onmessage = function (e) { + assertEquals(count, e.data); + if (count < 42) { + intercom.postMessage(++count); + } else { + worker.terminate(); + intercom.close(); + promise.resolve(); + } + }; + + await promise; +}); diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index 4e56ff193..32b631406 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -3,6 +3,7 @@ import { assertEquals, assertThrows, assertThrowsAsync, + pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -71,6 +72,25 @@ unitTest( unitTest( { perms: { read: true, write: true } }, + function utimeSyncUrlSuccess(): void { + const testDir = Deno.makeTempDirSync(); + const filename = testDir + "/file.txt"; + Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { + mode: 0o666, + }); + + const atime = 1000; + const mtime = 50000; + Deno.utimeSync(pathToAbsoluteFileUrl(filename), atime, mtime); + + const fileInfo = Deno.statSync(filename); + assertEquals(fileInfo.atime, new Date(atime * 1000)); + assertEquals(fileInfo.mtime, new Date(mtime * 1000)); + }, +); + +unitTest( + { perms: { read: true, write: true } }, function utimeSyncDirectorySuccess(): void { const testDir = Deno.makeTempDirSync(); @@ -179,6 +199,25 @@ unitTest( unitTest( { perms: { read: true, write: true } }, + async function utimeUrlSuccess(): Promise<void> { + const testDir = Deno.makeTempDirSync(); + const filename = testDir + "/file.txt"; + Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { + mode: 0o666, + }); + + const atime = 1000; + const mtime = 50000; + await Deno.utime(pathToAbsoluteFileUrl(filename), atime, mtime); + + const fileInfo = Deno.statSync(filename); + assertEquals(fileInfo.atime, new Date(atime * 1000)); + assertEquals(fileInfo.mtime, new Date(mtime * 1000)); + }, +); + +unitTest( + { perms: { read: true, write: true } }, async function utimeDirectorySuccess(): Promise<void> { const testDir = Deno.makeTempDirSync(); diff --git a/cli/tests/unit/version_test.ts b/cli/tests/unit/version_test.ts index 91bbb260f..d3a5270c9 100644 --- a/cli/tests/unit/version_test.ts +++ b/cli/tests/unit/version_test.ts @@ -7,6 +7,7 @@ unitTest(function version(): void { // Unreleased version of TypeScript now set the version to 0-dev assert( pattern.test(Deno.version.typescript) || - Deno.version.typescript === "0-dev", + Deno.version.typescript === "0-dev" || + Deno.version.typescript === "0-beta", ); }); |