0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

refactor: remove "unitTest" wrapper from cli/tests/unit (#12750)

This commit is contained in:
Bartek Iwańczuk 2021-11-23 17:45:18 +01:00 committed by GitHub
parent 51e3db956a
commit bedb2adfb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
83 changed files with 1049 additions and 1163 deletions

View file

@ -1,4 +1,4 @@
unitTest( Deno.test(
{ perms: { net: true } }, { perms: { net: true } },
async function responseClone() { async function responseClone() {
const response = const response =

View file

@ -1,5 +1,5 @@
// This file should be excluded from formatting // This file should be excluded from formatting
unitTest( Deno.test(
{ perms: { net: true } }, { perms: { net: true } },
async function fetchBodyUsedCancelStream() { async function fetchBodyUsedCancelStream() {
const response = await fetch( const response = await fetch(

View file

@ -4,16 +4,16 @@ Files in this directory are unit tests for Deno runtime.
Testing Deno runtime code requires checking API under different runtime Testing Deno runtime code requires checking API under different runtime
permissions. To accomplish this all tests exercised are created using permissions. To accomplish this all tests exercised are created using
`unitTest()` function. `Deno.test()` function.
```ts ```ts
import { unitTest } from "./test_util.ts"; import {} from "./test_util.ts";
unitTest(function simpleTestFn(): void { Deno.test(function simpleTestFn(): void {
// test code here // test code here
}); });
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },

View file

@ -1,6 +1,6 @@
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
unitTest(function basicAbortController() { Deno.test(function basicAbortController() {
const controller = new AbortController(); const controller = new AbortController();
assert(controller); assert(controller);
const { signal } = controller; const { signal } = controller;
@ -10,7 +10,7 @@ unitTest(function basicAbortController() {
assertEquals(signal.aborted, true); assertEquals(signal.aborted, true);
}); });
unitTest(function signalCallsOnabort() { Deno.test(function signalCallsOnabort() {
const controller = new AbortController(); const controller = new AbortController();
const { signal } = controller; const { signal } = controller;
let called = false; let called = false;
@ -23,7 +23,7 @@ unitTest(function signalCallsOnabort() {
assert(called); assert(called);
}); });
unitTest(function signalEventListener() { Deno.test(function signalEventListener() {
const controller = new AbortController(); const controller = new AbortController();
const { signal } = controller; const { signal } = controller;
let called = false; let called = false;
@ -36,7 +36,7 @@ unitTest(function signalEventListener() {
assert(called); assert(called);
}); });
unitTest(function onlyAbortsOnce() { Deno.test(function onlyAbortsOnce() {
const controller = new AbortController(); const controller = new AbortController();
const { signal } = controller; const { signal } = controller;
let called = 0; let called = 0;
@ -50,12 +50,12 @@ unitTest(function onlyAbortsOnce() {
assertEquals(called, 2); assertEquals(called, 2);
}); });
unitTest(function controllerHasProperToString() { Deno.test(function controllerHasProperToString() {
const actual = Object.prototype.toString.call(new AbortController()); const actual = Object.prototype.toString.call(new AbortController());
assertEquals(actual, "[object AbortController]"); assertEquals(actual, "[object AbortController]");
}); });
unitTest(function abortReason() { Deno.test(function abortReason() {
const signal = AbortSignal.abort("hey!"); const signal = AbortSignal.abort("hey!");
assertEquals(signal.aborted, true); assertEquals(signal.aborted, true);
assertEquals(signal.reason, "hey!"); assertEquals(signal.reason, "hey!");

View file

@ -1,20 +1,15 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assert, assertEquals, assertStringIncludes } from "./test_util.ts";
assert,
assertEquals,
assertStringIncludes,
unitTest,
} from "./test_util.ts";
import { concat } from "../../../test_util/std/bytes/mod.ts"; import { concat } from "../../../test_util/std/bytes/mod.ts";
unitTest(function blobString() { Deno.test(function blobString() {
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
const str = "Test"; const str = "Test";
const b2 = new Blob([b1, str]); const b2 = new Blob([b1, str]);
assertEquals(b2.size, b1.size + str.length); assertEquals(b2.size, b1.size + str.length);
}); });
unitTest(function blobBuffer() { Deno.test(function blobBuffer() {
const buffer = new ArrayBuffer(12); const buffer = new ArrayBuffer(12);
const u8 = new Uint8Array(buffer); const u8 = new Uint8Array(buffer);
const f1 = new Float32Array(buffer); const f1 = new Float32Array(buffer);
@ -24,7 +19,7 @@ unitTest(function blobBuffer() {
assertEquals(b2.size, 3 * u8.length); assertEquals(b2.size, 3 * u8.length);
}); });
unitTest(function blobSlice() { Deno.test(function blobSlice() {
const blob = new Blob(["Deno", "Foo"]); const blob = new Blob(["Deno", "Foo"]);
const b1 = blob.slice(0, 3, "Text/HTML"); const b1 = blob.slice(0, 3, "Text/HTML");
assert(b1 instanceof Blob); assert(b1 instanceof Blob);
@ -38,7 +33,7 @@ unitTest(function blobSlice() {
assertEquals(b4.size, blob.size); assertEquals(b4.size, blob.size);
}); });
unitTest(function blobInvalidType() { Deno.test(function blobInvalidType() {
const blob = new Blob(["foo"], { const blob = new Blob(["foo"], {
type: "\u0521", type: "\u0521",
}); });
@ -46,7 +41,7 @@ unitTest(function blobInvalidType() {
assertEquals(blob.type, ""); assertEquals(blob.type, "");
}); });
unitTest(function blobShouldNotThrowError() { Deno.test(function blobShouldNotThrowError() {
let hasThrown = false; let hasThrown = false;
try { try {
@ -66,7 +61,7 @@ unitTest(function blobShouldNotThrowError() {
}); });
/* TODO https://github.com/denoland/deno/issues/7540 /* TODO https://github.com/denoland/deno/issues/7540
unitTest(function nativeEndLine() { Deno.test(function nativeEndLine() {
const options = { const options = {
ending: "native", ending: "native",
} as const; } as const;
@ -76,12 +71,12 @@ unitTest(function nativeEndLine() {
}); });
*/ */
unitTest(async function blobText() { Deno.test(async function blobText() {
const blob = new Blob(["Hello World"]); const blob = new Blob(["Hello World"]);
assertEquals(await blob.text(), "Hello World"); assertEquals(await blob.text(), "Hello World");
}); });
unitTest(async function blobStream() { Deno.test(async function blobStream() {
const blob = new Blob(["Hello World"]); const blob = new Blob(["Hello World"]);
const stream = blob.stream(); const stream = blob.stream();
assert(stream instanceof ReadableStream); assert(stream instanceof ReadableStream);
@ -99,18 +94,18 @@ unitTest(async function blobStream() {
assertEquals(decoder.decode(bytes), "Hello World"); assertEquals(decoder.decode(bytes), "Hello World");
}); });
unitTest(async function blobArrayBuffer() { Deno.test(async function blobArrayBuffer() {
const uint = new Uint8Array([102, 111, 111]); const uint = new Uint8Array([102, 111, 111]);
const blob = new Blob([uint]); const blob = new Blob([uint]);
assertEquals(await blob.arrayBuffer(), uint.buffer); assertEquals(await blob.arrayBuffer(), uint.buffer);
}); });
unitTest(function blobConstructorNameIsBlob() { Deno.test(function blobConstructorNameIsBlob() {
const blob = new Blob(); const blob = new Blob();
assertEquals(blob.constructor.name, "Blob"); assertEquals(blob.constructor.name, "Blob");
}); });
unitTest(function blobCustomInspectFunction() { Deno.test(function blobCustomInspectFunction() {
const blob = new Blob(); const blob = new Blob();
assertEquals( assertEquals(
Deno.inspect(blob), Deno.inspect(blob),

View file

@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
// just a hack to get a body object // just a hack to get a body object
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
@ -23,7 +23,7 @@ const intArrays = [
Float32Array, Float32Array,
Float64Array, Float64Array,
]; ];
unitTest(async function arrayBufferFromByteArrays() { Deno.test(async function arrayBufferFromByteArrays() {
const buffer = new TextEncoder().encode("ahoyhoy8").buffer; const buffer = new TextEncoder().encode("ahoyhoy8").buffer;
for (const type of intArrays) { for (const type of intArrays) {
@ -34,7 +34,7 @@ unitTest(async function arrayBufferFromByteArrays() {
}); });
//FormData //FormData
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function bodyMultipartFormData() { async function bodyMultipartFormData() {
const response = await fetch( const response = await fetch(
@ -53,7 +53,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function bodyURLEncodedFormData() { async function bodyURLEncodedFormData() {
const response = await fetch( const response = await fetch(
@ -73,14 +73,14 @@ unitTest(
}, },
); );
unitTest({ permissions: {} }, async function bodyURLSearchParams() { Deno.test({ permissions: {} }, async function bodyURLSearchParams() {
const body = buildBody(new URLSearchParams({ hello: "world" })); const body = buildBody(new URLSearchParams({ hello: "world" }));
const text = await body.text(); const text = await body.text();
assertEquals(text, "hello=world"); assertEquals(text, "hello=world");
}); });
unitTest(async function bodyArrayBufferMultipleParts() { Deno.test(async function bodyArrayBufferMultipleParts() {
const parts: Uint8Array[] = []; const parts: Uint8Array[] = [];
let size = 0; let size = 0;
for (let i = 0; i <= 150000; i++) { for (let i = 0; i <= 150000; i++) {

View file

@ -10,7 +10,6 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
const MAX_SIZE = 2 ** 32 - 2; const MAX_SIZE = 2 ** 32 - 2;
@ -87,7 +86,7 @@ function repeat(c: string, bytes: number): Uint8Array {
return ui8; return ui8;
} }
unitTest(function bufferNewBuffer() { Deno.test(function bufferNewBuffer() {
init(); init();
assert(testBytes); assert(testBytes);
assert(testString); assert(testString);
@ -95,7 +94,7 @@ unitTest(function bufferNewBuffer() {
check(buf, testString); check(buf, testString);
}); });
unitTest(async function bufferBasicOperations() { Deno.test(async function bufferBasicOperations() {
init(); init();
assert(testBytes); assert(testBytes);
assert(testString); assert(testString);
@ -135,7 +134,7 @@ unitTest(async function bufferBasicOperations() {
} }
}); });
unitTest(async function bufferReadEmptyAtEOF() { Deno.test(async function bufferReadEmptyAtEOF() {
// check that EOF of 'buf' is not reached (even though it's empty) if // check that EOF of 'buf' is not reached (even though it's empty) if
// results are written to buffer that has 0 length (ie. it can't store any data) // results are written to buffer that has 0 length (ie. it can't store any data)
const buf = new Deno.Buffer(); const buf = new Deno.Buffer();
@ -144,7 +143,7 @@ unitTest(async function bufferReadEmptyAtEOF() {
assertEquals(result, 0); assertEquals(result, 0);
}); });
unitTest(async function bufferLargeByteWrites() { Deno.test(async function bufferLargeByteWrites() {
init(); init();
const buf = new Deno.Buffer(); const buf = new Deno.Buffer();
const limit = 9; const limit = 9;
@ -155,7 +154,7 @@ unitTest(async function bufferLargeByteWrites() {
check(buf, ""); check(buf, "");
}); });
unitTest(async function bufferTooLargeByteWrites() { Deno.test(async function bufferTooLargeByteWrites() {
init(); init();
const tmp = new Uint8Array(72); const tmp = new Uint8Array(72);
const growLen = Number.MAX_VALUE; const growLen = Number.MAX_VALUE;
@ -172,7 +171,7 @@ unitTest(async function bufferTooLargeByteWrites() {
); );
}); });
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
function bufferGrowWriteMaxBuffer() { function bufferGrowWriteMaxBuffer() {
const bufSize = 16 * 1024; const bufSize = 16 * 1024;
@ -194,7 +193,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
async function bufferGrowReadCloseMaxBufferPlus1() { async function bufferGrowReadCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
@ -210,7 +209,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
function bufferGrowReadSyncCloseMaxBufferPlus1() { function bufferGrowReadSyncCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
@ -226,7 +225,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
function bufferGrowReadSyncCloseToMaxBuffer() { function bufferGrowReadSyncCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1]; const capacities = [MAX_SIZE, MAX_SIZE - 1];
@ -240,7 +239,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
async function bufferGrowReadCloseToMaxBuffer() { async function bufferGrowReadCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1]; const capacities = [MAX_SIZE, MAX_SIZE - 1];
@ -253,7 +252,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: ignoreMaxSizeTests }, { ignore: ignoreMaxSizeTests },
async function bufferReadCloseToMaxBufferWithInitialGrow() { async function bufferReadCloseToMaxBufferWithInitialGrow() {
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512]; const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
@ -267,7 +266,7 @@ unitTest(
}, },
); );
unitTest(async function bufferLargeByteReads() { Deno.test(async function bufferLargeByteReads() {
init(); init();
assert(testBytes); assert(testBytes);
assert(testString); assert(testString);
@ -280,12 +279,12 @@ unitTest(async function bufferLargeByteReads() {
check(buf, ""); check(buf, "");
}); });
unitTest(function bufferCapWithPreallocatedSlice() { Deno.test(function bufferCapWithPreallocatedSlice() {
const buf = new Deno.Buffer(new ArrayBuffer(10)); const buf = new Deno.Buffer(new ArrayBuffer(10));
assertEquals(buf.capacity, 10); assertEquals(buf.capacity, 10);
}); });
unitTest(async function bufferReadFrom() { Deno.test(async function bufferReadFrom() {
init(); init();
assert(testBytes); assert(testBytes);
assert(testString); assert(testString);
@ -307,7 +306,7 @@ unitTest(async function bufferReadFrom() {
}); });
}); });
unitTest(async function bufferReadFromSync() { Deno.test(async function bufferReadFromSync() {
init(); init();
assert(testBytes); assert(testBytes);
assert(testString); assert(testString);
@ -329,7 +328,7 @@ unitTest(async function bufferReadFromSync() {
}); });
}); });
unitTest(async function bufferTestGrow() { Deno.test(async function bufferTestGrow() {
const tmp = new Uint8Array(72); const tmp = new Uint8Array(72);
for (const startLen of [0, 100, 1000, 10000]) { for (const startLen of [0, 100, 1000, 10000]) {
const xBytes = repeat("x", startLen); const xBytes = repeat("x", startLen);
@ -353,7 +352,7 @@ unitTest(async function bufferTestGrow() {
} }
}); });
unitTest(async function testReadAll() { Deno.test(async function testReadAll() {
init(); init();
assert(testBytes); assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -364,7 +363,7 @@ unitTest(async function testReadAll() {
} }
}); });
unitTest(function testReadAllSync() { Deno.test(function testReadAllSync() {
init(); init();
assert(testBytes); assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -375,7 +374,7 @@ unitTest(function testReadAllSync() {
} }
}); });
unitTest(async function testWriteAll() { Deno.test(async function testWriteAll() {
init(); init();
assert(testBytes); assert(testBytes);
const writer = new Deno.Buffer(); const writer = new Deno.Buffer();
@ -387,7 +386,7 @@ unitTest(async function testWriteAll() {
} }
}); });
unitTest(function testWriteAllSync() { Deno.test(function testWriteAllSync() {
init(); init();
assert(testBytes); assert(testBytes);
const writer = new Deno.Buffer(); const writer = new Deno.Buffer();
@ -399,7 +398,7 @@ unitTest(function testWriteAllSync() {
} }
}); });
unitTest(function testBufferBytesArrayBufferLength() { Deno.test(function testBufferBytesArrayBufferLength() {
// defaults to copy // defaults to copy
const args = [{}, { copy: undefined }, undefined, { copy: true }]; const args = [{}, { copy: undefined }, undefined, { copy: true }];
for (const arg of args) { for (const arg of args) {
@ -418,7 +417,7 @@ unitTest(function testBufferBytesArrayBufferLength() {
} }
}); });
unitTest(function testBufferBytesCopyFalse() { Deno.test(function testBufferBytesCopyFalse() {
const bufSize = 64 * 1024; const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize)); const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer(); const reader = new Deno.Buffer();
@ -433,7 +432,7 @@ unitTest(function testBufferBytesCopyFalse() {
assert(actualBytes.buffer.byteLength > actualBytes.byteLength); assert(actualBytes.buffer.byteLength > actualBytes.byteLength);
}); });
unitTest(function testBufferBytesCopyFalseGrowExactBytes() { Deno.test(function testBufferBytesCopyFalseGrowExactBytes() {
const bufSize = 64 * 1024; const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize)); const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer(); const reader = new Deno.Buffer();

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function buildInfo() { Deno.test(function buildInfo() {
// Deno.build is injected by rollup at compile time. Here // Deno.build is injected by rollup at compile time. Here
// we check it has been properly transformed. // we check it has been properly transformed.
const { arch, os } = Deno.build; const { arch, os } = Deno.build;

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -27,7 +26,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -50,7 +49,7 @@ unitTest(
); );
// Check symlink when not on windows // Check symlink when not on windows
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -81,7 +80,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, function chmodSyncFailure() { Deno.test({ permissions: { write: true } }, function chmodSyncFailure() {
const filename = "/badfile.txt"; const filename = "/badfile.txt";
assertThrows( assertThrows(
() => { () => {
@ -92,13 +91,13 @@ unitTest({ permissions: { write: true } }, function chmodSyncFailure() {
); );
}); });
unitTest({ permissions: { write: false } }, function chmodSyncPerm() { Deno.test({ permissions: { write: false } }, function chmodSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.chmodSync("/somefile.txt", 0o777); Deno.chmodSync("/somefile.txt", 0o777);
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -118,7 +117,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -142,7 +141,7 @@ unitTest(
// Check symlink when not on windows // Check symlink when not on windows
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -173,7 +172,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, async function chmodFailure() { Deno.test({ permissions: { write: true } }, async function chmodFailure() {
const filename = "/badfile.txt"; const filename = "/badfile.txt";
await assertRejects( await assertRejects(
async () => { async () => {
@ -184,7 +183,7 @@ unitTest({ permissions: { write: true } }, async function chmodFailure() {
); );
}); });
unitTest({ permissions: { write: false } }, async function chmodPerm() { Deno.test({ permissions: { write: false } }, async function chmodPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.chmod("/somefile.txt", 0o777); await Deno.chmod("/somefile.txt", 0o777);
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);

View file

@ -1,10 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
assertEquals,
assertRejects,
assertThrows,
unitTest,
} from "./test_util.ts";
// chown on Windows is noop for now, so ignore its testing on Windows // chown on Windows is noop for now, so ignore its testing on Windows
@ -29,8 +24,8 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> {
return { uid, gid }; return { uid, gid };
} }
unitTest( Deno.test(
{ ignore: Deno.build.os == "windows" }, { ignore: Deno.build.os == "windows", permissions: { write: false } },
async function chownNoWritePermission() { async function chownNoWritePermission() {
const filePath = "chown_test_file.txt"; const filePath = "chown_test_file.txt";
await assertRejects(async () => { await assertRejects(async () => {
@ -39,7 +34,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -58,7 +53,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -77,7 +72,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true }, ignore: Deno.build.os == "windows" }, { permissions: { write: true }, ignore: Deno.build.os == "windows" },
function chownSyncPermissionDenied() { function chownSyncPermissionDenied() {
const dirPath = Deno.makeTempDirSync(); const dirPath = Deno.makeTempDirSync();
@ -92,7 +87,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true }, ignore: Deno.build.os == "windows" }, { permissions: { write: true }, ignore: Deno.build.os == "windows" },
async function chownPermissionDenied() { async function chownPermissionDenied() {
const dirPath = await Deno.makeTempDir(); const dirPath = await Deno.makeTempDir();
@ -107,7 +102,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -130,7 +125,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -145,7 +140,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -160,7 +155,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",
@ -175,7 +170,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, write: true }, permissions: { run: true, write: true },
ignore: Deno.build.os == "windows", ignore: Deno.build.os == "windows",

View file

@ -13,7 +13,6 @@ import {
assertEquals, assertEquals,
assertStringIncludes, assertStringIncludes,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
import { stripColor } from "../../../test_util/std/fmt/colors.ts"; import { stripColor } from "../../../test_util/std/fmt/colors.ts";
@ -64,7 +63,7 @@ function cssToAnsiEsc(css: Css, prevCss: Css | null = null): string {
// test cases from web-platform-tests // test cases from web-platform-tests
// via https://github.com/web-platform-tests/wpt/blob/master/console/console-is-a-namespace.any.js // via https://github.com/web-platform-tests/wpt/blob/master/console/console-is-a-namespace.any.js
unitTest(function consoleShouldBeANamespace() { Deno.test(function consoleShouldBeANamespace() {
const prototype1 = Object.getPrototypeOf(console); const prototype1 = Object.getPrototypeOf(console);
const prototype2 = Object.getPrototypeOf(prototype1); const prototype2 = Object.getPrototypeOf(prototype1);
@ -72,12 +71,12 @@ unitTest(function consoleShouldBeANamespace() {
assertEquals(prototype2, Object.prototype); assertEquals(prototype2, Object.prototype);
}); });
unitTest(function consoleHasRightInstance() { Deno.test(function consoleHasRightInstance() {
assert(console instanceof Console); assert(console instanceof Console);
assertEquals({} instanceof Console, false); assertEquals({} instanceof Console, false);
}); });
unitTest(function consoleTestAssertShouldNotThrowError() { Deno.test(function consoleTestAssertShouldNotThrowError() {
mockConsole((console) => { mockConsole((console) => {
console.assert(true); console.assert(true);
let hasThrown = undefined; let hasThrown = undefined;
@ -91,13 +90,13 @@ unitTest(function consoleTestAssertShouldNotThrowError() {
}); });
}); });
unitTest(function consoleTestStringifyComplexObjects() { Deno.test(function consoleTestStringifyComplexObjects() {
assertEquals(stringify("foo"), "foo"); assertEquals(stringify("foo"), "foo");
assertEquals(stringify(["foo", "bar"]), `[ "foo", "bar" ]`); assertEquals(stringify(["foo", "bar"]), `[ "foo", "bar" ]`);
assertEquals(stringify({ foo: "bar" }), `{ foo: "bar" }`); assertEquals(stringify({ foo: "bar" }), `{ foo: "bar" }`);
}); });
unitTest( Deno.test(
function consoleTestStringifyComplexObjectsWithEscapedSequences() { function consoleTestStringifyComplexObjectsWithEscapedSequences() {
assertEquals( assertEquals(
stringify( stringify(
@ -167,14 +166,14 @@ unitTest(
}, },
); );
unitTest(function consoleTestStringifyQuotes() { Deno.test(function consoleTestStringifyQuotes() {
assertEquals(stringify(["\\"]), `[ "\\\\" ]`); assertEquals(stringify(["\\"]), `[ "\\\\" ]`);
assertEquals(stringify(['\\,"']), `[ '\\\\,"' ]`); assertEquals(stringify(['\\,"']), `[ '\\\\,"' ]`);
assertEquals(stringify([`\\,",'`]), `[ \`\\\\,",'\` ]`); assertEquals(stringify([`\\,",'`]), `[ \`\\\\,",'\` ]`);
assertEquals(stringify(["\\,\",',`"]), `[ "\\\\,\\",',\`" ]`); assertEquals(stringify(["\\,\",',`"]), `[ "\\\\,\\",',\`" ]`);
}); });
unitTest(function consoleTestStringifyLongStrings() { Deno.test(function consoleTestStringifyLongStrings() {
const veryLongString = "a".repeat(200); const veryLongString = "a".repeat(200);
// If we stringify an object containing the long string, it gets abbreviated. // If we stringify an object containing the long string, it gets abbreviated.
let actual = stringify({ veryLongString }); let actual = stringify({ veryLongString });
@ -185,7 +184,7 @@ unitTest(function consoleTestStringifyLongStrings() {
assertEquals(actual, veryLongString); assertEquals(actual, veryLongString);
}); });
unitTest(function consoleTestStringifyCircular() { Deno.test(function consoleTestStringifyCircular() {
class Base { class Base {
a = 1; a = 1;
m1() {} m1() {}
@ -357,7 +356,7 @@ unitTest(function consoleTestStringifyCircular() {
assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected); assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected);
}); });
unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() { Deno.test(function consoleTestStringifyFunctionWithPrototypeRemoved() {
const f = function f() {}; const f = function f() {};
Reflect.setPrototypeOf(f, null); Reflect.setPrototypeOf(f, null);
assertEquals(stringify(f), "[Function: f]"); assertEquals(stringify(f), "[Function: f]");
@ -372,7 +371,7 @@ unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() {
assertEquals(stringify(agf), "[Function: agf]"); assertEquals(stringify(agf), "[Function: agf]");
}); });
unitTest(function consoleTestStringifyFunctionWithProperties() { Deno.test(function consoleTestStringifyFunctionWithProperties() {
const f = () => "test"; const f = () => "test";
f.x = () => "foo"; f.x = () => "foo";
f.y = 3; f.y = 3;
@ -416,7 +415,7 @@ unitTest(function consoleTestStringifyFunctionWithProperties() {
); );
}); });
unitTest(function consoleTestStringifyWithDepth() { Deno.test(function consoleTestStringifyWithDepth() {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } }; const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } };
assertEquals( assertEquals(
@ -439,7 +438,7 @@ unitTest(function consoleTestStringifyWithDepth() {
); );
}); });
unitTest(function consoleTestStringifyLargeObject() { Deno.test(function consoleTestStringifyLargeObject() {
const obj = { const obj = {
a: 2, a: 2,
o: { o: {
@ -475,7 +474,7 @@ unitTest(function consoleTestStringifyLargeObject() {
); );
}); });
unitTest(function consoleTestStringifyIterable() { Deno.test(function consoleTestStringifyIterable() {
const shortArray = [1, 2, 3, 4, 5]; const shortArray = [1, 2, 3, 4, 5];
assertEquals(stringify(shortArray), "[ 1, 2, 3, 4, 5 ]"); assertEquals(stringify(shortArray), "[ 1, 2, 3, 4, 5 ]");
@ -771,7 +770,7 @@ unitTest(function consoleTestStringifyIterable() {
*/ */
}); });
unitTest(function consoleTestStringifyIterableWhenGrouped() { Deno.test(function consoleTestStringifyIterableWhenGrouped() {
const withOddNumberOfEls = new Float64Array( const withOddNumberOfEls = new Float64Array(
[ [
2.1, 2.1,
@ -849,7 +848,7 @@ unitTest(function consoleTestStringifyIterableWhenGrouped() {
); );
}); });
unitTest(async function consoleTestStringifyPromises() { Deno.test(async function consoleTestStringifyPromises() {
const pendingPromise = new Promise((_res, _rej) => {}); const pendingPromise = new Promise((_res, _rej) => {});
assertEquals(stringify(pendingPromise), "Promise { <pending> }"); assertEquals(stringify(pendingPromise), "Promise { <pending> }");
@ -872,7 +871,7 @@ unitTest(async function consoleTestStringifyPromises() {
assertEquals(strLines[1], " <rejected> Error: Whoops"); assertEquals(strLines[1], " <rejected> Error: Whoops");
}); });
unitTest(function consoleTestWithCustomInspector() { Deno.test(function consoleTestWithCustomInspector() {
class A { class A {
[customInspect](): string { [customInspect](): string {
return "b"; return "b";
@ -882,7 +881,7 @@ unitTest(function consoleTestWithCustomInspector() {
assertEquals(stringify(new A()), "b"); assertEquals(stringify(new A()), "b");
}); });
unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() { Deno.test(function consoleTestWithCustomInspectorUsingInspectFunc() {
class A { class A {
[customInspect]( [customInspect](
inspect: (v: unknown, opts?: Deno.InspectOptions) => string, inspect: (v: unknown, opts?: Deno.InspectOptions) => string,
@ -894,7 +893,7 @@ unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() {
assertEquals(stringify(new A()), "b { c: 1 }"); assertEquals(stringify(new A()), "b { c: 1 }");
}); });
unitTest(function consoleTestWithCustomInspectorError() { Deno.test(function consoleTestWithCustomInspectorError() {
class A { class A {
[customInspect](): never { [customInspect](): never {
throw new Error("BOOM"); throw new Error("BOOM");
@ -916,7 +915,7 @@ unitTest(function consoleTestWithCustomInspectorError() {
); );
}); });
unitTest(function consoleTestWithCustomInspectFunction() { Deno.test(function consoleTestWithCustomInspectFunction() {
function a() {} function a() {}
Object.assign(a, { Object.assign(a, {
[customInspect]() { [customInspect]() {
@ -927,7 +926,7 @@ unitTest(function consoleTestWithCustomInspectFunction() {
assertEquals(stringify(a), "b"); assertEquals(stringify(a), "b");
}); });
unitTest(function consoleTestWithIntegerFormatSpecifier() { Deno.test(function consoleTestWithIntegerFormatSpecifier() {
assertEquals(stringify("%i"), "%i"); assertEquals(stringify("%i"), "%i");
assertEquals(stringify("%i", 42.0), "42"); assertEquals(stringify("%i", 42.0), "42");
assertEquals(stringify("%i", 42), "42"); assertEquals(stringify("%i", 42), "42");
@ -945,7 +944,7 @@ unitTest(function consoleTestWithIntegerFormatSpecifier() {
); );
}); });
unitTest(function consoleTestWithFloatFormatSpecifier() { Deno.test(function consoleTestWithFloatFormatSpecifier() {
assertEquals(stringify("%f"), "%f"); assertEquals(stringify("%f"), "%f");
assertEquals(stringify("%f", 42.0), "42"); assertEquals(stringify("%f", 42.0), "42");
assertEquals(stringify("%f", 42), "42"); assertEquals(stringify("%f", 42), "42");
@ -960,7 +959,7 @@ unitTest(function consoleTestWithFloatFormatSpecifier() {
assertEquals(stringify("%f %f", 42), "42 %f"); assertEquals(stringify("%f %f", 42), "42 %f");
}); });
unitTest(function consoleTestWithStringFormatSpecifier() { Deno.test(function consoleTestWithStringFormatSpecifier() {
assertEquals(stringify("%s"), "%s"); assertEquals(stringify("%s"), "%s");
assertEquals(stringify("%s", undefined), "undefined"); assertEquals(stringify("%s", undefined), "undefined");
assertEquals(stringify("%s", "foo"), "foo"); assertEquals(stringify("%s", "foo"), "foo");
@ -971,7 +970,7 @@ unitTest(function consoleTestWithStringFormatSpecifier() {
assertEquals(stringify("%s", Symbol("foo")), "Symbol(foo)"); assertEquals(stringify("%s", Symbol("foo")), "Symbol(foo)");
}); });
unitTest(function consoleTestWithObjectFormatSpecifier() { Deno.test(function consoleTestWithObjectFormatSpecifier() {
assertEquals(stringify("%o"), "%o"); assertEquals(stringify("%o"), "%o");
assertEquals(stringify("%o", 42), "42"); assertEquals(stringify("%o", 42), "42");
assertEquals(stringify("%o", "foo"), `"foo"`); assertEquals(stringify("%o", "foo"), `"foo"`);
@ -983,13 +982,13 @@ unitTest(function consoleTestWithObjectFormatSpecifier() {
); );
}); });
unitTest(function consoleTestWithStyleSpecifier() { Deno.test(function consoleTestWithStyleSpecifier() {
assertEquals(stringify("%cfoo%cbar"), "%cfoo%cbar"); assertEquals(stringify("%cfoo%cbar"), "%cfoo%cbar");
assertEquals(stringify("%cfoo%cbar", ""), "foo%cbar"); assertEquals(stringify("%cfoo%cbar", ""), "foo%cbar");
assertEquals(stripColor(stringify("%cfoo%cbar", "", "color: red")), "foobar"); assertEquals(stripColor(stringify("%cfoo%cbar", "", "color: red")), "foobar");
}); });
unitTest(function consoleParseCssColor() { Deno.test(function consoleParseCssColor() {
assertEquals(parseCssColor("black"), [0, 0, 0]); assertEquals(parseCssColor("black"), [0, 0, 0]);
assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]); assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]);
assertEquals(parseCssColor("slateblue"), [106, 90, 205]); assertEquals(parseCssColor("slateblue"), [106, 90, 205]);
@ -1008,7 +1007,7 @@ unitTest(function consoleParseCssColor() {
); );
}); });
unitTest(function consoleParseCss() { Deno.test(function consoleParseCss() {
assertEquals( assertEquals(
parseCss("background-color: red"), parseCss("background-color: red"),
{ ...DEFAULT_CSS, backgroundColor: [255, 0, 0] }, { ...DEFAULT_CSS, backgroundColor: [255, 0, 0] },
@ -1062,7 +1061,7 @@ unitTest(function consoleParseCss() {
); );
}); });
unitTest(function consoleCssToAnsi() { Deno.test(function consoleCssToAnsi() {
assertEquals( assertEquals(
cssToAnsiEsc({ ...DEFAULT_CSS, backgroundColor: [200, 201, 202] }), cssToAnsiEsc({ ...DEFAULT_CSS, backgroundColor: [200, 201, 202] }),
"_[48;2;200;201;202m", "_[48;2;200;201;202m",
@ -1102,7 +1101,7 @@ unitTest(function consoleCssToAnsi() {
); );
}); });
unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() { Deno.test(function consoleTestWithVariousOrInvalidFormatSpecifier() {
assertEquals(stringify("%s:%s"), "%s:%s"); assertEquals(stringify("%s:%s"), "%s:%s");
assertEquals(stringify("%i:%i"), "%i:%i"); assertEquals(stringify("%i:%i"), "%i:%i");
assertEquals(stringify("%d:%d"), "%d:%d"); assertEquals(stringify("%d:%d"), "%d:%d");
@ -1118,7 +1117,7 @@ unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() {
assertEquals(stringify("abc%", 1), "abc% 1"); assertEquals(stringify("abc%", 1), "abc% 1");
}); });
unitTest(function consoleTestCallToStringOnLabel() { Deno.test(function consoleTestCallToStringOnLabel() {
const methods = ["count", "countReset", "time", "timeLog", "timeEnd"]; const methods = ["count", "countReset", "time", "timeLog", "timeEnd"];
mockConsole((console) => { mockConsole((console) => {
for (const method of methods) { for (const method of methods) {
@ -1133,7 +1132,7 @@ unitTest(function consoleTestCallToStringOnLabel() {
}); });
}); });
unitTest(function consoleTestError() { Deno.test(function consoleTestError() {
class MyError extends Error { class MyError extends Error {
constructor(errStr: string) { constructor(errStr: string) {
super(errStr); super(errStr);
@ -1151,7 +1150,7 @@ unitTest(function consoleTestError() {
} }
}); });
unitTest(function consoleTestClear() { Deno.test(function consoleTestClear() {
mockConsole((console, out) => { mockConsole((console, out) => {
console.clear(); console.clear();
assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J"); assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J");
@ -1159,7 +1158,7 @@ unitTest(function consoleTestClear() {
}); });
// Test bound this issue // Test bound this issue
unitTest(function consoleDetachedLog() { Deno.test(function consoleDetachedLog() {
mockConsole((console) => { mockConsole((console) => {
const log = console.log; const log = console.log;
const dir = console.dir; const dir = console.dir;
@ -1232,7 +1231,7 @@ function mockConsole(f: ConsoleExamineFunc) {
} }
// console.group test // console.group test
unitTest(function consoleGroup() { Deno.test(function consoleGroup() {
mockConsole((console, out) => { mockConsole((console, out) => {
console.group("1"); console.group("1");
console.log("2"); console.log("2");
@ -1257,7 +1256,7 @@ unitTest(function consoleGroup() {
}); });
// console.group with console.warn test // console.group with console.warn test
unitTest(function consoleGroupWarn() { Deno.test(function consoleGroupWarn() {
mockConsole((console, _out, _err, both) => { mockConsole((console, _out, _err, both) => {
assert(both); assert(both);
console.warn("1"); console.warn("1");
@ -1287,7 +1286,7 @@ unitTest(function consoleGroupWarn() {
}); });
// console.table test // console.table test
unitTest(function consoleTable() { Deno.test(function consoleTable() {
mockConsole((console, out) => { mockConsole((console, out) => {
console.table({ a: "test", b: 1 }); console.table({ a: "test", b: 1 });
assertEquals( assertEquals(
@ -1535,7 +1534,7 @@ unitTest(function consoleTable() {
}); });
// console.log(Error) test // console.log(Error) test
unitTest(function consoleLogShouldNotThrowError() { Deno.test(function consoleLogShouldNotThrowError() {
mockConsole((console) => { mockConsole((console) => {
let result = 0; let result = 0;
try { try {
@ -1555,7 +1554,7 @@ unitTest(function consoleLogShouldNotThrowError() {
}); });
// console.log(Invalid Date) test // console.log(Invalid Date) test
unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { Deno.test(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() {
mockConsole((console, out) => { mockConsole((console, out) => {
const invalidDate = new Date("test"); const invalidDate = new Date("test");
console.log(invalidDate); console.log(invalidDate);
@ -1564,7 +1563,7 @@ unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() {
}); });
// console.dir test // console.dir test
unitTest(function consoleDir() { Deno.test(function consoleDir() {
mockConsole((console, out) => { mockConsole((console, out) => {
console.dir("DIR"); console.dir("DIR");
assertEquals(out.toString(), "DIR\n"); assertEquals(out.toString(), "DIR\n");
@ -1576,7 +1575,7 @@ unitTest(function consoleDir() {
}); });
// console.dir test // console.dir test
unitTest(function consoleDirXml() { Deno.test(function consoleDirXml() {
mockConsole((console, out) => { mockConsole((console, out) => {
console.dirxml("DIRXML"); console.dirxml("DIRXML");
assertEquals(out.toString(), "DIRXML\n"); assertEquals(out.toString(), "DIRXML\n");
@ -1588,7 +1587,7 @@ unitTest(function consoleDirXml() {
}); });
// console.trace test // console.trace test
unitTest(function consoleTrace() { Deno.test(function consoleTrace() {
mockConsole((console, _out, err) => { mockConsole((console, _out, err) => {
console.trace("%s", "custom message"); console.trace("%s", "custom message");
assert(err); assert(err);
@ -1596,7 +1595,7 @@ unitTest(function consoleTrace() {
}); });
}); });
unitTest(function inspectString() { Deno.test(function inspectString() {
assertEquals( assertEquals(
stripColor(Deno.inspect("\0")), stripColor(Deno.inspect("\0")),
`"\\x00"`, `"\\x00"`,
@ -1607,7 +1606,7 @@ unitTest(function inspectString() {
); );
}); });
unitTest(function inspectGetters() { Deno.test(function inspectGetters() {
assertEquals( assertEquals(
stripColor(Deno.inspect({ stripColor(Deno.inspect({
get foo() { get foo() {
@ -1636,12 +1635,12 @@ unitTest(function inspectGetters() {
); );
}); });
unitTest(function inspectPrototype() { Deno.test(function inspectPrototype() {
class A {} class A {}
assertEquals(Deno.inspect(A.prototype), "A {}"); assertEquals(Deno.inspect(A.prototype), "A {}");
}); });
unitTest(function inspectSorted() { Deno.test(function inspectSorted() {
assertEquals( assertEquals(
stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })), stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })),
"{ a: 1, b: 2 }", "{ a: 1, b: 2 }",
@ -1662,7 +1661,7 @@ unitTest(function inspectSorted() {
); );
}); });
unitTest(function inspectTrailingComma() { Deno.test(function inspectTrailingComma() {
assertEquals( assertEquals(
stripColor(Deno.inspect( stripColor(Deno.inspect(
[ [
@ -1717,7 +1716,7 @@ unitTest(function inspectTrailingComma() {
); );
}); });
unitTest(function inspectCompact() { Deno.test(function inspectCompact() {
assertEquals( assertEquals(
stripColor(Deno.inspect({ a: 1, b: 2 }, { compact: false })), stripColor(Deno.inspect({ a: 1, b: 2 }, { compact: false })),
`{ `{
@ -1727,7 +1726,7 @@ unitTest(function inspectCompact() {
); );
}); });
unitTest(function inspectIterableLimit() { Deno.test(function inspectIterableLimit() {
assertEquals( assertEquals(
stripColor(Deno.inspect(["a", "b", "c"], { iterableLimit: 2 })), stripColor(Deno.inspect(["a", "b", "c"], { iterableLimit: 2 })),
`[ "a", "b", ... 1 more items ]`, `[ "a", "b", ... 1 more items ]`,
@ -1749,7 +1748,7 @@ unitTest(function inspectIterableLimit() {
); );
}); });
unitTest(function inspectProxy() { Deno.test(function inspectProxy() {
assertEquals( assertEquals(
stripColor(Deno.inspect( stripColor(Deno.inspect(
new Proxy([1, 2, 3], {}), new Proxy([1, 2, 3], {}),
@ -1823,7 +1822,7 @@ unitTest(function inspectProxy() {
); );
}); });
unitTest(function inspectError() { Deno.test(function inspectError() {
const error1 = new Error("This is an error"); const error1 = new Error("This is an error");
const error2 = new Error("This is an error", { const error2 = new Error("This is an error", {
cause: new Error("This is a cause error"), cause: new Error("This is a cause error"),
@ -1843,7 +1842,7 @@ unitTest(function inspectError() {
); );
}); });
unitTest(function inspectErrorCircular() { Deno.test(function inspectErrorCircular() {
const error1 = new Error("This is an error"); const error1 = new Error("This is an error");
const error2 = new Error("This is an error", { const error2 = new Error("This is an error", {
cause: new Error("This is a cause error"), cause: new Error("This is a cause error"),
@ -1865,7 +1864,7 @@ unitTest(function inspectErrorCircular() {
); );
}); });
unitTest(function inspectColors() { Deno.test(function inspectColors() {
assertEquals(Deno.inspect(1), "1"); assertEquals(Deno.inspect(1), "1");
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b["); assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");
}); });

View file

@ -1,10 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
assertEquals,
assertRejects,
assertThrows,
unitTest,
} from "./test_util.ts";
function readFileString(filename: string | URL): string { function readFileString(filename: string | URL): string {
const dataRead = Deno.readFileSync(filename); const dataRead = Deno.readFileSync(filename);
@ -27,7 +22,7 @@ function assertSameContent(
assertEquals(data1, data2); assertEquals(data1, data2);
} }
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function copyFileSyncSuccess() { function copyFileSyncSuccess() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -44,7 +39,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function copyFileSyncByUrl() { function copyFileSyncByUrl() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -65,7 +60,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
function copyFileSyncFailure() { function copyFileSyncFailure() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -84,7 +79,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: false } }, { permissions: { write: true, read: false } },
function copyFileSyncPerm1() { function copyFileSyncPerm1() {
assertThrows(() => { assertThrows(() => {
@ -93,7 +88,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: false, read: true } }, { permissions: { write: false, read: true } },
function copyFileSyncPerm2() { function copyFileSyncPerm2() {
assertThrows(() => { assertThrows(() => {
@ -102,7 +97,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function copyFileSyncOverwrite() { function copyFileSyncOverwrite() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -121,7 +116,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function copyFileSuccess() { async function copyFileSuccess() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -138,7 +133,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function copyFileByUrl() { async function copyFileByUrl() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -159,7 +154,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function copyFileFailure() { async function copyFileFailure() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -178,7 +173,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function copyFileOverwrite() { async function copyFileOverwrite() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -197,7 +192,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: false, write: true } }, { permissions: { read: false, write: true } },
async function copyFilePerm1() { async function copyFilePerm1() {
await assertRejects(async () => { await assertRejects(async () => {
@ -206,7 +201,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
async function copyFilePerm2() { async function copyFilePerm2() {
await assertRejects(async () => { await assertRejects(async () => {

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(function customEventInitializedWithDetail() { Deno.test(function customEventInitializedWithDetail() {
const type = "touchstart"; const type = "touchstart";
const detail = { message: "hello" }; const detail = { message: "hello" };
const customEventInit = { const customEventInit = {
@ -20,7 +20,7 @@ unitTest(function customEventInitializedWithDetail() {
assertEquals(event.type, type); assertEquals(event.type, type);
}); });
unitTest(function toStringShouldBeWebCompatibility() { Deno.test(function toStringShouldBeWebCompatibility() {
const type = "touchstart"; const type = "touchstart";
const event = new CustomEvent(type, {}); const event = new CustomEvent(type, {});
assertEquals(event.toString(), "[object CustomEvent]"); assertEquals(event.toString(), "[object CustomEvent]");

View file

@ -1,11 +1,11 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertThrows } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function dirCwdNotNull() { Deno.test({ permissions: { read: true } }, function dirCwdNotNull() {
assert(Deno.cwd() != null); assert(Deno.cwd() != null);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function dirCwdChdirSuccess() { function dirCwdChdirSuccess() {
const initialdir = Deno.cwd(); const initialdir = Deno.cwd();
@ -21,7 +21,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true, write: true } }, function dirCwdError() { Deno.test({ permissions: { read: true, write: true } }, function dirCwdError() {
// excluding windows since it throws resource busy, while removeSync // excluding windows since it throws resource busy, while removeSync
if (["linux", "darwin"].includes(Deno.build.os)) { if (["linux", "darwin"].includes(Deno.build.os)) {
const initialdir = Deno.cwd(); const initialdir = Deno.cwd();
@ -38,7 +38,7 @@ unitTest({ permissions: { read: true, write: true } }, function dirCwdError() {
} }
}); });
unitTest({ permissions: { read: false } }, function dirCwdPermError() { Deno.test({ permissions: { read: false } }, function dirCwdPermError() {
assertThrows( assertThrows(
() => { () => {
Deno.cwd(); Deno.cwd();
@ -48,7 +48,7 @@ unitTest({ permissions: { read: false } }, function dirCwdPermError() {
); );
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function dirChdirError() { function dirChdirError() {
const path = Deno.makeTempDirSync() + "test"; const path = Deno.makeTempDirSync() + "test";

View file

@ -1,6 +1,6 @@
import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts"; import { assertEquals, assertStringIncludes } from "./test_util.ts";
unitTest(function customInspectFunction() { Deno.test(function customInspectFunction() {
const blob = new DOMException("test"); const blob = new DOMException("test");
assertEquals( assertEquals(
Deno.inspect(blob), Deno.inspect(blob),

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertMatch, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertMatch } from "./test_util.ts";
unitTest(function errorStackMessageLine() { Deno.test(function errorStackMessageLine() {
const e1 = new Error(); const e1 = new Error();
e1.name = "Foo"; e1.name = "Foo";
e1.message = "bar"; e1.message = "bar";
@ -41,7 +41,7 @@ unitTest(function errorStackMessageLine() {
assertMatch(e6.stack!, /^null: null\n/); assertMatch(e6.stack!, /^null: null\n/);
}); });
unitTest(function captureStackTrace() { Deno.test(function captureStackTrace() {
function foo() { function foo() {
const error = new Error(); const error = new Error();
const stack1 = error.stack!; const stack1 = error.stack!;
@ -55,7 +55,7 @@ unitTest(function captureStackTrace() {
// FIXME(bartlomieju): no longer works after migrating // FIXME(bartlomieju): no longer works after migrating
// to JavaScript runtime code // to JavaScript runtime code
unitTest({ ignore: true }, function applySourceMap() { Deno.test({ ignore: true }, function applySourceMap() {
const result = Deno.applySourceMap({ const result = Deno.applySourceMap({
fileName: "CLI_SNAPSHOT.js", fileName: "CLI_SNAPSHOT.js",
lineNumber: 23, lineNumber: 23,

View file

@ -1,10 +1,10 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
// TODO(@kitsonk) remove when we are no longer patching TypeScript to have // TODO(@kitsonk) remove when we are no longer patching TypeScript to have
// these types available. // these types available.
unitTest(function typeCheckingEsNextArrayString() { Deno.test(function typeCheckingEsNextArrayString() {
const a = "abcdef"; const a = "abcdef";
assertEquals(a.at(-1), "f"); assertEquals(a.at(-1), "f");
const b = ["a", "b", "c", "d", "e", "f"]; const b = ["a", "b", "c", "d", "e", "f"];
@ -13,13 +13,13 @@ unitTest(function typeCheckingEsNextArrayString() {
assertEquals(b.findLastIndex((val) => typeof val === "string"), 5); assertEquals(b.findLastIndex((val) => typeof val === "string"), 5);
}); });
unitTest(function objectHasOwn() { Deno.test(function objectHasOwn() {
const a = { a: 1 }; const a = { a: 1 };
assert(Object.hasOwn(a, "a")); assert(Object.hasOwn(a, "a"));
assert(!Object.hasOwn(a, "b")); assert(!Object.hasOwn(a, "b"));
}); });
unitTest(function errorCause() { Deno.test(function errorCause() {
const e = new Error("test", { cause: "something" }); const e = new Error("test", { cause: "something" });
assertEquals(e.cause, "something"); assertEquals(e.cause, "something");
}); });

View file

@ -1,8 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-window-prefix // deno-lint-ignore-file no-window-prefix
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(function addEventListenerTest() { Deno.test(function addEventListenerTest() {
const document = new EventTarget(); const document = new EventTarget();
assertEquals(document.addEventListener("x", null, false), undefined); assertEquals(document.addEventListener("x", null, false), undefined);
@ -10,7 +10,7 @@ unitTest(function addEventListenerTest() {
assertEquals(document.addEventListener("x", null), undefined); assertEquals(document.addEventListener("x", null), undefined);
}); });
unitTest(function constructedEventTargetCanBeUsedAsExpected() { Deno.test(function constructedEventTargetCanBeUsedAsExpected() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false }); const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0; let callCount = 0;
@ -33,7 +33,7 @@ unitTest(function constructedEventTargetCanBeUsedAsExpected() {
assertEquals(callCount, 2); assertEquals(callCount, 2);
}); });
unitTest(function anEventTargetCanBeSubclassed() { Deno.test(function anEventTargetCanBeSubclassed() {
class NicerEventTarget extends EventTarget { class NicerEventTarget extends EventTarget {
on( on(
type: string, type: string,
@ -67,14 +67,14 @@ unitTest(function anEventTargetCanBeSubclassed() {
assertEquals(callCount, 0); assertEquals(callCount, 0);
}); });
unitTest(function removingNullEventListenerShouldSucceed() { Deno.test(function removingNullEventListenerShouldSucceed() {
const document = new EventTarget(); const document = new EventTarget();
assertEquals(document.removeEventListener("x", null, false), undefined); assertEquals(document.removeEventListener("x", null, false), undefined);
assertEquals(document.removeEventListener("x", null, true), undefined); assertEquals(document.removeEventListener("x", null, true), undefined);
assertEquals(document.removeEventListener("x", null), undefined); assertEquals(document.removeEventListener("x", null), undefined);
}); });
unitTest(function constructedEventTargetUseObjectPrototype() { Deno.test(function constructedEventTargetUseObjectPrototype() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("toString", { bubbles: true, cancelable: false }); const event = new Event("toString", { bubbles: true, cancelable: false });
let callCount = 0; let callCount = 0;
@ -97,12 +97,12 @@ unitTest(function constructedEventTargetUseObjectPrototype() {
assertEquals(callCount, 2); assertEquals(callCount, 2);
}); });
unitTest(function toStringShouldBeWebCompatible() { Deno.test(function toStringShouldBeWebCompatible() {
const target = new EventTarget(); const target = new EventTarget();
assertEquals(target.toString(), "[object EventTarget]"); assertEquals(target.toString(), "[object EventTarget]");
}); });
unitTest(function dispatchEventShouldNotThrowError() { Deno.test(function dispatchEventShouldNotThrowError() {
let hasThrown = false; let hasThrown = false;
try { try {
@ -121,7 +121,7 @@ unitTest(function dispatchEventShouldNotThrowError() {
assertEquals(hasThrown, false); assertEquals(hasThrown, false);
}); });
unitTest(function eventTargetThisShouldDefaultToWindow() { Deno.test(function eventTargetThisShouldDefaultToWindow() {
const { const {
addEventListener, addEventListener,
dispatchEvent, dispatchEvent,
@ -150,7 +150,7 @@ unitTest(function eventTargetThisShouldDefaultToWindow() {
assertEquals(n, 1); assertEquals(n, 1);
}); });
unitTest(function eventTargetShouldAcceptEventListenerObject() { Deno.test(function eventTargetShouldAcceptEventListenerObject() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false }); const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0; let callCount = 0;
@ -175,7 +175,7 @@ unitTest(function eventTargetShouldAcceptEventListenerObject() {
assertEquals(callCount, 2); assertEquals(callCount, 2);
}); });
unitTest(function eventTargetShouldAcceptAsyncFunction() { Deno.test(function eventTargetShouldAcceptAsyncFunction() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false }); const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0; let callCount = 0;
@ -198,7 +198,7 @@ unitTest(function eventTargetShouldAcceptAsyncFunction() {
assertEquals(callCount, 2); assertEquals(callCount, 2);
}); });
unitTest( Deno.test(
function eventTargetShouldAcceptAsyncFunctionForEventListenerObject() { function eventTargetShouldAcceptAsyncFunctionForEventListenerObject() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false }); const event = new Event("foo", { bubbles: true, cancelable: false });
@ -224,7 +224,7 @@ unitTest(
assertEquals(callCount, 2); assertEquals(callCount, 2);
}, },
); );
unitTest(function eventTargetDispatchShouldSetTargetNoListener() { Deno.test(function eventTargetDispatchShouldSetTargetNoListener() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo"); const event = new Event("foo");
assertEquals(event.target, null); assertEquals(event.target, null);
@ -232,7 +232,7 @@ unitTest(function eventTargetDispatchShouldSetTargetNoListener() {
assertEquals(event.target, target); assertEquals(event.target, target);
}); });
unitTest(function eventTargetDispatchShouldSetTargetInListener() { Deno.test(function eventTargetDispatchShouldSetTargetInListener() {
const target = new EventTarget(); const target = new EventTarget();
const event = new Event("foo"); const event = new Event("foo");
assertEquals(event.target, null); assertEquals(event.target, null);

View file

@ -1,12 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assert, assertEquals, assertStringIncludes } from "./test_util.ts";
assert,
assertEquals,
assertStringIncludes,
unitTest,
} from "./test_util.ts";
unitTest(function eventInitializedWithType() { Deno.test(function eventInitializedWithType() {
const type = "click"; const type = "click";
const event = new Event(type); const event = new Event(type);
@ -18,7 +13,7 @@ unitTest(function eventInitializedWithType() {
assertEquals(event.cancelable, false); assertEquals(event.cancelable, false);
}); });
unitTest(function eventInitializedWithTypeAndDict() { Deno.test(function eventInitializedWithTypeAndDict() {
const init = "submit"; const init = "submit";
const eventInit = { bubbles: true, cancelable: true } as EventInit; const eventInit = { bubbles: true, cancelable: true } as EventInit;
const event = new Event(init, eventInit); const event = new Event(init, eventInit);
@ -31,7 +26,7 @@ unitTest(function eventInitializedWithTypeAndDict() {
assertEquals(event.cancelable, true); assertEquals(event.cancelable, true);
}); });
unitTest(function eventComposedPathSuccess() { Deno.test(function eventComposedPathSuccess() {
const type = "click"; const type = "click";
const event = new Event(type); const event = new Event(type);
const composedPath = event.composedPath(); const composedPath = event.composedPath();
@ -39,7 +34,7 @@ unitTest(function eventComposedPathSuccess() {
assertEquals(composedPath, []); assertEquals(composedPath, []);
}); });
unitTest(function eventStopPropagationSuccess() { Deno.test(function eventStopPropagationSuccess() {
const type = "click"; const type = "click";
const event = new Event(type); const event = new Event(type);
@ -48,7 +43,7 @@ unitTest(function eventStopPropagationSuccess() {
assertEquals(event.cancelBubble, true); assertEquals(event.cancelBubble, true);
}); });
unitTest(function eventStopImmediatePropagationSuccess() { Deno.test(function eventStopImmediatePropagationSuccess() {
const type = "click"; const type = "click";
const event = new Event(type); const event = new Event(type);
@ -57,7 +52,7 @@ unitTest(function eventStopImmediatePropagationSuccess() {
assertEquals(event.cancelBubble, true); assertEquals(event.cancelBubble, true);
}); });
unitTest(function eventPreventDefaultSuccess() { Deno.test(function eventPreventDefaultSuccess() {
const type = "click"; const type = "click";
const event = new Event(type); const event = new Event(type);
@ -72,7 +67,7 @@ unitTest(function eventPreventDefaultSuccess() {
assertEquals(cancelableEvent.defaultPrevented, true); assertEquals(cancelableEvent.defaultPrevented, true);
}); });
unitTest(function eventInitializedWithNonStringType() { Deno.test(function eventInitializedWithNonStringType() {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
const type: any = undefined; const type: any = undefined;
const event = new Event(type); const event = new Event(type);
@ -86,7 +81,7 @@ unitTest(function eventInitializedWithNonStringType() {
}); });
// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js // ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
unitTest(function eventIsTrusted() { Deno.test(function eventIsTrusted() {
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted"); const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
assert(desc1); assert(desc1);
assertEquals(typeof desc1.get, "function"); assertEquals(typeof desc1.get, "function");
@ -98,7 +93,7 @@ unitTest(function eventIsTrusted() {
assertEquals(desc1!.get, desc2!.get); assertEquals(desc1!.get, desc2!.get);
}); });
unitTest(function eventInspectOutput() { Deno.test(function eventInspectOutput() {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
const cases: Array<[any, (event: any) => string]> = [ const cases: Array<[any, (event: any) => string]> = [
[ [
@ -133,7 +128,7 @@ unitTest(function eventInspectOutput() {
} }
}); });
unitTest(function inspectEvent() { Deno.test(function inspectEvent() {
// has a customInspect implementation that previously would throw on a getter // has a customInspect implementation that previously would throw on a getter
assertEquals( assertEquals(
Deno.inspect(Event.prototype), Deno.inspect(Event.prototype),

View file

@ -6,11 +6,10 @@ import {
deferred, deferred,
fail, fail,
unimplemented, unimplemented,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
import { Buffer } from "../../../test_util/std/io/buffer.ts"; import { Buffer } from "../../../test_util/std/io/buffer.ts";
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchRequiresOneArgument() { async function fetchRequiresOneArgument() {
await assertRejects( await assertRejects(
@ -20,7 +19,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function fetchProtocolError() { Deno.test({ permissions: { net: true } }, async function fetchProtocolError() {
await assertRejects( await assertRejects(
async () => { async () => {
await fetch("ftp://localhost:21/a/file"); await fetch("ftp://localhost:21/a/file");
@ -54,7 +53,7 @@ function findClosedPortInRange(
); );
} }
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchConnectionError() { async function fetchConnectionError() {
const port = findClosedPortInRange(4000, 9999); const port = findClosedPortInRange(4000, 9999);
@ -68,7 +67,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchDnsError() { async function fetchDnsError() {
await assertRejects( await assertRejects(
@ -81,7 +80,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInvalidUriError() { async function fetchInvalidUriError() {
await assertRejects( await assertRejects(
@ -93,25 +92,25 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function fetchJsonSuccess() { Deno.test({ permissions: { net: true } }, async function fetchJsonSuccess() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const json = await response.json(); const json = await response.json();
assertEquals(json.name, "deno"); assertEquals(json.name, "deno");
}); });
unitTest(async function fetchPerm() { Deno.test({ permissions: { net: false } }, async function fetchPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await fetch("http://localhost:4545/fixture.json"); await fetch("http://localhost:4545/fixture.json");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { net: true } }, async function fetchUrl() { Deno.test({ permissions: { net: true } }, async function fetchUrl() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
assertEquals(response.url, "http://localhost:4545/fixture.json"); assertEquals(response.url, "http://localhost:4545/fixture.json");
const _json = await response.json(); const _json = await response.json();
}); });
unitTest({ permissions: { net: true } }, async function fetchURL() { Deno.test({ permissions: { net: true } }, async function fetchURL() {
const response = await fetch( const response = await fetch(
new URL("http://localhost:4545/fixture.json"), new URL("http://localhost:4545/fixture.json"),
); );
@ -119,14 +118,14 @@ unitTest({ permissions: { net: true } }, async function fetchURL() {
const _json = await response.json(); const _json = await response.json();
}); });
unitTest({ permissions: { net: true } }, async function fetchHeaders() { Deno.test({ permissions: { net: true } }, async function fetchHeaders() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const headers = response.headers; const headers = response.headers;
assertEquals(headers.get("Content-Type"), "application/json"); assertEquals(headers.get("Content-Type"), "application/json");
const _json = await response.json(); const _json = await response.json();
}); });
unitTest({ permissions: { net: true } }, async function fetchBlob() { Deno.test({ permissions: { net: true } }, async function fetchBlob() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const headers = response.headers; const headers = response.headers;
const blob = await response.blob(); const blob = await response.blob();
@ -134,7 +133,7 @@ unitTest({ permissions: { net: true } }, async function fetchBlob() {
assertEquals(blob.size, Number(headers.get("Content-Length"))); assertEquals(blob.size, Number(headers.get("Content-Length")));
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyUsedReader() { async function fetchBodyUsedReader() {
const response = await fetch( const response = await fetch(
@ -152,7 +151,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyUsedCancelStream() { async function fetchBodyUsedCancelStream() {
const response = await fetch( const response = await fetch(
@ -167,7 +166,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function fetchAsyncIterator() { Deno.test({ permissions: { net: true } }, async function fetchAsyncIterator() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const headers = response.headers; const headers = response.headers;
@ -181,7 +180,7 @@ unitTest({ permissions: { net: true } }, async function fetchAsyncIterator() {
assertEquals(total, Number(headers.get("Content-Length"))); assertEquals(total, Number(headers.get("Content-Length")));
}); });
unitTest({ permissions: { net: true } }, async function fetchBodyReader() { Deno.test({ permissions: { net: true } }, async function fetchBodyReader() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const headers = response.headers; const headers = response.headers;
assert(response.body !== null); assert(response.body !== null);
@ -198,7 +197,7 @@ unitTest({ permissions: { net: true } }, async function fetchBodyReader() {
assertEquals(total, Number(headers.get("Content-Length"))); assertEquals(total, Number(headers.get("Content-Length")));
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyReaderBigBody() { async function fetchBodyReaderBigBody() {
const data = "a".repeat(10 << 10); // 10mb const data = "a".repeat(10 << 10); // 10mb
@ -220,7 +219,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function responseClone() { Deno.test({ permissions: { net: true } }, async function responseClone() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
const response1 = response.clone(); const response1 = response.clone();
assert(response !== response1); assert(response !== response1);
@ -233,7 +232,7 @@ unitTest({ permissions: { net: true } }, async function responseClone() {
} }
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchMultipartFormDataSuccess() { async function fetchMultipartFormDataSuccess() {
const response = await fetch( const response = await fetch(
@ -250,7 +249,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchMultipartFormBadContentType() { async function fetchMultipartFormBadContentType() {
const response = await fetch( const response = await fetch(
@ -268,7 +267,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchURLEncodedFormDataSuccess() { async function fetchURLEncodedFormDataSuccess() {
const response = await fetch( const response = await fetch(
@ -282,7 +281,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitFormDataBinaryFileBody() { async function fetchInitFormDataBinaryFileBody() {
// Some random bytes // Some random bytes
@ -301,7 +300,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitFormDataMultipleFilesBody() { async function fetchInitFormDataMultipleFilesBody() {
const files = [ const files = [
@ -355,7 +354,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -369,7 +368,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -384,7 +383,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -405,7 +404,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -418,7 +417,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitStringBody() { async function fetchInitStringBody() {
const data = "Hello World"; const data = "Hello World";
@ -432,7 +431,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchRequestInitStringBody() { async function fetchRequestInitStringBody() {
const data = "Hello World"; const data = "Hello World";
@ -446,7 +445,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchSeparateInit() { async function fetchSeparateInit() {
// related to: https://github.com/denoland/deno/issues/10396 // related to: https://github.com/denoland/deno/issues/10396
@ -461,7 +460,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitTypedArrayBody() { async function fetchInitTypedArrayBody() {
const data = "Hello World"; const data = "Hello World";
@ -474,7 +473,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitArrayBufferBody() { async function fetchInitArrayBufferBody() {
const data = "Hello World"; const data = "Hello World";
@ -487,7 +486,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitURLSearchParamsBody() { async function fetchInitURLSearchParamsBody() {
const data = "param1=value1&param2=value2"; const data = "param1=value1&param2=value2";
@ -506,7 +505,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function fetchInitBlobBody() { Deno.test({ permissions: { net: true } }, async function fetchInitBlobBody() {
const data = "const a = 1"; const data = "const a = 1";
const blob = new Blob([data], { const blob = new Blob([data], {
type: "text/javascript", type: "text/javascript",
@ -520,7 +519,7 @@ unitTest({ permissions: { net: true } }, async function fetchInitBlobBody() {
assert(response.headers.get("content-type")!.startsWith("text/javascript")); assert(response.headers.get("content-type")!.startsWith("text/javascript"));
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitFormDataBody() { async function fetchInitFormDataBody() {
const form = new FormData(); const form = new FormData();
@ -534,7 +533,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitFormDataBlobFilenameBody() { async function fetchInitFormDataBlobFilenameBody() {
const form = new FormData(); const form = new FormData();
@ -552,7 +551,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchInitFormDataTextFileBody() { async function fetchInitFormDataTextFileBody() {
const fileContent = "deno land"; const fileContent = "deno land";
@ -582,7 +581,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function fetchUserAgent() { Deno.test({ permissions: { net: true } }, async function fetchUserAgent() {
const data = "Hello World"; const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", { const response = await fetch("http://localhost:4545/echo_server", {
method: "POST", method: "POST",
@ -619,7 +618,7 @@ function bufferServer(addr: string): Promise<Buffer> {
}); });
} }
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -652,7 +651,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -689,7 +688,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -726,7 +725,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -740,7 +739,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -756,7 +755,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -772,7 +771,7 @@ unitTest(
}, },
); );
unitTest(function responseRedirect() { Deno.test(function responseRedirect() {
const redir = Response.redirect("example.com/newLocation", 301); const redir = Response.redirect("example.com/newLocation", 301);
assertEquals(redir.status, 301); assertEquals(redir.status, 301);
assertEquals(redir.statusText, ""); assertEquals(redir.statusText, "");
@ -784,7 +783,7 @@ unitTest(function responseRedirect() {
assertEquals(redir.type, "default"); assertEquals(redir.type, "default");
}); });
unitTest(async function responseWithoutBody() { Deno.test(async function responseWithoutBody() {
const response = new Response(); const response = new Response();
assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); assertEquals(await response.arrayBuffer(), new ArrayBuffer(0));
const blob = await response.blob(); const blob = await response.blob();
@ -796,7 +795,7 @@ unitTest(async function responseWithoutBody() {
}); });
}); });
unitTest({ permissions: { net: true } }, async function fetchBodyReadTwice() { Deno.test({ permissions: { net: true } }, async function fetchBodyReadTwice() {
const response = await fetch("http://localhost:4545/fixture.json"); const response = await fetch("http://localhost:4545/fixture.json");
// Read body // Read body
@ -817,7 +816,7 @@ unitTest({ permissions: { net: true } }, async function fetchBodyReadTwice() {
} }
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyReaderAfterRead() { async function fetchBodyReaderAfterRead() {
const response = await fetch( const response = await fetch(
@ -840,7 +839,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyReaderWithCancelAndNewReader() { async function fetchBodyReaderWithCancelAndNewReader() {
const data = "a".repeat(1 << 10); const data = "a".repeat(1 << 10);
@ -868,7 +867,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchBodyReaderWithReadCancelAndNewReader() { async function fetchBodyReaderWithReadCancelAndNewReader() {
const data = "a".repeat(1 << 10); const data = "a".repeat(1 << 10);
@ -898,7 +897,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchResourceCloseAfterStreamCancel() { async function fetchResourceCloseAfterStreamCancel() {
const res = await fetch("http://localhost:4545/fixture.json"); const res = await fetch("http://localhost:4545/fixture.json");
@ -916,7 +915,7 @@ unitTest(
// TypeError: error sending request for url (http://localhost:4545/echo_server): // TypeError: error sending request for url (http://localhost:4545/echo_server):
// connection error: An established connection was aborted by // connection error: An established connection was aborted by
// the software in your host machine. (os error 10053) // the software in your host machine. (os error 10053)
unitTest( Deno.test(
{ permissions: { net: true }, ignore: Deno.build.os == "windows" }, { permissions: { net: true }, ignore: Deno.build.os == "windows" },
async function fetchNullBodyStatus() { async function fetchNullBodyStatus() {
const nullBodyStatus = [101, 204, 205, 304]; const nullBodyStatus = [101, 204, 205, 304];
@ -934,7 +933,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchResponseContentLength() { async function fetchResponseContentLength() {
const body = new Uint8Array(2 ** 16); const body = new Uint8Array(2 ** 16);
@ -953,7 +952,7 @@ unitTest(
}, },
); );
unitTest(function fetchResponseConstructorNullBody() { Deno.test(function fetchResponseConstructorNullBody() {
const nullBodyStatus = [204, 205, 304]; const nullBodyStatus = [204, 205, 304];
for (const status of nullBodyStatus) { for (const status of nullBodyStatus) {
@ -970,7 +969,7 @@ unitTest(function fetchResponseConstructorNullBody() {
} }
}); });
unitTest(function fetchResponseConstructorInvalidStatus() { Deno.test(function fetchResponseConstructorInvalidStatus() {
const invalidStatus = [101, 600, 199, null, "", NaN]; const invalidStatus = [101, 600, 199, null, "", NaN];
for (const status of invalidStatus) { for (const status of invalidStatus) {
@ -986,7 +985,7 @@ unitTest(function fetchResponseConstructorInvalidStatus() {
} }
}); });
unitTest(function fetchResponseEmptyConstructor() { Deno.test(function fetchResponseEmptyConstructor() {
const response = new Response(); const response = new Response();
assertEquals(response.status, 200); assertEquals(response.status, 200);
assertEquals(response.body, null); assertEquals(response.body, null);
@ -998,7 +997,7 @@ unitTest(function fetchResponseEmptyConstructor() {
assertEquals([...response.headers], []); assertEquals([...response.headers], []);
}); });
unitTest( Deno.test(
{ permissions: { net: true, read: true } }, { permissions: { net: true, read: true } },
async function fetchCustomHttpClientParamCertificateSuccess(): Promise< async function fetchCustomHttpClientParamCertificateSuccess(): Promise<
void void
@ -1014,7 +1013,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchCustomClientUserAgent(): Promise< async function fetchCustomClientUserAgent(): Promise<
void void
@ -1035,7 +1034,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -1083,7 +1082,7 @@ unitTest(
}, },
); );
unitTest({}, function fetchWritableRespProps() { Deno.test({}, function fetchWritableRespProps() {
const original = new Response("https://deno.land", { const original = new Response("https://deno.land", {
status: 404, status: 404,
headers: { "x-deno": "foo" }, headers: { "x-deno": "foo" },
@ -1122,7 +1121,7 @@ function returnHostHeaderServer(addr: string): Deno.Listener {
return listener; return listener;
} }
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchFilterOutCustomHostHeader(): Promise< async function fetchFilterOutCustomHostHeader(): Promise<
void void
@ -1139,7 +1138,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchNoServerReadableStreamBody() { async function fetchNoServerReadableStreamBody() {
const done = deferred(); const done = deferred();
@ -1160,7 +1159,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchHeadRespBody() { async function fetchHeadRespBody() {
const res = await fetch("http://localhost:4545/echo_server", { const res = await fetch("http://localhost:4545/echo_server", {
@ -1170,7 +1169,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function fetchClientCertWrongPrivateKey(): Promise<void> { async function fetchClientCertWrongPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1187,7 +1186,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function fetchClientCertBadPrivateKey(): Promise<void> { async function fetchClientCertBadPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1204,7 +1203,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function fetchClientCertNotPrivateKey(): Promise<void> { async function fetchClientCertNotPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1221,7 +1220,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function fetchCustomClientPrivateKey(): Promise< async function fetchCustomClientPrivateKey(): Promise<
void void
@ -1251,7 +1250,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchAbortWhileUploadStreaming(): Promise<void> { async function fetchAbortWhileUploadStreaming(): Promise<void> {
const abortController = new AbortController(); const abortController = new AbortController();
@ -1278,7 +1277,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchHeaderValueShouldNotPanic() { async function fetchHeaderValueShouldNotPanic() {
for (let i = 0; i < 0x21; i++) { for (let i = 0; i < 0x21; i++) {
@ -1300,7 +1299,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchHeaderNameShouldNotPanic() { async function fetchHeaderNameShouldNotPanic() {
const validTokens = const validTokens =
@ -1326,7 +1325,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true, read: true } }, { permissions: { net: true, read: true } },
async function fetchSupportsHttp1Only() { async function fetchSupportsHttp1Only() {
const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem");
@ -1338,7 +1337,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true, read: true } }, { permissions: { net: true, read: true } },
async function fetchSupportsHttp2() { async function fetchSupportsHttp2() {
const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem");
@ -1350,7 +1349,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true, read: true } }, { permissions: { net: true, read: true } },
async function fetchPrefersHttp2() { async function fetchPrefersHttp2() {
const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem");
@ -1362,19 +1361,22 @@ unitTest(
}, },
); );
unitTest(async function fetchFilePerm() { Deno.test({ permissions: { read: false } }, async function fetchFilePerm() {
await assertRejects(async () => { await assertRejects(async () => {
await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url)); await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url));
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest(async function fetchFilePermDoesNotExist() { Deno.test(
{ permissions: { read: false } },
async function fetchFilePermDoesNotExist() {
await assertRejects(async () => { await assertRejects(async () => {
await fetch(new URL("./bad.json", import.meta.url)); await fetch(new URL("./bad.json", import.meta.url));
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); },
);
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function fetchFileBadMethod() { async function fetchFileBadMethod() {
await assertRejects( await assertRejects(
@ -1392,7 +1394,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function fetchFileDoesNotExist() { async function fetchFileDoesNotExist() {
await assertRejects( await assertRejects(
@ -1404,7 +1406,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function fetchFile() { async function fetchFile() {
const res = await fetch( const res = await fetch(
@ -1418,7 +1420,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchContentLengthPost() { async function fetchContentLengthPost() {
const response = await fetch("http://localhost:4545/content_length", { const response = await fetch("http://localhost:4545/content_length", {
@ -1429,7 +1431,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchContentLengthPut() { async function fetchContentLengthPut() {
const response = await fetch("http://localhost:4545/content_length", { const response = await fetch("http://localhost:4545/content_length", {
@ -1440,7 +1442,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchContentLengthPatch() { async function fetchContentLengthPatch() {
const response = await fetch("http://localhost:4545/content_length", { const response = await fetch("http://localhost:4545/content_length", {
@ -1451,7 +1453,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchContentLengthPostWithStringBody() { async function fetchContentLengthPostWithStringBody() {
const response = await fetch("http://localhost:4545/content_length", { const response = await fetch("http://localhost:4545/content_length", {
@ -1463,7 +1465,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function fetchContentLengthPostWithBufferBody() { async function fetchContentLengthPostWithBufferBody() {
const response = await fetch("http://localhost:4545/content_length", { const response = await fetch("http://localhost:4545/content_length", {

View file

@ -1,8 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertThrows, unitTest } from "./test_util.ts"; import { assertThrows } from "./test_util.ts";
unitTest({ permissions: { ffi: true } }, function dlopenInvalidArguments() { Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() {
const filename = "/usr/lib/libc.so.6"; const filename = "/usr/lib/libc.so.6";
assertThrows(() => { assertThrows(() => {
// @ts-expect-error: ForeignFunction cannot be null // @ts-expect-error: ForeignFunction cannot be null

View file

@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
function testFirstArgument(arg1: any[], expectedSize: number) { function testFirstArgument(arg1: any[], expectedSize: number) {
@ -10,47 +10,47 @@ function testFirstArgument(arg1: any[], expectedSize: number) {
assertEquals(file.type, ""); assertEquals(file.type, "");
} }
unitTest(function fileEmptyFileBits() { Deno.test(function fileEmptyFileBits() {
testFirstArgument([], 0); testFirstArgument([], 0);
}); });
unitTest(function fileStringFileBits() { Deno.test(function fileStringFileBits() {
testFirstArgument(["bits"], 4); testFirstArgument(["bits"], 4);
}); });
unitTest(function fileUnicodeStringFileBits() { Deno.test(function fileUnicodeStringFileBits() {
testFirstArgument(["𝓽𝓮𝔁𝓽"], 16); testFirstArgument(["𝓽𝓮𝔁𝓽"], 16);
}); });
unitTest(function fileStringObjectFileBits() { Deno.test(function fileStringObjectFileBits() {
testFirstArgument([new String("string object")], 13); testFirstArgument([new String("string object")], 13);
}); });
unitTest(function fileEmptyBlobFileBits() { Deno.test(function fileEmptyBlobFileBits() {
testFirstArgument([new Blob()], 0); testFirstArgument([new Blob()], 0);
}); });
unitTest(function fileBlobFileBits() { Deno.test(function fileBlobFileBits() {
testFirstArgument([new Blob(["bits"])], 4); testFirstArgument([new Blob(["bits"])], 4);
}); });
unitTest(function fileEmptyFileFileBits() { Deno.test(function fileEmptyFileFileBits() {
testFirstArgument([new File([], "world.txt")], 0); testFirstArgument([new File([], "world.txt")], 0);
}); });
unitTest(function fileFileFileBits() { Deno.test(function fileFileFileBits() {
testFirstArgument([new File(["bits"], "world.txt")], 4); testFirstArgument([new File(["bits"], "world.txt")], 4);
}); });
unitTest(function fileArrayBufferFileBits() { Deno.test(function fileArrayBufferFileBits() {
testFirstArgument([new ArrayBuffer(8)], 8); testFirstArgument([new ArrayBuffer(8)], 8);
}); });
unitTest(function fileTypedArrayFileBits() { Deno.test(function fileTypedArrayFileBits() {
testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4); testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4);
}); });
unitTest(function fileVariousFileBits() { Deno.test(function fileVariousFileBits() {
testFirstArgument( testFirstArgument(
[ [
"bits", "bits",
@ -64,15 +64,15 @@ unitTest(function fileVariousFileBits() {
); );
}); });
unitTest(function fileNumberInFileBits() { Deno.test(function fileNumberInFileBits() {
testFirstArgument([12], 2); testFirstArgument([12], 2);
}); });
unitTest(function fileArrayInFileBits() { Deno.test(function fileArrayInFileBits() {
testFirstArgument([[1, 2, 3]], 5); testFirstArgument([[1, 2, 3]], 5);
}); });
unitTest(function fileObjectInFileBits() { Deno.test(function fileObjectInFileBits() {
// "[object Object]" // "[object Object]"
testFirstArgument([{}], 15); testFirstArgument([{}], 15);
}); });
@ -84,23 +84,23 @@ function testSecondArgument(arg2: any, expectedFileName: string) {
assertEquals(file.name, expectedFileName); assertEquals(file.name, expectedFileName);
} }
unitTest(function fileUsingFileName() { Deno.test(function fileUsingFileName() {
testSecondArgument("dummy", "dummy"); testSecondArgument("dummy", "dummy");
}); });
unitTest(function fileUsingNullFileName() { Deno.test(function fileUsingNullFileName() {
testSecondArgument(null, "null"); testSecondArgument(null, "null");
}); });
unitTest(function fileUsingNumberFileName() { Deno.test(function fileUsingNumberFileName() {
testSecondArgument(1, "1"); testSecondArgument(1, "1");
}); });
unitTest(function fileUsingEmptyStringFileName() { Deno.test(function fileUsingEmptyStringFileName() {
testSecondArgument("", ""); testSecondArgument("", "");
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function fileTruncateSyncSuccess() { function fileTruncateSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fileTruncateSync.txt"; const filename = Deno.makeTempDirSync() + "/test_fileTruncateSync.txt";
@ -122,7 +122,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function fileTruncateSuccess() { async function fileTruncateSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fileTruncate.txt"; const filename = Deno.makeTempDirSync() + "/test_fileTruncate.txt";
@ -144,7 +144,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, function fileStatSyncSuccess() { Deno.test({ permissions: { read: true } }, function fileStatSyncSuccess() {
const file = Deno.openSync("README.md"); const file = Deno.openSync("README.md");
const fileInfo = file.statSync(); const fileInfo = file.statSync();
assert(fileInfo.isFile); assert(fileInfo.isFile);
@ -159,7 +159,7 @@ unitTest({ permissions: { read: true } }, function fileStatSyncSuccess() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, async function fileStatSuccess() { Deno.test({ permissions: { read: true } }, async function fileStatSuccess() {
const file = await Deno.open("README.md"); const file = await Deno.open("README.md");
const fileInfo = await file.stat(); const fileInfo = await file.stat();
assert(fileInfo.isFile); assert(fileInfo.isFile);

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(function fileReaderConstruct() { Deno.test(function fileReaderConstruct() {
const fr = new FileReader(); const fr = new FileReader();
assertEquals(fr.readyState, FileReader.EMPTY); assertEquals(fr.readyState, FileReader.EMPTY);
@ -10,7 +10,7 @@ unitTest(function fileReaderConstruct() {
assertEquals(FileReader.DONE, 2); assertEquals(FileReader.DONE, 2);
}); });
unitTest(async function fileReaderLoadBlob() { Deno.test(async function fileReaderLoadBlob() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
@ -77,7 +77,7 @@ unitTest(async function fileReaderLoadBlob() {
}); });
}); });
unitTest(async function fileReaderLoadBlobDouble() { Deno.test(async function fileReaderLoadBlobDouble() {
// impl note from https://w3c.github.io/FileAPI/ // impl note from https://w3c.github.io/FileAPI/
// Event handler for the load or error events could have started another load, // Event handler for the load or error events could have started another load,
// if that happens the loadend event for the first load is not fired // if that happens the loadend event for the first load is not fired
@ -107,7 +107,7 @@ unitTest(async function fileReaderLoadBlobDouble() {
}); });
}); });
unitTest(async function fileReaderLoadBlobArrayBuffer() { Deno.test(async function fileReaderLoadBlobArrayBuffer() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
@ -129,7 +129,7 @@ unitTest(async function fileReaderLoadBlobArrayBuffer() {
}); });
}); });
unitTest(async function fileReaderLoadBlobDataUrl() { Deno.test(async function fileReaderLoadBlobDataUrl() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
@ -149,7 +149,7 @@ unitTest(async function fileReaderLoadBlobDataUrl() {
}); });
}); });
unitTest(async function fileReaderLoadBlobAbort() { Deno.test(async function fileReaderLoadBlobAbort() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
@ -184,7 +184,7 @@ unitTest(async function fileReaderLoadBlobAbort() {
}); });
}); });
unitTest(async function fileReaderLoadBlobAbort() { Deno.test(async function fileReaderLoadBlobAbort() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();
const b1 = new Blob(["Hello World"]); const b1 = new Blob(["Hello World"]);
@ -219,7 +219,7 @@ unitTest(async function fileReaderLoadBlobAbort() {
}); });
}); });
unitTest( Deno.test(
async function fileReaderDispatchesEventsInCorrectOrder() { async function fileReaderDispatchesEventsInCorrectOrder() {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
const fr = new FileReader(); const fr = new FileReader();

View file

@ -7,17 +7,16 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
import { copy } from "../../../test_util/std/io/util.ts"; import { copy } from "../../../test_util/std/io/util.ts";
unitTest(function filesStdioFileDescriptors() { Deno.test(function filesStdioFileDescriptors() {
assertEquals(Deno.stdin.rid, 0); assertEquals(Deno.stdin.rid, 0);
assertEquals(Deno.stdout.rid, 1); assertEquals(Deno.stdout.rid, 1);
assertEquals(Deno.stderr.rid, 2); assertEquals(Deno.stderr.rid, 2);
}); });
unitTest({ permissions: { read: true } }, async function filesCopyToStdout() { Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() {
const filename = "cli/tests/testdata/fixture.json"; const filename = "cli/tests/testdata/fixture.json";
const file = await Deno.open(filename); const file = await Deno.open(filename);
assert(file.rid > 2); assert(file.rid > 2);
@ -27,7 +26,7 @@ unitTest({ permissions: { read: true } }, async function filesCopyToStdout() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, async function filesIter() { Deno.test({ permissions: { read: true } }, async function filesIter() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = await Deno.open(filename); const file = await Deno.open(filename);
@ -40,7 +39,7 @@ unitTest({ permissions: { read: true } }, async function filesIter() {
file.close(); file.close();
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function filesIterCustomBufSize() { async function filesIterCustomBufSize() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
@ -59,7 +58,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, function filesIterSync() { Deno.test({ permissions: { read: true } }, function filesIterSync() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = Deno.openSync(filename); const file = Deno.openSync(filename);
@ -72,7 +71,7 @@ unitTest({ permissions: { read: true } }, function filesIterSync() {
file.close(); file.close();
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
function filesIterSyncCustomBufSize() { function filesIterSyncCustomBufSize() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
@ -91,7 +90,7 @@ unitTest(
}, },
); );
unitTest(async function readerIter() { Deno.test(async function readerIter() {
// ref: https://github.com/denoland/deno/issues/2330 // ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder(); const encoder = new TextEncoder();
@ -126,7 +125,7 @@ unitTest(async function readerIter() {
assertEquals(totalSize, 12); assertEquals(totalSize, 12);
}); });
unitTest(async function readerIterSync() { Deno.test(async function readerIterSync() {
// ref: https://github.com/denoland/deno/issues/2330 // ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder(); const encoder = new TextEncoder();
@ -161,7 +160,7 @@ unitTest(async function readerIterSync() {
assertEquals(totalSize, 12); assertEquals(totalSize, 12);
}); });
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -180,7 +179,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -199,7 +198,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -225,7 +224,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -251,7 +250,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: false } }, { permissions: { write: false } },
async function writePermFailure() { async function writePermFailure() {
const filename = "tests/hello.txt"; const filename = "tests/hello.txt";
@ -264,7 +263,7 @@ unitTest(
}, },
); );
unitTest(async function openOptions() { Deno.test(async function openOptions() {
const filename = "cli/tests/testdata/fixture.json"; const filename = "cli/tests/testdata/fixture.json";
await assertRejects( await assertRejects(
async () => { async () => {
@ -299,13 +298,13 @@ unitTest(async function openOptions() {
); );
}); });
unitTest({ permissions: { read: false } }, async function readPermFailure() { Deno.test({ permissions: { read: false } }, async function readPermFailure() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.open("package.json", { read: true }); await Deno.open("package.json", { read: true });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { write: true } }, { permissions: { write: true } },
async function writeNullBufferFailure() { async function writeNullBufferFailure() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -329,7 +328,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function readNullBufferFailure() { async function readNullBufferFailure() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -357,7 +356,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: false, read: false } }, { permissions: { write: false, read: false } },
async function readWritePermFailure() { async function readWritePermFailure() {
const filename = "tests/hello.txt"; const filename = "tests/hello.txt";
@ -367,7 +366,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function openNotFound() { async function openNotFound() {
await assertRejects( await assertRejects(
@ -380,7 +379,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
function openSyncNotFound() { function openSyncNotFound() {
assertThrows( assertThrows(
@ -393,7 +392,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function createFile() { async function createFile() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -414,7 +413,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function createFileWithUrl() { async function createFileWithUrl() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -436,7 +435,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function createSyncFile() { async function createSyncFile() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -457,7 +456,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function createSyncFileWithUrl() { async function createSyncFileWithUrl() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -479,7 +478,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function openModeWrite() { async function openModeWrite() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -522,7 +521,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function openModeWriteRead() { async function openModeWriteRead() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -558,7 +557,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, async function seekStart() { Deno.test({ permissions: { read: true } }, async function seekStart() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = await Deno.open(filename); const file = await Deno.open(filename);
const seekPosition = 6; const seekPosition = 6;
@ -575,7 +574,7 @@ unitTest({ permissions: { read: true } }, async function seekStart() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, function seekSyncStart() { Deno.test({ permissions: { read: true } }, function seekSyncStart() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = Deno.openSync(filename); const file = Deno.openSync(filename);
const seekPosition = 6; const seekPosition = 6;
@ -592,7 +591,7 @@ unitTest({ permissions: { read: true } }, function seekSyncStart() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, async function seekCurrent() { Deno.test({ permissions: { read: true } }, async function seekCurrent() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = await Deno.open(filename); const file = await Deno.open(filename);
// Deliberately move 1 step forward // Deliberately move 1 step forward
@ -609,7 +608,7 @@ unitTest({ permissions: { read: true } }, async function seekCurrent() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, function seekSyncCurrent() { Deno.test({ permissions: { read: true } }, function seekSyncCurrent() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = Deno.openSync(filename); const file = Deno.openSync(filename);
// Deliberately move 1 step forward // Deliberately move 1 step forward
@ -626,7 +625,7 @@ unitTest({ permissions: { read: true } }, function seekSyncCurrent() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, async function seekEnd() { Deno.test({ permissions: { read: true } }, async function seekEnd() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = await Deno.open(filename); const file = await Deno.open(filename);
const seekPosition = -6; const seekPosition = -6;
@ -640,7 +639,7 @@ unitTest({ permissions: { read: true } }, async function seekEnd() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, function seekSyncEnd() { Deno.test({ permissions: { read: true } }, function seekSyncEnd() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = Deno.openSync(filename); const file = Deno.openSync(filename);
const seekPosition = -6; const seekPosition = -6;
@ -654,7 +653,7 @@ unitTest({ permissions: { read: true } }, function seekSyncEnd() {
file.close(); file.close();
}); });
unitTest({ permissions: { read: true } }, async function seekMode() { Deno.test({ permissions: { read: true } }, async function seekMode() {
const filename = "cli/tests/testdata/hello.txt"; const filename = "cli/tests/testdata/hello.txt";
const file = await Deno.open(filename); const file = await Deno.open(filename);
await assertRejects( await assertRejects(

View file

@ -1,15 +1,15 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
import { readAll } from "../../../test_util/std/io/util.ts"; import { readAll } from "../../../test_util/std/io/util.ts";
unitTest( Deno.test(
{ permissions: { read: true, run: true, hrtime: true } }, { permissions: { read: true, run: true, hrtime: true } },
async function flockFileSync() { async function flockFileSync() {
await runFlockTests({ sync: true }); await runFlockTests({ sync: true });
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, run: true, hrtime: true } }, { permissions: { read: true, run: true, hrtime: true } },
async function flockFileAsync() { async function flockFileAsync() {
await runFlockTests({ sync: false }); await runFlockTests({ sync: false });

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function formatDiagnosticBasic() { Deno.test(function formatDiagnosticBasic() {
const fixture: Deno.Diagnostic[] = [ const fixture: Deno.Diagnostic[] = [
{ {
start: { start: {
@ -25,7 +25,7 @@ unitTest(function formatDiagnosticBasic() {
assert(out.includes("test.ts")); assert(out.includes("test.ts"));
}); });
unitTest(function formatDiagnosticError() { Deno.test(function formatDiagnosticError() {
let thrown = false; let thrown = false;
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
const bad = ([{ hello: 123 }] as any) as Deno.Diagnostic[]; const bad = ([{ hello: 123 }] as any) as Deno.Diagnostic[];

View file

@ -1,21 +1,15 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { import { assert, assertEquals, assertThrows, delay } from "./test_util.ts";
assert,
assertEquals,
assertThrows,
delay,
unitTest,
} from "./test_util.ts";
// TODO(ry) Add more tests to specify format. // TODO(ry) Add more tests to specify format.
unitTest({ permissions: { read: false } }, function watchFsPermissions() { Deno.test({ permissions: { read: false } }, function watchFsPermissions() {
assertThrows(() => { assertThrows(() => {
Deno.watchFs("."); Deno.watchFs(".");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function watchFsInvalidPath() { Deno.test({ permissions: { read: true } }, function watchFsInvalidPath() {
if (Deno.build.os === "windows") { if (Deno.build.os === "windows") {
assertThrows( assertThrows(
() => { () => {
@ -50,7 +44,7 @@ async function makeTempDir(): Promise<string> {
return testDir; return testDir;
} }
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function watchFsBasic() { async function watchFsBasic() {
const testDir = await makeTempDir(); const testDir = await makeTempDir();
@ -77,7 +71,7 @@ unitTest(
// TODO(kt3k): This test is for the backward compatibility of `.return` method. // TODO(kt3k): This test is for the backward compatibility of `.return` method.
// This should be removed at 2.0 // This should be removed at 2.0
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function watchFsReturn() { async function watchFsReturn() {
const testDir = await makeTempDir(); const testDir = await makeTempDir();
@ -95,7 +89,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function watchFsClose() { async function watchFsClose() {
const testDir = await makeTempDir(); const testDir = await makeTempDir();

View file

@ -1,49 +1,49 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertNotEquals, assertStrictEquals, unitTest } from "./test_util.ts"; import { assertNotEquals, assertStrictEquals } from "./test_util.ts";
unitTest(function getRandomValuesInt8Array() { Deno.test(function getRandomValuesInt8Array() {
const arr = new Int8Array(32); const arr = new Int8Array(32);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Int8Array(32)); assertNotEquals(arr, new Int8Array(32));
}); });
unitTest(function getRandomValuesUint8Array() { Deno.test(function getRandomValuesUint8Array() {
const arr = new Uint8Array(32); const arr = new Uint8Array(32);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint8Array(32)); assertNotEquals(arr, new Uint8Array(32));
}); });
unitTest(function getRandomValuesUint8ClampedArray() { Deno.test(function getRandomValuesUint8ClampedArray() {
const arr = new Uint8ClampedArray(32); const arr = new Uint8ClampedArray(32);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint8ClampedArray(32)); assertNotEquals(arr, new Uint8ClampedArray(32));
}); });
unitTest(function getRandomValuesInt16Array() { Deno.test(function getRandomValuesInt16Array() {
const arr = new Int16Array(4); const arr = new Int16Array(4);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Int16Array(4)); assertNotEquals(arr, new Int16Array(4));
}); });
unitTest(function getRandomValuesUint16Array() { Deno.test(function getRandomValuesUint16Array() {
const arr = new Uint16Array(4); const arr = new Uint16Array(4);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint16Array(4)); assertNotEquals(arr, new Uint16Array(4));
}); });
unitTest(function getRandomValuesInt32Array() { Deno.test(function getRandomValuesInt32Array() {
const arr = new Int32Array(8); const arr = new Int32Array(8);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Int32Array(8)); assertNotEquals(arr, new Int32Array(8));
}); });
unitTest(function getRandomValuesUint32Array() { Deno.test(function getRandomValuesUint32Array() {
const arr = new Uint32Array(8); const arr = new Uint32Array(8);
crypto.getRandomValues(arr); crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint32Array(8)); assertNotEquals(arr, new Uint32Array(8));
}); });
unitTest(function getRandomValuesReturnValue() { Deno.test(function getRandomValuesReturnValue() {
const arr = new Uint32Array(8); const arr = new Uint32Array(8);
const rtn = crypto.getRandomValues(arr); const rtn = crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint32Array(8)); assertNotEquals(arr, new Uint32Array(8));

View file

@ -1,73 +1,73 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-window-prefix // deno-lint-ignore-file no-window-prefix
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function globalThisExists() { Deno.test(function globalThisExists() {
assert(globalThis != null); assert(globalThis != null);
}); });
unitTest(function noInternalGlobals() { Deno.test(function noInternalGlobals() {
// globalThis.__bootstrap should not be there. // globalThis.__bootstrap should not be there.
for (const key of Object.keys(globalThis)) { for (const key of Object.keys(globalThis)) {
assert(!key.startsWith("_")); assert(!key.startsWith("_"));
} }
}); });
unitTest(function windowExists() { Deno.test(function windowExists() {
assert(window != null); assert(window != null);
}); });
unitTest(function selfExists() { Deno.test(function selfExists() {
assert(self != null); assert(self != null);
}); });
unitTest(function windowWindowExists() { Deno.test(function windowWindowExists() {
assert(window.window === window); assert(window.window === window);
}); });
unitTest(function windowSelfExists() { Deno.test(function windowSelfExists() {
assert(window.self === window); assert(window.self === window);
}); });
unitTest(function globalThisEqualsWindow() { Deno.test(function globalThisEqualsWindow() {
assert(globalThis === window); assert(globalThis === window);
}); });
unitTest(function globalThisEqualsSelf() { Deno.test(function globalThisEqualsSelf() {
assert(globalThis === self); assert(globalThis === self);
}); });
unitTest(function globalThisInstanceofWindow() { Deno.test(function globalThisInstanceofWindow() {
assert(globalThis instanceof Window); assert(globalThis instanceof Window);
}); });
unitTest(function globalThisConstructorLength() { Deno.test(function globalThisConstructorLength() {
assert(globalThis.constructor.length === 0); assert(globalThis.constructor.length === 0);
}); });
unitTest(function globalThisInstanceofEventTarget() { Deno.test(function globalThisInstanceofEventTarget() {
assert(globalThis instanceof EventTarget); assert(globalThis instanceof EventTarget);
}); });
unitTest(function navigatorInstanceofNavigator() { Deno.test(function navigatorInstanceofNavigator() {
// TODO(nayeemrmn): Add `Navigator` to deno_lint globals. // TODO(nayeemrmn): Add `Navigator` to deno_lint globals.
// deno-lint-ignore no-undef // deno-lint-ignore no-undef
assert(navigator instanceof Navigator); assert(navigator instanceof Navigator);
}); });
unitTest(function DenoNamespaceExists() { Deno.test(function DenoNamespaceExists() {
assert(Deno != null); assert(Deno != null);
}); });
unitTest(function DenoNamespaceEqualsWindowDeno() { Deno.test(function DenoNamespaceEqualsWindowDeno() {
assert(Deno === window.Deno); assert(Deno === window.Deno);
}); });
unitTest(function DenoNamespaceIsNotFrozen() { Deno.test(function DenoNamespaceIsNotFrozen() {
assert(!Object.isFrozen(Deno)); assert(!Object.isFrozen(Deno));
}); });
unitTest(function webAssemblyExists() { Deno.test(function webAssemblyExists() {
assert(typeof WebAssembly.compile === "function"); assert(typeof WebAssembly.compile === "function");
}); });
@ -78,14 +78,14 @@ declare global {
} }
} }
unitTest(function DenoNamespaceConfigurable() { Deno.test(function DenoNamespaceConfigurable() {
const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno"); const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno");
assert(desc); assert(desc);
assert(desc.configurable); assert(desc.configurable);
assert(!desc.writable); assert(!desc.writable);
}); });
unitTest(function DenoCoreNamespaceIsImmutable() { Deno.test(function DenoCoreNamespaceIsImmutable() {
const { print } = Deno.core; const { print } = Deno.core;
try { try {
Deno.core.print = 1; Deno.core.print = 1;
@ -101,7 +101,7 @@ unitTest(function DenoCoreNamespaceIsImmutable() {
assert(print === Deno.core.print); assert(print === Deno.core.print);
}); });
unitTest(async function windowQueueMicrotask() { Deno.test(async function windowQueueMicrotask() {
let resolve1: () => void | undefined; let resolve1: () => void | undefined;
let resolve2: () => void | undefined; let resolve2: () => void | undefined;
let microtaskDone = false; let microtaskDone = false;
@ -123,7 +123,7 @@ unitTest(async function windowQueueMicrotask() {
await p2; await p2;
}); });
unitTest(function webApiGlobalThis() { Deno.test(function webApiGlobalThis() {
assert(globalThis.FormData !== null); assert(globalThis.FormData !== null);
assert(globalThis.TextEncoder !== null); assert(globalThis.TextEncoder !== null);
assert(globalThis.TextEncoderStream !== null); assert(globalThis.TextEncoderStream !== null);

View file

@ -1,18 +1,18 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
const { const {
inspectArgs, inspectArgs,
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal]; } = Deno[Deno.internal];
unitTest(function headersHasCorrectNameProp() { Deno.test(function headersHasCorrectNameProp() {
assertEquals(Headers.name, "Headers"); assertEquals(Headers.name, "Headers");
}); });
// Logic heavily copied from web-platform-tests, make // Logic heavily copied from web-platform-tests, make
// sure pass mostly header basic test // sure pass mostly header basic test
// ref: https://github.com/web-platform-tests/wpt/blob/7c50c216081d6ea3c9afe553ee7b64534020a1b2/fetch/api/headers/headers-basic.html // ref: https://github.com/web-platform-tests/wpt/blob/7c50c216081d6ea3c9afe553ee7b64534020a1b2/fetch/api/headers/headers-basic.html
unitTest(function newHeaderTest() { Deno.test(function newHeaderTest() {
new Headers(); new Headers();
new Headers(undefined); new Headers(undefined);
new Headers({}); new Headers({});
@ -38,7 +38,7 @@ for (const name in headerDict) {
headerSeq.push([name, headerDict[name]]); headerSeq.push([name, headerDict[name]]);
} }
unitTest(function newHeaderWithSequence() { Deno.test(function newHeaderWithSequence() {
const headers = new Headers(headerSeq); const headers = new Headers(headerSeq);
for (const name in headerDict) { for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name])); assertEquals(headers.get(name), String(headerDict[name]));
@ -46,14 +46,14 @@ unitTest(function newHeaderWithSequence() {
assertEquals(headers.get("length"), null); assertEquals(headers.get("length"), null);
}); });
unitTest(function newHeaderWithRecord() { Deno.test(function newHeaderWithRecord() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
for (const name in headerDict) { for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name])); assertEquals(headers.get(name), String(headerDict[name]));
} }
}); });
unitTest(function newHeaderWithHeadersInstance() { Deno.test(function newHeaderWithHeadersInstance() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
const headers2 = new Headers(headers); const headers2 = new Headers(headers);
for (const name in headerDict) { for (const name in headerDict) {
@ -61,7 +61,7 @@ unitTest(function newHeaderWithHeadersInstance() {
} }
}); });
unitTest(function headerAppendSuccess() { Deno.test(function headerAppendSuccess() {
const headers = new Headers(); const headers = new Headers();
for (const name in headerDict) { for (const name in headerDict) {
headers.append(name, headerDict[name]); headers.append(name, headerDict[name]);
@ -69,7 +69,7 @@ unitTest(function headerAppendSuccess() {
} }
}); });
unitTest(function headerSetSuccess() { Deno.test(function headerSetSuccess() {
const headers = new Headers(); const headers = new Headers();
for (const name in headerDict) { for (const name in headerDict) {
headers.set(name, headerDict[name]); headers.set(name, headerDict[name]);
@ -77,7 +77,7 @@ unitTest(function headerSetSuccess() {
} }
}); });
unitTest(function headerHasSuccess() { Deno.test(function headerHasSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
for (const name in headerDict) { for (const name in headerDict) {
assert(headers.has(name), "headers has name " + name); assert(headers.has(name), "headers has name " + name);
@ -88,7 +88,7 @@ unitTest(function headerHasSuccess() {
} }
}); });
unitTest(function headerDeleteSuccess() { Deno.test(function headerDeleteSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
for (const name in headerDict) { for (const name in headerDict) {
assert(headers.has(name), "headers have a header: " + name); assert(headers.has(name), "headers have a header: " + name);
@ -97,7 +97,7 @@ unitTest(function headerDeleteSuccess() {
} }
}); });
unitTest(function headerGetSuccess() { Deno.test(function headerGetSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
for (const name in headerDict) { for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name])); assertEquals(headers.get(name), String(headerDict[name]));
@ -105,7 +105,7 @@ unitTest(function headerGetSuccess() {
} }
}); });
unitTest(function headerEntriesSuccess() { Deno.test(function headerEntriesSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
const iterators = headers.entries(); const iterators = headers.entries();
for (const it of iterators) { for (const it of iterators) {
@ -116,7 +116,7 @@ unitTest(function headerEntriesSuccess() {
} }
}); });
unitTest(function headerKeysSuccess() { Deno.test(function headerKeysSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
const iterators = headers.keys(); const iterators = headers.keys();
for (const it of iterators) { for (const it of iterators) {
@ -124,7 +124,7 @@ unitTest(function headerKeysSuccess() {
} }
}); });
unitTest(function headerValuesSuccess() { Deno.test(function headerValuesSuccess() {
const headers = new Headers(headerDict); const headers = new Headers(headerDict);
const iterators = headers.values(); const iterators = headers.values();
const entries = headers.entries(); const entries = headers.entries();
@ -146,7 +146,7 @@ const headerEntriesDict: Record<string, string> = {
"Content-Types": "value6", "Content-Types": "value6",
}; };
unitTest(function headerForEachSuccess() { Deno.test(function headerForEachSuccess() {
const headers = new Headers(headerEntriesDict); const headers = new Headers(headerEntriesDict);
const keys = Object.keys(headerEntriesDict); const keys = Object.keys(headerEntriesDict);
keys.forEach((key) => { keys.forEach((key) => {
@ -163,7 +163,7 @@ unitTest(function headerForEachSuccess() {
assertEquals(callNum, keys.length); assertEquals(callNum, keys.length);
}); });
unitTest(function headerSymbolIteratorSuccess() { Deno.test(function headerSymbolIteratorSuccess() {
assert(Symbol.iterator in Headers.prototype); assert(Symbol.iterator in Headers.prototype);
const headers = new Headers(headerEntriesDict); const headers = new Headers(headerEntriesDict);
for (const header of headers) { for (const header of headers) {
@ -174,7 +174,7 @@ unitTest(function headerSymbolIteratorSuccess() {
} }
}); });
unitTest(function headerTypesAvailable() { Deno.test(function headerTypesAvailable() {
function newHeaders(): Headers { function newHeaders(): Headers {
return new Headers(); return new Headers();
} }
@ -184,7 +184,7 @@ unitTest(function headerTypesAvailable() {
// Modified from https://github.com/bitinn/node-fetch/blob/7d3293200a91ad52b5ca7962f9d6fd1c04983edb/test/test.js#L2001-L2014 // Modified from https://github.com/bitinn/node-fetch/blob/7d3293200a91ad52b5ca7962f9d6fd1c04983edb/test/test.js#L2001-L2014
// Copyright (c) 2016 David Frank. MIT License. // Copyright (c) 2016 David Frank. MIT License.
unitTest(function headerIllegalReject() { Deno.test(function headerIllegalReject() {
let errorCount = 0; let errorCount = 0;
try { try {
new Headers({ "He y": "ok" }); new Headers({ "He y": "ok" });
@ -238,7 +238,7 @@ unitTest(function headerIllegalReject() {
}); });
// If pair does not contain exactly two items,then throw a TypeError. // If pair does not contain exactly two items,then throw a TypeError.
unitTest(function headerParamsShouldThrowTypeError() { Deno.test(function headerParamsShouldThrowTypeError() {
let hasThrown = 0; let hasThrown = 0;
try { try {
@ -255,7 +255,7 @@ unitTest(function headerParamsShouldThrowTypeError() {
assertEquals(hasThrown, 2); assertEquals(hasThrown, 2);
}); });
unitTest(function headerParamsArgumentsCheck() { Deno.test(function headerParamsArgumentsCheck() {
const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const; const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const;
const methodRequireTwoParams = ["append", "set"] as const; const methodRequireTwoParams = ["append", "set"] as const;
@ -310,7 +310,7 @@ unitTest(function headerParamsArgumentsCheck() {
}); });
}); });
unitTest(function headersInitMultiple() { Deno.test(function headersInitMultiple() {
const headers = new Headers([ const headers = new Headers([
["Set-Cookie", "foo=bar"], ["Set-Cookie", "foo=bar"],
["Set-Cookie", "bar=baz"], ["Set-Cookie", "bar=baz"],
@ -325,7 +325,7 @@ unitTest(function headersInitMultiple() {
]); ]);
}); });
unitTest(function headersAppendMultiple() { Deno.test(function headersAppendMultiple() {
const headers = new Headers([ const headers = new Headers([
["Set-Cookie", "foo=bar"], ["Set-Cookie", "foo=bar"],
["X-Deno", "foo"], ["X-Deno", "foo"],
@ -340,7 +340,7 @@ unitTest(function headersAppendMultiple() {
]); ]);
}); });
unitTest(function headersAppendDuplicateSetCookieKey() { Deno.test(function headersAppendDuplicateSetCookieKey() {
const headers = new Headers([["Set-Cookie", "foo=bar"]]); const headers = new Headers([["Set-Cookie", "foo=bar"]]);
headers.append("set-Cookie", "foo=baz"); headers.append("set-Cookie", "foo=baz");
headers.append("Set-cookie", "baz=bar"); headers.append("Set-cookie", "baz=bar");
@ -352,7 +352,7 @@ unitTest(function headersAppendDuplicateSetCookieKey() {
]); ]);
}); });
unitTest(function headersGetSetCookie() { Deno.test(function headersGetSetCookie() {
const headers = new Headers([ const headers = new Headers([
["Set-Cookie", "foo=bar"], ["Set-Cookie", "foo=bar"],
["set-Cookie", "bar=qat"], ["set-Cookie", "bar=qat"],
@ -360,7 +360,7 @@ unitTest(function headersGetSetCookie() {
assertEquals(headers.get("SET-COOKIE"), "foo=bar, bar=qat"); assertEquals(headers.get("SET-COOKIE"), "foo=bar, bar=qat");
}); });
unitTest(function toStringShouldBeWebCompatibility() { Deno.test(function toStringShouldBeWebCompatibility() {
const headers = new Headers(); const headers = new Headers();
assertEquals(headers.toString(), "[object Headers]"); assertEquals(headers.toString(), "[object Headers]");
}); });
@ -369,7 +369,7 @@ function stringify(...args: unknown[]): string {
return inspectArgs(args).replace(/\n$/, ""); return inspectArgs(args).replace(/\n$/, "");
} }
unitTest(function customInspectReturnsCorrectHeadersFormat() { Deno.test(function customInspectReturnsCorrectHeadersFormat() {
const blankHeaders = new Headers(); const blankHeaders = new Headers();
assertEquals(stringify(blankHeaders), "Headers {}"); assertEquals(stringify(blankHeaders), "Headers {}");
const singleHeader = new Headers([["Content-Type", "application/json"]]); const singleHeader = new Headers([["Content-Type", "application/json"]]);

View file

@ -12,7 +12,6 @@ import {
deferred, deferred,
delay, delay,
fail, fail,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> { async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
@ -42,7 +41,7 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
return decoder.decode(dest.bytes()); return decoder.decode(dest.bytes());
} }
unitTest({ permissions: { net: true } }, async function httpServerBasic() { Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
const promise = (async () => { const promise = (async () => {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
for await (const conn of listener) { for await (const conn of listener) {
@ -68,7 +67,7 @@ unitTest({ permissions: { net: true } }, async function httpServerBasic() {
await promise; await promise;
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerGetRequestBody() { async function httpServerGetRequestBody() {
const promise = (async () => { const promise = (async () => {
@ -102,7 +101,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerStreamResponse() { async function httpServerStreamResponse() {
const stream = new TransformStream(); const stream = new TransformStream();
@ -131,7 +130,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerStreamRequest() { async function httpServerStreamRequest() {
const stream = new TransformStream(); const stream = new TransformStream();
@ -170,7 +169,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerStreamDuplex() { async function httpServerStreamDuplex() {
const promise = (async () => { const promise = (async () => {
@ -209,7 +208,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function httpServerClose() { Deno.test({ permissions: { net: true } }, async function httpServerClose() {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
const client = await Deno.connect({ port: 4501 }); const client = await Deno.connect({ port: 4501 });
const httpConn = Deno.serveHttp(await listener.accept()); const httpConn = Deno.serveHttp(await listener.accept());
@ -220,7 +219,7 @@ unitTest({ permissions: { net: true } }, async function httpServerClose() {
listener.close(); listener.close();
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerInvalidMethod() { async function httpServerInvalidMethod() {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
@ -240,7 +239,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function httpServerWithTls() { async function httpServerWithTls() {
const hostname = "localhost"; const hostname = "localhost";
@ -281,7 +280,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerRegressionHang() { async function httpServerRegressionHang() {
const promise = (async () => { const promise = (async () => {
@ -308,7 +307,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerCancelBodyOnResponseFailure() { async function httpServerCancelBodyOnResponseFailure() {
const promise = (async () => { const promise = (async () => {
@ -353,7 +352,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerNextRequestErrorExposedInResponse() { async function httpServerNextRequestErrorExposedInResponse() {
const promise = (async () => { const promise = (async () => {
@ -398,7 +397,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerEmptyBlobResponse() { async function httpServerEmptyBlobResponse() {
const promise = (async () => { const promise = (async () => {
@ -420,7 +419,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerNextRequestResolvesOnClose() { async function httpServerNextRequestResolvesOnClose() {
const httpConnList: Deno.HttpConn[] = []; const httpConnList: Deno.HttpConn[] = [];
@ -452,7 +451,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
// Issue: https://github.com/denoland/deno/issues/10870 // Issue: https://github.com/denoland/deno/issues/10870
async function httpServerHang() { async function httpServerHang() {
@ -498,7 +497,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
// Issue: https://github.com/denoland/deno/issues/10930 // Issue: https://github.com/denoland/deno/issues/10930
async function httpServerStreamingResponse() { async function httpServerStreamingResponse() {
@ -588,7 +587,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpRequestLatin1Headers() { async function httpRequestLatin1Headers() {
const promise = (async () => { const promise = (async () => {
@ -634,7 +633,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerRequestWithoutPath() { async function httpServerRequestWithoutPath() {
const promise = (async () => { const promise = (async () => {
@ -679,7 +678,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function httpServerWebSocket() { Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
const promise = (async () => { const promise = (async () => {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
for await (const conn of listener) { for await (const conn of listener) {
@ -709,7 +708,7 @@ unitTest({ permissions: { net: true } }, async function httpServerWebSocket() {
await promise; await promise;
}); });
unitTest(function httpUpgradeWebSocket() { Deno.test(function httpUpgradeWebSocket() {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
headers: { headers: {
connection: "Upgrade", connection: "Upgrade",
@ -727,7 +726,7 @@ unitTest(function httpUpgradeWebSocket() {
); );
}); });
unitTest(function httpUpgradeWebSocketMultipleConnectionOptions() { Deno.test(function httpUpgradeWebSocketMultipleConnectionOptions() {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
headers: { headers: {
connection: "keep-alive, upgrade", connection: "keep-alive, upgrade",
@ -739,7 +738,7 @@ unitTest(function httpUpgradeWebSocketMultipleConnectionOptions() {
assertEquals(response.status, 101); assertEquals(response.status, 101);
}); });
unitTest(function httpUpgradeWebSocketMultipleUpgradeOptions() { Deno.test(function httpUpgradeWebSocketMultipleUpgradeOptions() {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
headers: { headers: {
connection: "upgrade", connection: "upgrade",
@ -751,7 +750,7 @@ unitTest(function httpUpgradeWebSocketMultipleUpgradeOptions() {
assertEquals(response.status, 101); assertEquals(response.status, 101);
}); });
unitTest(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() { Deno.test(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
headers: { headers: {
connection: "upgrade", connection: "upgrade",
@ -763,7 +762,7 @@ unitTest(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() {
assertEquals(response.status, 101); assertEquals(response.status, 101);
}); });
unitTest(function httpUpgradeWebSocketInvalidUpgradeHeader() { Deno.test(function httpUpgradeWebSocketInvalidUpgradeHeader() {
assertThrows( assertThrows(
() => { () => {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
@ -780,7 +779,7 @@ unitTest(function httpUpgradeWebSocketInvalidUpgradeHeader() {
); );
}); });
unitTest(function httpUpgradeWebSocketWithoutUpgradeHeader() { Deno.test(function httpUpgradeWebSocketWithoutUpgradeHeader() {
assertThrows( assertThrows(
() => { () => {
const request = new Request("https://deno.land/", { const request = new Request("https://deno.land/", {
@ -796,7 +795,7 @@ unitTest(function httpUpgradeWebSocketWithoutUpgradeHeader() {
); );
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpCookieConcatenation() { async function httpCookieConcatenation() {
const promise = (async () => { const promise = (async () => {
@ -827,7 +826,7 @@ unitTest(
); );
// https://github.com/denoland/deno/issues/11651 // https://github.com/denoland/deno/issues/11651
unitTest({ permissions: { net: true } }, async function httpServerPanic() { Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
const client = await Deno.connect({ port: 4501 }); const client = await Deno.connect({ port: 4501 });
const conn = await listener.accept(); const conn = await listener.accept();
@ -847,7 +846,7 @@ unitTest({ permissions: { net: true } }, async function httpServerPanic() {
}); });
// https://github.com/denoland/deno/issues/11595 // https://github.com/denoland/deno/issues/11595
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerIncompleteMessage() { async function httpServerIncompleteMessage() {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
@ -906,7 +905,7 @@ unitTest(
); );
// https://github.com/denoland/deno/issues/11743 // https://github.com/denoland/deno/issues/11743
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerDoesntLeakResources() { async function httpServerDoesntLeakResources() {
const listener = Deno.listen({ port: 4505 }); const listener = Deno.listen({ port: 4505 });
@ -930,7 +929,7 @@ unitTest(
); );
// https://github.com/denoland/deno/issues/11926 // https://github.com/denoland/deno/issues/11926
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerDoesntLeakResources2() { async function httpServerDoesntLeakResources2() {
let listener: Deno.Listener; let listener: Deno.Listener;
@ -972,7 +971,7 @@ unitTest(
); );
// https://github.com/denoland/deno/pull/12216 // https://github.com/denoland/deno/pull/12216
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function droppedConnSenderNoPanic() { async function droppedConnSenderNoPanic() {
async function server() { async function server() {
@ -1003,7 +1002,7 @@ unitTest(
); );
// https://github.com/denoland/deno/issues/12193 // https://github.com/denoland/deno/issues/12193
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpConnConcurrentNextRequestCalls() { async function httpConnConcurrentNextRequestCalls() {
const hostname = "localhost"; const hostname = "localhost";
@ -1040,7 +1039,7 @@ unitTest(
// https://github.com/denoland/deno/pull/12704 // https://github.com/denoland/deno/pull/12704
// https://github.com/denoland/deno/pull/12732 // https://github.com/denoland/deno/pull/12732
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpConnAutoCloseDelayedOnUpgrade() { async function httpConnAutoCloseDelayedOnUpgrade() {
const hostname = "localhost"; const hostname = "localhost";
@ -1079,7 +1078,7 @@ unitTest(
// https://github.com/denoland/deno/issues/12741 // https://github.com/denoland/deno/issues/12741
// https://github.com/denoland/deno/pull/12746 // https://github.com/denoland/deno/pull/12746
// https://github.com/denoland/deno/pull/12798 // https://github.com/denoland/deno/pull/12798
unitTest( Deno.test(
{ permissions: { net: true, run: true } }, { permissions: { net: true, run: true } },
async function httpServerDeleteRequestHasBody() { async function httpServerDeleteRequestHasBody() {
const hostname = "localhost"; const hostname = "localhost";
@ -1110,7 +1109,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function httpServerRespondNonAsciiUint8Array() { async function httpServerRespondNonAsciiUint8Array() {
const promise = (async () => { const promise = (async () => {

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function internalsExists() { Deno.test(function internalsExists() {
const { const {
inspectArgs, inspectArgs,
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol

View file

@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
import { Buffer } from "../../../test_util/std/io/buffer.ts"; import { Buffer } from "../../../test_util/std/io/buffer.ts";
const DEFAULT_BUF_SIZE = 32 * 1024; const DEFAULT_BUF_SIZE = 32 * 1024;
@ -28,7 +28,7 @@ function spyRead(obj: Buffer): Spy {
return spy; return spy;
} }
unitTest(async function copyWithDefaultBufferSize() { Deno.test(async function copyWithDefaultBufferSize() {
const xBytes = repeat("b", DEFAULT_BUF_SIZE); const xBytes = repeat("b", DEFAULT_BUF_SIZE);
const reader = new Buffer(xBytes.buffer as ArrayBuffer); const reader = new Buffer(xBytes.buffer as ArrayBuffer);
const write = new Buffer(); const write = new Buffer();
@ -43,7 +43,7 @@ unitTest(async function copyWithDefaultBufferSize() {
assertEquals(readSpy.calls, 2); // read with DEFAULT_BUF_SIZE bytes + read with 0 bytes assertEquals(readSpy.calls, 2); // read with DEFAULT_BUF_SIZE bytes + read with 0 bytes
}); });
unitTest(async function copyWithCustomBufferSize() { Deno.test(async function copyWithCustomBufferSize() {
const bufSize = 1024; const bufSize = 1024;
const xBytes = repeat("b", DEFAULT_BUF_SIZE); const xBytes = repeat("b", DEFAULT_BUF_SIZE);
const reader = new Buffer(xBytes.buffer as ArrayBuffer); const reader = new Buffer(xBytes.buffer as ArrayBuffer);
@ -59,7 +59,7 @@ unitTest(async function copyWithCustomBufferSize() {
assertEquals(readSpy.calls, DEFAULT_BUF_SIZE / bufSize + 1); assertEquals(readSpy.calls, DEFAULT_BUF_SIZE / bufSize + 1);
}); });
unitTest({ permissions: { write: true } }, async function copyBufferToFile() { Deno.test({ permissions: { write: true } }, async function copyBufferToFile() {
const filePath = "test-file.txt"; const filePath = "test-file.txt";
// bigger than max File possible buffer 16kb // bigger than max File possible buffer 16kb
const bufSize = 32 * 1024; const bufSize = 32 * 1024;

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function linkSyncSuccess() { function linkSyncSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -46,7 +45,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function linkSyncExists() { function linkSyncExists() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -66,7 +65,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function linkSyncNotFound() { function linkSyncNotFound() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -83,7 +82,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: false, write: true } }, { permissions: { read: false, write: true } },
function linkSyncReadPerm() { function linkSyncReadPerm() {
assertThrows(() => { assertThrows(() => {
@ -92,7 +91,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
function linkSyncWritePerm() { function linkSyncWritePerm() {
assertThrows(() => { assertThrows(() => {
@ -101,7 +100,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function linkSuccess() { async function linkSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -140,7 +139,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function linkExists() { async function linkExists() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -160,7 +159,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function linkNotFound() { async function linkNotFound() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -177,7 +176,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: false, write: true } }, { permissions: { read: false, write: true } },
async function linkReadPerm() { async function linkReadPerm() {
await assertRejects(async () => { await assertRejects(async () => {
@ -186,7 +185,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
async function linkWritePerm() { async function linkWritePerm() {
await assertRejects(async () => { await assertRejects(async () => {

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { write: true } }, function makeTempDirSyncSuccess() { Deno.test({ permissions: { write: true } }, function makeTempDirSyncSuccess() {
const dir1 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" }); const dir1 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" });
const dir2 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" }); const dir2 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" });
// Check that both dirs are different. // Check that both dirs are different.
@ -28,7 +27,7 @@ unitTest({ permissions: { write: true } }, function makeTempDirSyncSuccess() {
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function makeTempDirSyncMode() { function makeTempDirSyncMode() {
const path = Deno.makeTempDirSync(); const path = Deno.makeTempDirSync();
@ -39,14 +38,14 @@ unitTest(
}, },
); );
unitTest(function makeTempDirSyncPerm() { Deno.test({ permissions: { write: false } }, function makeTempDirSyncPerm() {
// makeTempDirSync should require write permissions (for now). // makeTempDirSync should require write permissions (for now).
assertThrows(() => { assertThrows(() => {
Deno.makeTempDirSync({ dir: "/baddir" }); Deno.makeTempDirSync({ dir: "/baddir" });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { write: true } }, { permissions: { write: true } },
async function makeTempDirSuccess() { async function makeTempDirSuccess() {
const dir1 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" }); const dir1 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" });
@ -70,7 +69,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function makeTempDirMode() { async function makeTempDirMode() {
const path = await Deno.makeTempDir(); const path = await Deno.makeTempDir();
@ -81,7 +80,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, function makeTempFileSyncSuccess() { Deno.test({ permissions: { write: true } }, function makeTempFileSyncSuccess() {
const file1 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" }); const file1 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" });
const file2 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" }); const file2 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" });
// Check that both dirs are different. // Check that both dirs are different.
@ -103,7 +102,7 @@ unitTest({ permissions: { write: true } }, function makeTempFileSyncSuccess() {
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function makeTempFileSyncMode() { function makeTempFileSyncMode() {
const path = Deno.makeTempFileSync(); const path = Deno.makeTempFileSync();
@ -114,14 +113,14 @@ unitTest(
}, },
); );
unitTest(function makeTempFileSyncPerm() { Deno.test({ permissions: { write: false } }, function makeTempFileSyncPerm() {
// makeTempFileSync should require write permissions (for now). // makeTempFileSync should require write permissions (for now).
assertThrows(() => { assertThrows(() => {
Deno.makeTempFileSync({ dir: "/baddir" }); Deno.makeTempFileSync({ dir: "/baddir" });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { write: true } }, { permissions: { write: true } },
async function makeTempFileSuccess() { async function makeTempFileSuccess() {
const file1 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" }); const file1 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" });
@ -146,7 +145,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function makeTempFileMode() { async function makeTempFileMode() {
const path = await Deno.makeTempFile(); const path = await Deno.makeTempFile();

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(async function metrics() { Deno.test(async function metrics() {
// Write to stdout to ensure a "data" message gets sent instead of just // Write to stdout to ensure a "data" message gets sent instead of just
// control messages. // control messages.
const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r", const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r",
@ -39,7 +39,7 @@ unitTest(async function metrics() {
assert(m2OpWrite.bytesReceived === m1OpWrite.bytesReceived); assert(m2OpWrite.bytesReceived === m1OpWrite.bytesReceived);
}); });
unitTest( Deno.test(
{ permissions: { write: true } }, { permissions: { write: true } },
function metricsUpdatedIfNoResponseSync() { function metricsUpdatedIfNoResponseSync() {
const filename = Deno.makeTempDirSync() + "/test.txt"; const filename = Deno.makeTempDirSync() + "/test.txt";
@ -53,7 +53,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true } }, { permissions: { write: true } },
async function metricsUpdatedIfNoResponseAsync() { async function metricsUpdatedIfNoResponseAsync() {
const filename = Deno.makeTempDirSync() + "/test.txt"; const filename = Deno.makeTempDirSync() + "/test.txt";
@ -69,7 +69,7 @@ unitTest(
); );
// Test that ops from extensions have metrics (via OpMiddleware) // Test that ops from extensions have metrics (via OpMiddleware)
unitTest(function metricsForOpCrates() { Deno.test(function metricsForOpCrates() {
const _ = new URL("https://deno.land"); const _ = new URL("https://deno.land");
const m1 = Deno.metrics().ops["op_url_parse"]; const m1 = Deno.metrics().ops["op_url_parse"];

View file

@ -5,7 +5,6 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
function assertDirectory(path: string, mode?: number) { function assertDirectory(path: string, mode?: number) {
@ -16,7 +15,7 @@ function assertDirectory(path: string, mode?: number) {
} }
} }
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncSuccess() { function mkdirSyncSuccess() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -25,7 +24,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncMode() { function mkdirSyncMode() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -34,13 +33,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: false } }, function mkdirSyncPerm() { Deno.test({ permissions: { write: false } }, function mkdirSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.mkdirSync("/baddir"); Deno.mkdirSync("/baddir");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirSuccess() { async function mkdirSuccess() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -49,7 +48,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirMode() { async function mkdirMode() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -58,7 +57,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, function mkdirErrSyncIfExists() { Deno.test({ permissions: { write: true } }, function mkdirErrSyncIfExists() {
assertThrows( assertThrows(
() => { () => {
Deno.mkdirSync("."); Deno.mkdirSync(".");
@ -68,7 +67,7 @@ unitTest({ permissions: { write: true } }, function mkdirErrSyncIfExists() {
); );
}); });
unitTest({ permissions: { write: true } }, async function mkdirErrIfExists() { Deno.test({ permissions: { write: true } }, async function mkdirErrIfExists() {
await assertRejects( await assertRejects(
async () => { async () => {
await Deno.mkdir("."); await Deno.mkdir(".");
@ -78,7 +77,7 @@ unitTest({ permissions: { write: true } }, async function mkdirErrIfExists() {
); );
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncRecursive() { function mkdirSyncRecursive() {
const path = Deno.makeTempDirSync() + "/nested/directory"; const path = Deno.makeTempDirSync() + "/nested/directory";
@ -87,7 +86,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirRecursive() { async function mkdirRecursive() {
const path = Deno.makeTempDirSync() + "/nested/directory"; const path = Deno.makeTempDirSync() + "/nested/directory";
@ -96,7 +95,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncRecursiveMode() { function mkdirSyncRecursiveMode() {
const nested = Deno.makeTempDirSync() + "/nested"; const nested = Deno.makeTempDirSync() + "/nested";
@ -107,7 +106,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirRecursiveMode() { async function mkdirRecursiveMode() {
const nested = Deno.makeTempDirSync() + "/nested"; const nested = Deno.makeTempDirSync() + "/nested";
@ -118,7 +117,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncRecursiveIfExists() { function mkdirSyncRecursiveIfExists() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -136,7 +135,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirRecursiveIfExists() { async function mkdirRecursiveIfExists() {
const path = Deno.makeTempDirSync() + "/dir"; const path = Deno.makeTempDirSync() + "/dir";
@ -154,7 +153,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncErrors() { function mkdirSyncErrors() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -205,7 +204,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function mkdirSyncRelativeUrlPath() { function mkdirSyncRelativeUrlPath() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -220,7 +219,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function mkdirRelativeUrlPath() { async function mkdirRelativeUrlPath() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();

View file

@ -1,6 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function navigatorNumCpus() { Deno.test(function navigatorNumCpus() {
assert(navigator.hardwareConcurrency > 0); assert(navigator.hardwareConcurrency > 0);
}); });

View file

@ -7,7 +7,6 @@ import {
assertThrows, assertThrows,
deferred, deferred,
delay, delay,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
let isCI: boolean; let isCI: boolean;
@ -17,7 +16,7 @@ try {
isCI = true; isCI = true;
} }
unitTest({ permissions: { net: true } }, function netTcpListenClose() { Deno.test({ permissions: { net: true } }, function netTcpListenClose() {
const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 }); const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 });
assert(listener.addr.transport === "tcp"); assert(listener.addr.transport === "tcp");
assertEquals(listener.addr.hostname, "127.0.0.1"); assertEquals(listener.addr.hostname, "127.0.0.1");
@ -26,7 +25,7 @@ unitTest({ permissions: { net: true } }, function netTcpListenClose() {
listener.close(); listener.close();
}); });
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -43,7 +42,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -60,7 +59,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -77,8 +76,11 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: Deno.build.os === "windows", permissions: { read: true } }, {
ignore: Deno.build.os === "windows",
permissions: { read: true, write: false },
},
function netUnixListenWritePermission() { function netUnixListenWritePermission() {
assertThrows(() => { assertThrows(() => {
const filePath = Deno.makeTempFileSync(); const filePath = Deno.makeTempFileSync();
@ -93,8 +95,11 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: Deno.build.os === "windows", permissions: { read: true } }, {
ignore: Deno.build.os === "windows",
permissions: { read: true, write: false },
},
function netUnixPacketListenWritePermission() { function netUnixPacketListenWritePermission() {
assertThrows(() => { assertThrows(() => {
const filePath = Deno.makeTempFileSync(); const filePath = Deno.makeTempFileSync();
@ -109,7 +114,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -127,7 +132,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -147,7 +152,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netTcpConcurrentAccept() { async function netTcpConcurrentAccept() {
const listener = Deno.listen({ port: 4502 }); const listener = Deno.listen({ port: 4502 });
@ -170,7 +175,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -197,7 +202,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, async function netTcpDialListen() { Deno.test({ permissions: { net: true } }, async function netTcpDialListen() {
const listener = Deno.listen({ port: 3500 }); const listener = Deno.listen({ port: 3500 });
listener.accept().then( listener.accept().then(
async (conn) => { async (conn) => {
@ -232,7 +237,7 @@ unitTest({ permissions: { net: true } }, async function netTcpDialListen() {
conn.close(); conn.close();
}); });
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -271,7 +276,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netUdpSendReceive() { async function netUdpSendReceive() {
const alice = Deno.listenDatagram({ port: 3500, transport: "udp" }); const alice = Deno.listenDatagram({ port: 3500, transport: "udp" });
@ -301,7 +306,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netUdpConcurrentSendReceive() { async function netUdpConcurrentSendReceive() {
const socket = Deno.listenDatagram({ port: 3500, transport: "udp" }); const socket = Deno.listenDatagram({ port: 3500, transport: "udp" });
@ -325,7 +330,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netUdpBorrowMutError() { async function netUdpBorrowMutError() {
const socket = Deno.listenDatagram({ const socket = Deno.listenDatagram({
@ -340,7 +345,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -378,7 +383,7 @@ unitTest(
); );
// TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade. // TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade.
unitTest( Deno.test(
{ ignore: true, permissions: { read: true, write: true } }, { ignore: true, permissions: { read: true, write: true } },
async function netUnixPacketConcurrentSendReceive() { async function netUnixPacketConcurrentSendReceive() {
const filePath = await Deno.makeTempFile(); const filePath = await Deno.makeTempFile();
@ -405,7 +410,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netTcpListenIteratorBreakClosesResource() { async function netTcpListenIteratorBreakClosesResource() {
async function iterate(listener: Deno.Listener) { async function iterate(listener: Deno.Listener) {
@ -435,7 +440,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netTcpListenCloseWhileIterating() { async function netTcpListenCloseWhileIterating() {
const listener = Deno.listen({ port: 8001 }); const listener = Deno.listen({ port: 8001 });
@ -448,7 +453,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netUdpListenCloseWhileIterating() { async function netUdpListenCloseWhileIterating() {
const socket = Deno.listenDatagram({ port: 8000, transport: "udp" }); const socket = Deno.listenDatagram({ port: 8000, transport: "udp" });
@ -461,7 +466,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -478,7 +483,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -498,7 +503,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function netListenAsyncIterator() { async function netListenAsyncIterator() {
const addr = { hostname: "127.0.0.1", port: 3500 }; const addr = { hostname: "127.0.0.1", port: 3500 };
@ -529,7 +534,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -562,7 +567,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
// https://github.com/denoland/deno/issues/11580 // https://github.com/denoland/deno/issues/11580
ignore: Deno.build.os === "darwin" && isCI, ignore: Deno.build.os === "darwin" && isCI,
@ -610,7 +615,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { net: true }, permissions: { net: true },
}, },
@ -621,7 +626,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os !== "linux", ignore: Deno.build.os !== "linux",
permissions: { read: true, write: true }, permissions: { read: true, write: true },

View file

@ -1,11 +1,6 @@
import { import { assert, assertStringIncludes, unreachable } from "./test_util.ts";
assert,
assertStringIncludes,
unitTest,
unreachable,
} from "./test_util.ts";
unitTest(async function sendAsyncStackTrace() { Deno.test(async function sendAsyncStackTrace() {
const buf = new Uint8Array(10); const buf = new Uint8Array(10);
const rid = 10; const rid = 10;
try { try {
@ -32,7 +27,7 @@ declare global {
} }
} }
unitTest(async function opsAsyncBadResource() { Deno.test(async function opsAsyncBadResource() {
try { try {
const nonExistingRid = 9999; const nonExistingRid = 9999;
await Deno.core.read( await Deno.core.read(
@ -46,7 +41,7 @@ unitTest(async function opsAsyncBadResource() {
} }
}); });
unitTest(function opsSyncBadResource() { Deno.test(function opsSyncBadResource() {
try { try {
const nonExistingRid = 9999; const nonExistingRid = 9999;
Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0)); Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0));

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertNotEquals, assertNotEquals,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { env: true } }, function envSuccess() { Deno.test({ permissions: { env: true } }, function envSuccess() {
Deno.env.set("TEST_VAR", "A"); Deno.env.set("TEST_VAR", "A");
const env = Deno.env.toObject(); const env = Deno.env.toObject();
Deno.env.set("TEST_VAR", "B"); Deno.env.set("TEST_VAR", "B");
@ -15,19 +14,19 @@ unitTest({ permissions: { env: true } }, function envSuccess() {
assertNotEquals(Deno.env.get("TEST_VAR"), env["TEST_VAR"]); assertNotEquals(Deno.env.get("TEST_VAR"), env["TEST_VAR"]);
}); });
unitTest({ permissions: { env: true } }, function envNotFound() { Deno.test({ permissions: { env: true } }, function envNotFound() {
const r = Deno.env.get("env_var_does_not_exist!"); const r = Deno.env.get("env_var_does_not_exist!");
assertEquals(r, undefined); assertEquals(r, undefined);
}); });
unitTest({ permissions: { env: true } }, function deleteEnv() { Deno.test({ permissions: { env: true } }, function deleteEnv() {
Deno.env.set("TEST_VAR", "A"); Deno.env.set("TEST_VAR", "A");
assertEquals(Deno.env.get("TEST_VAR"), "A"); assertEquals(Deno.env.get("TEST_VAR"), "A");
assertEquals(Deno.env.delete("TEST_VAR"), undefined); assertEquals(Deno.env.delete("TEST_VAR"), undefined);
assertEquals(Deno.env.get("TEST_VAR"), undefined); assertEquals(Deno.env.get("TEST_VAR"), undefined);
}); });
unitTest({ permissions: { env: true } }, function avoidEmptyNamedEnv() { Deno.test({ permissions: { env: true } }, function avoidEmptyNamedEnv() {
assertThrows(() => Deno.env.set("", "v"), TypeError); assertThrows(() => Deno.env.set("", "v"), TypeError);
assertThrows(() => Deno.env.set("a=a", "v"), TypeError); assertThrows(() => Deno.env.set("a=a", "v"), TypeError);
assertThrows(() => Deno.env.set("a\0a", "v"), TypeError); assertThrows(() => Deno.env.set("a\0a", "v"), TypeError);
@ -42,13 +41,13 @@ unitTest({ permissions: { env: true } }, function avoidEmptyNamedEnv() {
assertThrows(() => Deno.env.delete("a\0a"), TypeError); assertThrows(() => Deno.env.delete("a\0a"), TypeError);
}); });
unitTest(function envPermissionDenied1() { Deno.test({ permissions: { env: false } }, function envPermissionDenied1() {
assertThrows(() => { assertThrows(() => {
Deno.env.toObject(); Deno.env.toObject();
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest(function envPermissionDenied2() { Deno.test({ permissions: { env: false } }, function envPermissionDenied2() {
assertThrows(() => { assertThrows(() => {
Deno.env.get("PATH"); Deno.env.get("PATH");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
@ -57,7 +56,7 @@ unitTest(function envPermissionDenied2() {
// This test verifies that on Windows, environment variables are // This test verifies that on Windows, environment variables are
// case-insensitive. Case normalization needs be done using the collation // case-insensitive. Case normalization needs be done using the collation
// that Windows uses, rather than naively using String.toLowerCase(). // that Windows uses, rather than naively using String.toLowerCase().
unitTest( Deno.test(
{ {
ignore: Deno.build.os !== "windows", ignore: Deno.build.os !== "windows",
permissions: { read: true, env: true, run: true }, permissions: { read: true, env: true, run: true },
@ -122,15 +121,15 @@ unitTest(
}, },
); );
unitTest(function osPid() { Deno.test(function osPid() {
assert(Deno.pid > 0); assert(Deno.pid > 0);
}); });
unitTest(function osPpid() { Deno.test(function osPpid() {
assert(Deno.ppid > 0); assert(Deno.ppid > 0);
}); });
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function osPpidIsEqualToPidOfParentProcess() { async function osPpidIsEqualToPidOfParentProcess() {
const decoder = new TextDecoder(); const decoder = new TextDecoder();
@ -148,11 +147,11 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, function execPath() { Deno.test({ permissions: { read: true } }, function execPath() {
assertNotEquals(Deno.execPath(), ""); assertNotEquals(Deno.execPath(), "");
}); });
unitTest({ permissions: { read: false } }, function execPathPerm() { Deno.test({ permissions: { read: false } }, function execPathPerm() {
assertThrows( assertThrows(
() => { () => {
Deno.execPath(); Deno.execPath();
@ -162,38 +161,38 @@ unitTest({ permissions: { read: false } }, function execPathPerm() {
); );
}); });
unitTest({ permissions: { env: true } }, function loadavgSuccess() { Deno.test({ permissions: { env: true } }, function loadavgSuccess() {
const load = Deno.loadavg(); const load = Deno.loadavg();
assertEquals(load.length, 3); assertEquals(load.length, 3);
}); });
unitTest({ permissions: { env: false } }, function loadavgPerm() { Deno.test({ permissions: { env: false } }, function loadavgPerm() {
assertThrows(() => { assertThrows(() => {
Deno.loadavg(); Deno.loadavg();
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { env: true } }, function hostnameDir() { Deno.test({ permissions: { env: true } }, function hostnameDir() {
assertNotEquals(Deno.hostname(), ""); assertNotEquals(Deno.hostname(), "");
}); });
unitTest({ permissions: { env: false } }, function hostnamePerm() { Deno.test({ permissions: { env: false } }, function hostnamePerm() {
assertThrows(() => { assertThrows(() => {
Deno.hostname(); Deno.hostname();
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { env: true } }, function releaseDir() { Deno.test({ permissions: { env: true } }, function releaseDir() {
assertNotEquals(Deno.osRelease(), ""); assertNotEquals(Deno.osRelease(), "");
}); });
unitTest({ permissions: { env: false } }, function releasePerm() { Deno.test({ permissions: { env: false } }, function releasePerm() {
assertThrows(() => { assertThrows(() => {
Deno.osRelease(); Deno.osRelease();
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { env: true } }, function systemMemoryInfo() { Deno.test({ permissions: { env: true } }, function systemMemoryInfo() {
const info = Deno.systemMemoryInfo(); const info = Deno.systemMemoryInfo();
assert(info.total >= 0); assert(info.total >= 0);
assert(info.free >= 0); assert(info.free >= 0);

View file

@ -1,9 +1,9 @@
import { assertEquals, assertThrows, unitTest } from "./test_util.ts"; import { assertEquals, assertThrows } from "./test_util.ts";
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
const { pathFromURL } = Deno[Deno.internal]; const { pathFromURL } = Deno[Deno.internal];
unitTest( Deno.test(
{ ignore: Deno.build.os === "windows" }, { ignore: Deno.build.os === "windows" },
function pathFromURLPosix() { function pathFromURLPosix() {
assertEquals( assertEquals(
@ -15,7 +15,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: Deno.build.os !== "windows" }, { ignore: Deno.build.os !== "windows" },
function pathFromURLWin32() { function pathFromURLWin32() {
assertEquals( assertEquals(

View file

@ -5,10 +5,9 @@ import {
assertStringIncludes, assertStringIncludes,
assertThrows, assertThrows,
deferred, deferred,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { hrtime: false } }, async function performanceNow() { Deno.test({ permissions: { hrtime: false } }, async function performanceNow() {
const resolvable = deferred(); const resolvable = deferred();
const start = performance.now(); const start = performance.now();
let totalTime = 0; let totalTime = 0;
@ -21,7 +20,7 @@ unitTest({ permissions: { hrtime: false } }, async function performanceNow() {
assert(totalTime >= 10); assert(totalTime >= 10);
}); });
unitTest(function performanceMark() { Deno.test(function performanceMark() {
const mark = performance.mark("test"); const mark = performance.mark("test");
assert(mark instanceof PerformanceMark); assert(mark instanceof PerformanceMark);
assertEquals(mark.detail, null); assertEquals(mark.detail, null);
@ -35,7 +34,7 @@ unitTest(function performanceMark() {
assert(markEntries[markEntries.length - 1] === mark); assert(markEntries[markEntries.length - 1] === mark);
}); });
unitTest(function performanceMeasure() { Deno.test(function performanceMeasure() {
const markName1 = "mark1"; const markName1 = "mark1";
const measureName1 = "measure1"; const measureName1 = "measure1";
const measureName2 = "measure2"; const measureName2 = "measure2";
@ -82,7 +81,7 @@ unitTest(function performanceMeasure() {
}); });
}); });
unitTest(function performanceCustomInspectFunction() { Deno.test(function performanceCustomInspectFunction() {
assertStringIncludes(Deno.inspect(performance), "Performance"); assertStringIncludes(Deno.inspect(performance), "Performance");
assertStringIncludes( assertStringIncludes(
Deno.inspect(Performance.prototype), Deno.inspect(Performance.prototype),
@ -90,7 +89,7 @@ unitTest(function performanceCustomInspectFunction() {
); );
}); });
unitTest(function performanceMarkCustomInspectFunction() { Deno.test(function performanceMarkCustomInspectFunction() {
const mark1 = performance.mark("mark1"); const mark1 = performance.mark("mark1");
assertStringIncludes(Deno.inspect(mark1), "PerformanceMark"); assertStringIncludes(Deno.inspect(mark1), "PerformanceMark");
assertStringIncludes( assertStringIncludes(
@ -99,7 +98,7 @@ unitTest(function performanceMarkCustomInspectFunction() {
); );
}); });
unitTest(function performanceMeasureCustomInspectFunction() { Deno.test(function performanceMeasureCustomInspectFunction() {
const measure1 = performance.measure("measure1"); const measure1 = performance.measure("measure1");
assertStringIncludes(Deno.inspect(measure1), "PerformanceMeasure"); assertStringIncludes(Deno.inspect(measure1), "PerformanceMeasure");
assertStringIncludes( assertStringIncludes(
@ -108,17 +107,17 @@ unitTest(function performanceMeasureCustomInspectFunction() {
); );
}); });
unitTest(function performanceIllegalConstructor() { Deno.test(function performanceIllegalConstructor() {
assertThrows(() => new Performance(), TypeError, "Illegal constructor"); assertThrows(() => new Performance(), TypeError, "Illegal constructor");
assertEquals(Performance.length, 0); assertEquals(Performance.length, 0);
}); });
unitTest(function performanceEntryIllegalConstructor() { Deno.test(function performanceEntryIllegalConstructor() {
assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor"); assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor");
assertEquals(PerformanceEntry.length, 0); assertEquals(PerformanceEntry.length, 0);
}); });
unitTest(function performanceMeasureIllegalConstructor() { Deno.test(function performanceMeasureIllegalConstructor() {
assertThrows( assertThrows(
() => new PerformanceMeasure(), () => new PerformanceMeasure(),
TypeError, TypeError,

View file

@ -4,23 +4,22 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest(async function permissionInvalidName() { Deno.test(async function permissionInvalidName() {
await assertRejects(async () => { await assertRejects(async () => {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
await Deno.permissions.query({ name: "foo" as any }); await Deno.permissions.query({ name: "foo" as any });
}, TypeError); }, TypeError);
}); });
unitTest(async function permissionNetInvalidHost() { Deno.test(async function permissionNetInvalidHost() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.permissions.query({ name: "net", host: ":" }); await Deno.permissions.query({ name: "net", host: ":" });
}, URIError); }, URIError);
}); });
unitTest(async function permissionQueryReturnsEventTarget() { Deno.test(async function permissionQueryReturnsEventTarget() {
const status = await Deno.permissions.query({ name: "hrtime" }); const status = await Deno.permissions.query({ name: "hrtime" });
assert(["granted", "denied", "prompt"].includes(status.state)); assert(["granted", "denied", "prompt"].includes(status.state));
let called = false; let called = false;
@ -32,7 +31,7 @@ unitTest(async function permissionQueryReturnsEventTarget() {
assert(status === (await Deno.permissions.query({ name: "hrtime" }))); assert(status === (await Deno.permissions.query({ name: "hrtime" })));
}); });
unitTest(async function permissionQueryForReadReturnsSameStatus() { Deno.test(async function permissionQueryForReadReturnsSameStatus() {
const status1 = await Deno.permissions.query({ const status1 = await Deno.permissions.query({
name: "read", name: "read",
path: ".", path: ".",
@ -44,12 +43,12 @@ unitTest(async function permissionQueryForReadReturnsSameStatus() {
assert(status1 === status2); assert(status1 === status2);
}); });
unitTest(function permissionsIllegalConstructor() { Deno.test(function permissionsIllegalConstructor() {
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor."); assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor.");
assertEquals(Deno.Permissions.length, 0); assertEquals(Deno.Permissions.length, 0);
}); });
unitTest(function permissionStatusIllegalConstructor() { Deno.test(function permissionStatusIllegalConstructor() {
assertThrows( assertThrows(
() => new Deno.PermissionStatus(), () => new Deno.PermissionStatus(),
TypeError, TypeError,
@ -58,7 +57,7 @@ unitTest(function permissionStatusIllegalConstructor() {
assertEquals(Deno.PermissionStatus.length, 0); assertEquals(Deno.PermissionStatus.length, 0);
}); });
unitTest(async function permissionURL() { Deno.test(async function permissionURL() {
await Deno.permissions.query({ await Deno.permissions.query({
name: "read", name: "read",
path: new URL(".", import.meta.url), path: new URL(".", import.meta.url),

View file

@ -4,16 +4,20 @@ import {
assertEquals, assertEquals,
assertStringIncludes, assertStringIncludes,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function runPermissions() { Deno.test(
{ permissions: { read: true, run: false } },
function runPermissions() {
assertThrows(() => { assertThrows(() => {
Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"] }); Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
});
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); },
);
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runSuccess() { async function runSuccess() {
const p = Deno.run({ const p = Deno.run({
@ -30,7 +34,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runUrl() { async function runUrl() {
const p = Deno.run({ const p = Deno.run({
@ -51,7 +55,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runStdinRid0(): Promise< async function runStdinRid0(): Promise<
void void
@ -71,7 +75,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
function runInvalidStdio() { function runInvalidStdio() {
assertThrows(() => assertThrows(() =>
@ -98,7 +102,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runCommandFailedWithCode() { async function runCommandFailedWithCode() {
const p = Deno.run({ const p = Deno.run({
@ -112,7 +116,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, read: true }, permissions: { run: true, read: true },
}, },
@ -137,7 +141,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { run: true } }, function runNotFound() { Deno.test({ permissions: { run: true } }, function runNotFound() {
let error; let error;
try { try {
Deno.run({ cmd: ["this file hopefully doesn't exist"] }); Deno.run({ cmd: ["this file hopefully doesn't exist"] });
@ -148,7 +152,7 @@ unitTest({ permissions: { run: true } }, function runNotFound() {
assert(error instanceof Deno.errors.NotFound); assert(error instanceof Deno.errors.NotFound);
}); });
unitTest( Deno.test(
{ permissions: { write: true, run: true, read: true } }, { permissions: { write: true, run: true, read: true } },
async function runWithCwdIsAsync() { async function runWithCwdIsAsync() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -189,7 +193,7 @@ tryExit();
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runStdinPiped(): Promise< async function runStdinPiped(): Promise<
void void
@ -220,7 +224,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runStdoutPiped(): Promise< async function runStdoutPiped(): Promise<
void void
@ -256,7 +260,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runStderrPiped(): Promise< async function runStderrPiped(): Promise<
void void
@ -292,7 +296,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runOutput() { async function runOutput() {
const p = Deno.run({ const p = Deno.run({
@ -310,7 +314,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runStderrOutput(): Promise< async function runStderrOutput(): Promise<
void void
@ -330,7 +334,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, write: true, read: true } }, { permissions: { run: true, write: true, read: true } },
async function runRedirectStdoutStderr() { async function runRedirectStdoutStderr() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -363,7 +367,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, write: true, read: true } }, { permissions: { run: true, write: true, read: true } },
async function runRedirectStdin() { async function runRedirectStdin() {
const tempDir = await Deno.makeTempDir(); const tempDir = await Deno.makeTempDir();
@ -388,7 +392,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runEnv() { async function runEnv() {
const p = Deno.run({ const p = Deno.run({
@ -410,7 +414,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runClose() { async function runClose() {
const p = Deno.run({ const p = Deno.run({
@ -433,7 +437,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runKillAfterStatus() { async function runKillAfterStatus() {
const p = Deno.run({ const p = Deno.run({
@ -461,7 +465,7 @@ unitTest(
}, },
); );
unitTest(function killPermissions() { Deno.test({ permissions: { run: false } }, function killPermissions() {
assertThrows(() => { assertThrows(() => {
// Unlike the other test cases, we don't have permission to spawn a // Unlike the other test cases, we don't have permission to spawn a
// subprocess we can safely kill. Instead we send SIGCONT to the current // subprocess we can safely kill. Instead we send SIGCONT to the current
@ -471,7 +475,7 @@ unitTest(function killPermissions() {
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ ignore: Deno.build.os !== "windows", permissions: { run: true } }, { ignore: Deno.build.os !== "windows", permissions: { run: true } },
function negativePidInvalidWindows() { function negativePidInvalidWindows() {
assertThrows(() => { assertThrows(() => {
@ -480,7 +484,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ ignore: Deno.build.os !== "windows", permissions: { run: true } }, { ignore: Deno.build.os !== "windows", permissions: { run: true } },
function invalidSignalNameWindows() { function invalidSignalNameWindows() {
assertThrows(() => { assertThrows(() => {
@ -489,7 +493,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function killSuccess() { async function killSuccess() {
const p = Deno.run({ const p = Deno.run({
@ -514,7 +518,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { run: true, read: true } }, function killFailed() { Deno.test({ permissions: { run: true, read: true } }, function killFailed() {
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"],
}); });
@ -529,7 +533,7 @@ unitTest({ permissions: { run: true, read: true } }, function killFailed() {
p.close(); p.close();
}); });
unitTest( Deno.test(
{ permissions: { run: true, read: true, env: true } }, { permissions: { run: true, read: true, env: true } },
async function clearEnv(): Promise<void> { async function clearEnv(): Promise<void> {
const p = Deno.run({ const p = Deno.run({
@ -557,7 +561,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, read: true }, permissions: { run: true, read: true },
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
@ -588,7 +592,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { run: true, read: true }, permissions: { run: true, read: true },
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(function progressEventConstruct() { Deno.test(function progressEventConstruct() {
const progressEventDefs = new ProgressEvent("progressEventType", {}); const progressEventDefs = new ProgressEvent("progressEventType", {});
assertEquals(progressEventDefs.lengthComputable, false); assertEquals(progressEventDefs.lengthComputable, false);
assertEquals(progressEventDefs.loaded, 0); assertEquals(progressEventDefs.loaded, 0);

View file

@ -5,7 +5,6 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
function assertSameContent(files: Deno.DirEntry[]) { function assertSameContent(files: Deno.DirEntry[]) {
@ -21,25 +20,25 @@ function assertSameContent(files: Deno.DirEntry[]) {
assertEquals(counter, 1); assertEquals(counter, 1);
} }
unitTest({ permissions: { read: true } }, function readDirSyncSuccess() { Deno.test({ permissions: { read: true } }, function readDirSyncSuccess() {
const files = [...Deno.readDirSync("cli/tests/testdata")]; const files = [...Deno.readDirSync("cli/tests/testdata")];
assertSameContent(files); assertSameContent(files);
}); });
unitTest({ permissions: { read: true } }, function readDirSyncWithUrl() { Deno.test({ permissions: { read: true } }, function readDirSyncWithUrl() {
const files = [ const files = [
...Deno.readDirSync(pathToAbsoluteFileUrl("cli/tests/testdata")), ...Deno.readDirSync(pathToAbsoluteFileUrl("cli/tests/testdata")),
]; ];
assertSameContent(files); assertSameContent(files);
}); });
unitTest({ permissions: { read: false } }, function readDirSyncPerm() { Deno.test({ permissions: { read: false } }, function readDirSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.readDirSync("tests/"); Deno.readDirSync("tests/");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readDirSyncNotDir() { Deno.test({ permissions: { read: true } }, function readDirSyncNotDir() {
assertThrows( assertThrows(
() => { () => {
Deno.readDirSync("cli/tests/testdata/fixture.json"); Deno.readDirSync("cli/tests/testdata/fixture.json");
@ -49,7 +48,7 @@ unitTest({ permissions: { read: true } }, function readDirSyncNotDir() {
); );
}); });
unitTest({ permissions: { read: true } }, function readDirSyncNotFound() { Deno.test({ permissions: { read: true } }, function readDirSyncNotFound() {
assertThrows( assertThrows(
() => { () => {
Deno.readDirSync("bad_dir_name"); Deno.readDirSync("bad_dir_name");
@ -59,7 +58,7 @@ unitTest({ permissions: { read: true } }, function readDirSyncNotFound() {
); );
}); });
unitTest({ permissions: { read: true } }, async function readDirSuccess() { Deno.test({ permissions: { read: true } }, async function readDirSuccess() {
const files = []; const files = [];
for await (const dirEntry of Deno.readDir("cli/tests/testdata")) { for await (const dirEntry of Deno.readDir("cli/tests/testdata")) {
files.push(dirEntry); files.push(dirEntry);
@ -67,7 +66,7 @@ unitTest({ permissions: { read: true } }, async function readDirSuccess() {
assertSameContent(files); assertSameContent(files);
}); });
unitTest({ permissions: { read: true } }, async function readDirWithUrl() { Deno.test({ permissions: { read: true } }, async function readDirWithUrl() {
const files = []; const files = [];
for await ( for await (
const dirEntry of Deno.readDir(pathToAbsoluteFileUrl("cli/tests/testdata")) const dirEntry of Deno.readDir(pathToAbsoluteFileUrl("cli/tests/testdata"))
@ -77,13 +76,13 @@ unitTest({ permissions: { read: true } }, async function readDirWithUrl() {
assertSameContent(files); assertSameContent(files);
}); });
unitTest({ permissions: { read: false } }, async function readDirPerm() { Deno.test({ permissions: { read: false } }, async function readDirPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); await Deno.readDir("tests/")[Symbol.asyncIterator]().next();
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true }, ignore: Deno.build.os == "windows" }, { permissions: { read: true }, ignore: Deno.build.os == "windows" },
async function readDirDevFd(): Promise< async function readDirDevFd(): Promise<
void void
@ -94,7 +93,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true }, ignore: Deno.build.os == "windows" }, { permissions: { read: true }, ignore: Deno.build.os == "windows" },
function readDirDevFdSync() { function readDirDevFdSync() {
for (const _ of Deno.readDirSync("/dev/fd")) { for (const _ of Deno.readDirSync("/dev/fd")) {
@ -103,7 +102,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, async function readDirNotFound() { Deno.test({ permissions: { read: true } }, async function readDirNotFound() {
await assertRejects( await assertRejects(
async () => { async () => {
await Deno.readDir("bad_dir_name")[Symbol.asyncIterator]().next(); await Deno.readDir("bad_dir_name")[Symbol.asyncIterator]().next();

View file

@ -6,10 +6,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function readFileSyncSuccess() { Deno.test({ permissions: { read: true } }, function readFileSyncSuccess() {
const data = Deno.readFileSync("cli/tests/testdata/fixture.json"); const data = Deno.readFileSync("cli/tests/testdata/fixture.json");
assert(data.byteLength > 0); assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8"); const decoder = new TextDecoder("utf-8");
@ -18,7 +17,7 @@ unitTest({ permissions: { read: true } }, function readFileSyncSuccess() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: true } }, function readFileSyncUrl() { Deno.test({ permissions: { read: true } }, function readFileSyncUrl() {
const data = Deno.readFileSync( const data = Deno.readFileSync(
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
); );
@ -29,19 +28,19 @@ unitTest({ permissions: { read: true } }, function readFileSyncUrl() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: false } }, function readFileSyncPerm() { Deno.test({ permissions: { read: false } }, function readFileSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.readFileSync("cli/tests/testdata/fixture.json"); Deno.readFileSync("cli/tests/testdata/fixture.json");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readFileSyncNotFound() { Deno.test({ permissions: { read: true } }, function readFileSyncNotFound() {
assertThrows(() => { assertThrows(() => {
Deno.readFileSync("bad_filename"); Deno.readFileSync("bad_filename");
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest({ permissions: { read: true } }, async function readFileUrl() { Deno.test({ permissions: { read: true } }, async function readFileUrl() {
const data = await Deno.readFile( const data = await Deno.readFile(
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
); );
@ -52,7 +51,7 @@ unitTest({ permissions: { read: true } }, async function readFileUrl() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: true } }, async function readFileSuccess() { Deno.test({ permissions: { read: true } }, async function readFileSuccess() {
const data = await Deno.readFile("cli/tests/testdata/fixture.json"); const data = await Deno.readFile("cli/tests/testdata/fixture.json");
assert(data.byteLength > 0); assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8"); const decoder = new TextDecoder("utf-8");
@ -61,19 +60,19 @@ unitTest({ permissions: { read: true } }, async function readFileSuccess() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: false } }, async function readFilePerm() { Deno.test({ permissions: { read: false } }, async function readFilePerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.readFile("cli/tests/testdata/fixture.json"); await Deno.readFile("cli/tests/testdata/fixture.json");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readFileSyncLoop() { Deno.test({ permissions: { read: true } }, function readFileSyncLoop() {
for (let i = 0; i < 256; i++) { for (let i = 0; i < 256; i++) {
Deno.readFileSync("cli/tests/testdata/fixture.json"); Deno.readFileSync("cli/tests/testdata/fixture.json");
} }
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function readFileDoesNotLeakResources() { async function readFileDoesNotLeakResources() {
const resourcesBefore = Deno.resources(); const resourcesBefore = Deno.resources();
@ -82,7 +81,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
function readFileSyncDoesNotLeakResources() { function readFileSyncDoesNotLeakResources() {
const resourcesBefore = Deno.resources(); const resourcesBefore = Deno.resources();
@ -91,7 +90,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function readFileWithAbortSignal() { async function readFileWithAbortSignal() {
const ac = new AbortController(); const ac = new AbortController();
@ -104,7 +103,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" }, { permissions: { read: true }, ignore: Deno.build.os !== "linux" },
async function readFileProcFs() { async function readFileProcFs() {
const data = await Deno.readFile("/proc/self/stat"); const data = await Deno.readFile("/proc/self/stat");
@ -112,7 +111,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function readFileExtendedDuringRead() { async function readFileExtendedDuringRead() {
// Write 128MB file // Write 128MB file
@ -131,7 +130,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function readFile0LengthExtendedDuringRead() { async function readFile0LengthExtendedDuringRead() {
// Write 0 byte file // Write 0 byte file

View file

@ -4,10 +4,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
function readLinkSyncSuccess() { function readLinkSyncSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -22,7 +21,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
function readLinkSyncUrlSuccess() { function readLinkSyncUrlSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -37,13 +36,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, function readLinkSyncPerm() { Deno.test({ permissions: { read: false } }, function readLinkSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.readLinkSync("/symlink"); Deno.readLinkSync("/symlink");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readLinkSyncNotFound() { Deno.test({ permissions: { read: true } }, function readLinkSyncNotFound() {
assertThrows( assertThrows(
() => { () => {
Deno.readLinkSync("bad_filename"); Deno.readLinkSync("bad_filename");
@ -53,7 +52,7 @@ unitTest({ permissions: { read: true } }, function readLinkSyncNotFound() {
); );
}); });
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function readLinkSuccess() { async function readLinkSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -68,7 +67,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function readLinkUrlSuccess() { async function readLinkUrlSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -83,13 +82,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, async function readLinkPerm() { Deno.test({ permissions: { read: false } }, async function readLinkPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.readLink("/symlink"); await Deno.readLink("/symlink");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, async function readLinkNotFound() { Deno.test({ permissions: { read: true } }, async function readLinkNotFound() {
await assertRejects( await assertRejects(
async () => { async () => {
await Deno.readLink("bad_filename"); await Deno.readLink("bad_filename");

View file

@ -4,17 +4,16 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function readTextFileSyncSuccess() { Deno.test({ permissions: { read: true } }, function readTextFileSyncSuccess() {
const data = Deno.readTextFileSync("cli/tests/testdata/fixture.json"); const data = Deno.readTextFileSync("cli/tests/testdata/fixture.json");
assert(data.length > 0); assert(data.length > 0);
const pkg = JSON.parse(data); const pkg = JSON.parse(data);
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: true } }, function readTextFileSyncByUrl() { Deno.test({ permissions: { read: true } }, function readTextFileSyncByUrl() {
const data = Deno.readTextFileSync( const data = Deno.readTextFileSync(
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
); );
@ -23,19 +22,19 @@ unitTest({ permissions: { read: true } }, function readTextFileSyncByUrl() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: false } }, function readTextFileSyncPerm() { Deno.test({ permissions: { read: false } }, function readTextFileSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.readTextFileSync("cli/tests/testdata/fixture.json"); Deno.readTextFileSync("cli/tests/testdata/fixture.json");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readTextFileSyncNotFound() { Deno.test({ permissions: { read: true } }, function readTextFileSyncNotFound() {
assertThrows(() => { assertThrows(() => {
Deno.readTextFileSync("bad_filename"); Deno.readTextFileSync("bad_filename");
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function readTextFileSuccess() { async function readTextFileSuccess() {
const data = await Deno.readTextFile("cli/tests/testdata/fixture.json"); const data = await Deno.readTextFile("cli/tests/testdata/fixture.json");
@ -45,7 +44,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: true } }, async function readTextFileByUrl() { Deno.test({ permissions: { read: true } }, async function readTextFileByUrl() {
const data = await Deno.readTextFile( const data = await Deno.readTextFile(
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
); );
@ -54,19 +53,19 @@ unitTest({ permissions: { read: true } }, async function readTextFileByUrl() {
assertEquals(pkg.name, "deno"); assertEquals(pkg.name, "deno");
}); });
unitTest({ permissions: { read: false } }, async function readTextFilePerm() { Deno.test({ permissions: { read: false } }, async function readTextFilePerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.readTextFile("cli/tests/testdata/fixture.json"); await Deno.readTextFile("cli/tests/testdata/fixture.json");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function readTextFileSyncLoop() { Deno.test({ permissions: { read: true } }, function readTextFileSyncLoop() {
for (let i = 0; i < 256; i++) { for (let i = 0; i < 256; i++) {
Deno.readTextFileSync("cli/tests/testdata/fixture.json"); Deno.readTextFileSync("cli/tests/testdata/fixture.json");
} }
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function readTextFileDoesNotLeakResources() { async function readTextFileDoesNotLeakResources() {
const resourcesBefore = Deno.resources(); const resourcesBefore = Deno.resources();
@ -75,7 +74,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
function readTextFileSyncDoesNotLeakResources() { function readTextFileSyncDoesNotLeakResources() {
const resourcesBefore = Deno.resources(); const resourcesBefore = Deno.resources();
@ -84,7 +83,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function readTextFileWithAbortSignal() { async function readTextFileWithAbortSignal() {
const ac = new AbortController(); const ac = new AbortController();
@ -97,7 +96,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" }, { permissions: { read: true }, ignore: Deno.build.os !== "linux" },
async function readTextFileProcFs() { async function readTextFileProcFs() {
const data = await Deno.readTextFile("/proc/self/stat"); const data = await Deno.readTextFile("/proc/self/stat");

View file

@ -6,10 +6,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function realPathSyncSuccess() { Deno.test({ permissions: { read: true } }, function realPathSyncSuccess() {
const relative = "cli/tests/testdata/fixture.json"; const relative = "cli/tests/testdata/fixture.json";
const realPath = Deno.realPathSync(relative); const realPath = Deno.realPathSync(relative);
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -21,13 +20,13 @@ unitTest({ permissions: { read: true } }, function realPathSyncSuccess() {
} }
}); });
unitTest({ permissions: { read: true } }, function realPathSyncUrl() { Deno.test({ permissions: { read: true } }, function realPathSyncUrl() {
const relative = "cli/tests/testdata/fixture.json"; const relative = "cli/tests/testdata/fixture.json";
const url = pathToAbsoluteFileUrl(relative); const url = pathToAbsoluteFileUrl(relative);
assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url)); assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url));
}); });
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -48,19 +47,19 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, function realPathSyncPerm() { Deno.test({ permissions: { read: false } }, function realPathSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.realPathSync("some_file"); Deno.realPathSync("some_file");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function realPathSyncNotFound() { Deno.test({ permissions: { read: true } }, function realPathSyncNotFound() {
assertThrows(() => { assertThrows(() => {
Deno.realPathSync("bad_filename"); Deno.realPathSync("bad_filename");
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest({ permissions: { read: true } }, async function realPathSuccess() { Deno.test({ permissions: { read: true } }, async function realPathSuccess() {
const relativePath = "cli/tests/testdata/fixture.json"; const relativePath = "cli/tests/testdata/fixture.json";
const realPath = await Deno.realPath(relativePath); const realPath = await Deno.realPath(relativePath);
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -72,7 +71,7 @@ unitTest({ permissions: { read: true } }, async function realPathSuccess() {
} }
}); });
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
async function realPathUrl() { async function realPathUrl() {
const relative = "cli/tests/testdata/fixture.json"; const relative = "cli/tests/testdata/fixture.json";
@ -81,7 +80,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
permissions: { read: true, write: true }, permissions: { read: true, write: true },
}, },
@ -102,13 +101,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, async function realPathPerm() { Deno.test({ permissions: { read: false } }, async function realPathPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.realPath("some_file"); await Deno.realPath("some_file");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, async function realPathNotFound() { Deno.test({ permissions: { read: true } }, async function realPathNotFound() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.realPath("bad_filename"); await Deno.realPath("bad_filename");
}, Deno.errors.NotFound); }, Deno.errors.NotFound);

View file

@ -1,9 +1,9 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertRejects, assertThrows, unitTest } from "./test_util.ts"; import { assert, assertRejects, assertThrows } from "./test_util.ts";
const REMOVE_METHODS = ["remove", "removeSync"] as const; const REMOVE_METHODS = ["remove", "removeSync"] as const;
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeDirSuccess() { async function removeDirSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -21,7 +21,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeFileSuccess() { async function removeFileSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -41,7 +41,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeFileByUrl() { async function removeFileByUrl() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -66,7 +66,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeFail() { async function removeFail() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -101,7 +101,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeDanglingSymlinkSuccess() { async function removeDanglingSymlinkSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -123,7 +123,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeValidSymlinkSuccess() { async function removeValidSymlinkSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -149,7 +149,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: false } }, async function removePerm() { Deno.test({ permissions: { write: false } }, async function removePerm() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
await assertRejects(async () => { await assertRejects(async () => {
await Deno[method]("/baddir"); await Deno[method]("/baddir");
@ -157,7 +157,7 @@ unitTest({ permissions: { write: false } }, async function removePerm() {
} }
}); });
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeAllDirSuccess() { async function removeAllDirSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -194,7 +194,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: true, read: true } }, { permissions: { write: true, read: true } },
async function removeAllFileSuccess() { async function removeAllFileSuccess() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
@ -215,7 +215,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, async function removeAllFail() { Deno.test({ permissions: { write: true } }, async function removeAllFail() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
// NON-EXISTENT DIRECTORY/FILE // NON-EXISTENT DIRECTORY/FILE
await assertRejects( await assertRejects(
@ -229,7 +229,7 @@ unitTest({ permissions: { write: true } }, async function removeAllFail() {
} }
}); });
unitTest({ permissions: { write: false } }, async function removeAllPerm() { Deno.test({ permissions: { write: false } }, async function removeAllPerm() {
for (const method of REMOVE_METHODS) { for (const method of REMOVE_METHODS) {
await assertRejects(async () => { await assertRejects(async () => {
await Deno[method]("/baddir", { recursive: true }); await Deno[method]("/baddir", { recursive: true });
@ -237,7 +237,7 @@ unitTest({ permissions: { write: false } }, async function removeAllPerm() {
} }
}); });
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { write: true, read: true }, permissions: { write: true, read: true },
@ -259,7 +259,7 @@ unitTest(
); );
if (Deno.build.os === "windows") { if (Deno.build.os === "windows") {
unitTest( Deno.test(
{ permissions: { run: true, write: true, read: true } }, { permissions: { run: true, write: true, read: true } },
async function removeFileSymlink() { async function removeFileSymlink() {
const symlink = Deno.run({ const symlink = Deno.run({
@ -276,7 +276,7 @@ if (Deno.build.os === "windows") {
}, },
); );
unitTest( Deno.test(
{ permissions: { run: true, write: true, read: true } }, { permissions: { run: true, write: true, read: true } },
async function removeDirSymlink() { async function removeDirSymlink() {
const symlink = Deno.run({ const symlink = Deno.run({

View file

@ -4,7 +4,6 @@ import {
assertEquals, assertEquals,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
function assertMissing(path: string) { function assertMissing(path: string) {
@ -33,7 +32,7 @@ function assertDirectory(path: string, mode?: number) {
} }
} }
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function renameSyncSuccess() { function renameSyncSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -46,7 +45,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function renameSyncWithURL() { function renameSyncWithURL() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -62,7 +61,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: false, write: true } }, { permissions: { read: false, write: true } },
function renameSyncReadPerm() { function renameSyncReadPerm() {
assertThrows(() => { assertThrows(() => {
@ -73,7 +72,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
function renameSyncWritePerm() { function renameSyncWritePerm() {
assertThrows(() => { assertThrows(() => {
@ -84,7 +83,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function renameSuccess() { async function renameSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -97,7 +96,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function renameWithURL() { async function renameWithURL() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -125,7 +124,7 @@ function writeFileString(filename: string, s: string) {
Deno.writeFileSync(filename, data, { mode: 0o666 }); Deno.writeFileSync(filename, data, { mode: 0o666 });
} }
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -210,7 +209,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os !== "windows", ignore: Deno.build.os !== "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts"; import { assertEquals, assertStringIncludes } from "./test_util.ts";
unitTest(async function fromInit() { Deno.test(async function fromInit() {
const req = new Request("http://foo/", { const req = new Request("http://foo/", {
body: "ahoyhoy", body: "ahoyhoy",
method: "POST", method: "POST",
@ -15,7 +15,7 @@ unitTest(async function fromInit() {
assertEquals(req.headers.get("test-header"), "value"); assertEquals(req.headers.get("test-header"), "value");
}); });
unitTest(function requestNonString() { Deno.test(function requestNonString() {
const nonString = { const nonString = {
toString() { toString() {
return "http://foo/"; return "http://foo/";
@ -26,18 +26,18 @@ unitTest(function requestNonString() {
assertEquals(new Request(nonString).url, "http://foo/"); assertEquals(new Request(nonString).url, "http://foo/");
}); });
unitTest(function methodNonString() { Deno.test(function methodNonString() {
assertEquals(new Request("http://foo/", { method: undefined }).method, "GET"); assertEquals(new Request("http://foo/", { method: undefined }).method, "GET");
}); });
unitTest(function requestRelativeUrl() { Deno.test(function requestRelativeUrl() {
assertEquals( assertEquals(
new Request("relative-url").url, new Request("relative-url").url,
"http://js-unit-tests/foo/relative-url", "http://js-unit-tests/foo/relative-url",
); );
}); });
unitTest(async function cloneRequestBodyStream() { Deno.test(async function cloneRequestBodyStream() {
// hack to get a stream // hack to get a stream
const stream = const stream =
new Request("http://foo/", { body: "a test body", method: "POST" }).body; new Request("http://foo/", { body: "a test body", method: "POST" }).body;
@ -54,7 +54,7 @@ unitTest(async function cloneRequestBodyStream() {
assertEquals(b1, b2); assertEquals(b1, b2);
}); });
unitTest(function customInspectFunction() { Deno.test(function customInspectFunction() {
const request = new Request("https://example.com"); const request = new Request("https://example.com");
assertEquals( assertEquals(
Deno.inspect(request), Deno.inspect(request),

View file

@ -1,13 +1,13 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertThrows } from "./test_util.ts";
unitTest(function resourcesCloseBadArgs() { Deno.test(function resourcesCloseBadArgs() {
assertThrows(() => { assertThrows(() => {
Deno.close((null as unknown) as number); Deno.close((null as unknown) as number);
}, TypeError); }, TypeError);
}); });
unitTest(function resourcesStdio() { Deno.test(function resourcesStdio() {
const res = Deno.resources(); const res = Deno.resources();
assertEquals(res[0], "stdin"); assertEquals(res[0], "stdin");
@ -15,7 +15,7 @@ unitTest(function resourcesStdio() {
assertEquals(res[2], "stderr"); assertEquals(res[2], "stderr");
}); });
unitTest({ permissions: { net: true } }, async function resourcesNet() { Deno.test({ permissions: { net: true } }, async function resourcesNet() {
const listener = Deno.listen({ port: 4501 }); const listener = Deno.listen({ port: 4501 });
const dialerConn = await Deno.connect({ port: 4501 }); const dialerConn = await Deno.connect({ port: 4501 });
const listenerConn = await listener.accept(); const listenerConn = await listener.accept();
@ -35,7 +35,7 @@ unitTest({ permissions: { net: true } }, async function resourcesNet() {
listener.close(); listener.close();
}); });
unitTest({ permissions: { read: true } }, async function resourcesFile() { Deno.test({ permissions: { read: true } }, async function resourcesFile() {
const resourcesBefore = Deno.resources(); const resourcesBefore = Deno.resources();
const f = await Deno.open("cli/tests/testdata/hello.txt"); const f = await Deno.open("cli/tests/testdata/hello.txt");
const resourcesAfter = Deno.resources(); const resourcesAfter = Deno.resources();

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertStringIncludes, assertStringIncludes,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest(async function responseText() { Deno.test(async function responseText() {
const response = new Response("hello world"); const response = new Response("hello world");
const textPromise = response.text(); const textPromise = response.text();
assert(textPromise instanceof Promise); assert(textPromise instanceof Promise);
@ -16,7 +15,7 @@ unitTest(async function responseText() {
assertEquals(text, "hello world"); assertEquals(text, "hello world");
}); });
unitTest(async function responseArrayBuffer() { Deno.test(async function responseArrayBuffer() {
const response = new Response(new Uint8Array([1, 2, 3])); const response = new Response(new Uint8Array([1, 2, 3]));
const arrayBufferPromise = response.arrayBuffer(); const arrayBufferPromise = response.arrayBuffer();
assert(arrayBufferPromise instanceof Promise); assert(arrayBufferPromise instanceof Promise);
@ -25,7 +24,7 @@ unitTest(async function responseArrayBuffer() {
assertEquals(new Uint8Array(arrayBuffer), new Uint8Array([1, 2, 3])); assertEquals(new Uint8Array(arrayBuffer), new Uint8Array([1, 2, 3]));
}); });
unitTest(async function responseJson() { Deno.test(async function responseJson() {
const response = new Response('{"hello": "world"}'); const response = new Response('{"hello": "world"}');
const jsonPromise = response.json(); const jsonPromise = response.json();
assert(jsonPromise instanceof Promise); assert(jsonPromise instanceof Promise);
@ -34,7 +33,7 @@ unitTest(async function responseJson() {
assertEquals(json, { hello: "world" }); assertEquals(json, { hello: "world" });
}); });
unitTest(async function responseBlob() { Deno.test(async function responseBlob() {
const response = new Response(new Uint8Array([1, 2, 3])); const response = new Response(new Uint8Array([1, 2, 3]));
const blobPromise = response.blob(); const blobPromise = response.blob();
assert(blobPromise instanceof Promise); assert(blobPromise instanceof Promise);
@ -44,7 +43,7 @@ unitTest(async function responseBlob() {
assertEquals(await blob.arrayBuffer(), new Uint8Array([1, 2, 3]).buffer); assertEquals(await blob.arrayBuffer(), new Uint8Array([1, 2, 3]).buffer);
}); });
unitTest(async function responseFormData() { Deno.test(async function responseFormData() {
const input = new FormData(); const input = new FormData();
input.append("hello", "world"); input.append("hello", "world");
const response = new Response(input); const response = new Response(input);
@ -57,7 +56,7 @@ unitTest(async function responseFormData() {
assertEquals([...formData], [...input]); assertEquals([...formData], [...input]);
}); });
unitTest(function responseInvalidInit() { Deno.test(function responseInvalidInit() {
// deno-lint-ignore ban-ts-comment // deno-lint-ignore ban-ts-comment
// @ts-expect-error // @ts-expect-error
assertThrows(() => new Response("", 0)); assertThrows(() => new Response("", 0));
@ -67,14 +66,14 @@ unitTest(function responseInvalidInit() {
assertThrows(() => new Response("", { status: null })); assertThrows(() => new Response("", { status: null }));
}); });
unitTest(function responseNullInit() { Deno.test(function responseNullInit() {
// deno-lint-ignore ban-ts-comment // deno-lint-ignore ban-ts-comment
// @ts-expect-error // @ts-expect-error
const response = new Response("", null); const response = new Response("", null);
assertEquals(response.status, 200); assertEquals(response.status, 200);
}); });
unitTest(function customInspectFunction() { Deno.test(function customInspectFunction() {
const response = new Response(); const response = new Response();
assertEquals( assertEquals(
Deno.inspect(response), Deno.inspect(response),

View file

@ -1,13 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assertEquals, assertThrows, deferred, delay } from "./test_util.ts";
assertEquals,
assertThrows,
deferred,
delay,
unitTest,
} from "./test_util.ts";
unitTest( Deno.test(
{ ignore: Deno.build.os !== "windows" }, { ignore: Deno.build.os !== "windows" },
function signalsNotImplemented() { function signalsNotImplemented() {
assertThrows( assertThrows(
@ -97,7 +91,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { run: true }, permissions: { run: true },
@ -125,7 +119,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { run: true }, permissions: { run: true },
@ -173,7 +167,7 @@ unitTest(
); );
// This tests that pending op_signal_poll doesn't block the runtime from exiting the process. // This tests that pending op_signal_poll doesn't block the runtime from exiting the process.
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { run: true, read: true }, permissions: { run: true, read: true },
@ -193,7 +187,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { run: true }, permissions: { run: true },

View file

@ -5,10 +5,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest({ permissions: { read: true } }, function fstatSyncSuccess() { Deno.test({ permissions: { read: true } }, function fstatSyncSuccess() {
const file = Deno.openSync("README.md"); const file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid); const fileInfo = Deno.fstatSync(file.rid);
assert(fileInfo.isFile); assert(fileInfo.isFile);
@ -23,7 +22,7 @@ unitTest({ permissions: { read: true } }, function fstatSyncSuccess() {
Deno.close(file.rid); Deno.close(file.rid);
}); });
unitTest({ permissions: { read: true } }, async function fstatSuccess() { Deno.test({ permissions: { read: true } }, async function fstatSuccess() {
const file = await Deno.open("README.md"); const file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid); const fileInfo = await Deno.fstat(file.rid);
assert(fileInfo.isFile); assert(fileInfo.isFile);
@ -38,7 +37,7 @@ unitTest({ permissions: { read: true } }, async function fstatSuccess() {
Deno.close(file.rid); Deno.close(file.rid);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function statSyncSuccess() { function statSyncSuccess() {
const readmeInfo = Deno.statSync("README.md"); const readmeInfo = Deno.statSync("README.md");
@ -101,13 +100,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, function statSyncPerm() { Deno.test({ permissions: { read: false } }, function statSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.statSync("README.md"); Deno.statSync("README.md");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function statSyncNotFound() { Deno.test({ permissions: { read: true } }, function statSyncNotFound() {
assertThrows( assertThrows(
() => { () => {
Deno.statSync("bad_file_name"); Deno.statSync("bad_file_name");
@ -117,7 +116,7 @@ unitTest({ permissions: { read: true } }, function statSyncNotFound() {
); );
}); });
unitTest({ permissions: { read: true } }, function lstatSyncSuccess() { Deno.test({ permissions: { read: true } }, function lstatSyncSuccess() {
const packageInfo = Deno.lstatSync("README.md"); const packageInfo = Deno.lstatSync("README.md");
assert(packageInfo.isFile); assert(packageInfo.isFile);
assert(!packageInfo.isSymlink); assert(!packageInfo.isSymlink);
@ -145,13 +144,13 @@ unitTest({ permissions: { read: true } }, function lstatSyncSuccess() {
assert(!coreInfoByUrl.isSymlink); assert(!coreInfoByUrl.isSymlink);
}); });
unitTest({ permissions: { read: false } }, function lstatSyncPerm() { Deno.test({ permissions: { read: false } }, function lstatSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.lstatSync("hello.txt"); Deno.lstatSync("hello.txt");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, function lstatSyncNotFound() { Deno.test({ permissions: { read: true } }, function lstatSyncNotFound() {
assertThrows( assertThrows(
() => { () => {
Deno.lstatSync("bad_file_name"); Deno.lstatSync("bad_file_name");
@ -161,7 +160,7 @@ unitTest({ permissions: { read: true } }, function lstatSyncNotFound() {
); );
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function statSuccess() { async function statSuccess() {
const readmeInfo = await Deno.stat("README.md"); const readmeInfo = await Deno.stat("README.md");
@ -227,13 +226,13 @@ unitTest(
}, },
); );
unitTest({ permissions: { read: false } }, async function statPerm() { Deno.test({ permissions: { read: false } }, async function statPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.stat("README.md"); await Deno.stat("README.md");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, async function statNotFound() { Deno.test({ permissions: { read: true } }, async function statNotFound() {
await assertRejects( await assertRejects(
async () => { async () => {
await Deno.stat("bad_file_name"); await Deno.stat("bad_file_name");
@ -243,7 +242,7 @@ unitTest({ permissions: { read: true } }, async function statNotFound() {
); );
}); });
unitTest({ permissions: { read: true } }, async function lstatSuccess() { Deno.test({ permissions: { read: true } }, async function lstatSuccess() {
const readmeInfo = await Deno.lstat("README.md"); const readmeInfo = await Deno.lstat("README.md");
assert(readmeInfo.isFile); assert(readmeInfo.isFile);
assert(!readmeInfo.isSymlink); assert(!readmeInfo.isSymlink);
@ -271,13 +270,13 @@ unitTest({ permissions: { read: true } }, async function lstatSuccess() {
assert(!coreInfoByUrl.isSymlink); assert(!coreInfoByUrl.isSymlink);
}); });
unitTest({ permissions: { read: false } }, async function lstatPerm() { Deno.test({ permissions: { read: false } }, async function lstatPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.lstat("README.md"); await Deno.lstat("README.md");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { read: true } }, async function lstatNotFound() { Deno.test({ permissions: { read: true } }, async function lstatNotFound() {
await assertRejects( await assertRejects(
async () => { async () => {
await Deno.lstat("bad_file_name"); await Deno.lstat("bad_file_name");
@ -287,7 +286,7 @@ unitTest({ permissions: { read: true } }, async function lstatNotFound() {
); );
}); });
unitTest( Deno.test(
{ {
ignore: Deno.build.os !== "windows", ignore: Deno.build.os !== "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },
@ -311,7 +310,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
permissions: { read: true, write: true }, permissions: { read: true, write: true },

View file

@ -1,32 +1,32 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(async function stdioStdinRead() { Deno.test(async function stdioStdinRead() {
const nread = await Deno.stdin.read(new Uint8Array(0)); const nread = await Deno.stdin.read(new Uint8Array(0));
assertEquals(nread, 0); assertEquals(nread, 0);
}); });
unitTest(function stdioStdinReadSync() { Deno.test(function stdioStdinReadSync() {
const nread = Deno.stdin.readSync(new Uint8Array(0)); const nread = Deno.stdin.readSync(new Uint8Array(0));
assertEquals(nread, 0); assertEquals(nread, 0);
}); });
unitTest(async function stdioStdoutWrite() { Deno.test(async function stdioStdoutWrite() {
const nwritten = await Deno.stdout.write(new Uint8Array(0)); const nwritten = await Deno.stdout.write(new Uint8Array(0));
assertEquals(nwritten, 0); assertEquals(nwritten, 0);
}); });
unitTest(function stdioStdoutWriteSync() { Deno.test(function stdioStdoutWriteSync() {
const nwritten = Deno.stdout.writeSync(new Uint8Array(0)); const nwritten = Deno.stdout.writeSync(new Uint8Array(0));
assertEquals(nwritten, 0); assertEquals(nwritten, 0);
}); });
unitTest(async function stdioStderrWrite() { Deno.test(async function stdioStderrWrite() {
const nwritten = await Deno.stderr.write(new Uint8Array(0)); const nwritten = await Deno.stderr.write(new Uint8Array(0));
assertEquals(nwritten, 0); assertEquals(nwritten, 0);
}); });
unitTest(function stdioStderrWriteSync() { Deno.test(function stdioStderrWriteSync() {
const nwritten = Deno.stderr.writeSync(new Uint8Array(0)); const nwritten = Deno.stderr.writeSync(new Uint8Array(0));
assertEquals(nwritten, 0); assertEquals(nwritten, 0);
}); });

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest(async function symlinkSyncPerm() { Deno.test(async function symlinkSyncPerm() {
const rs = new ReadableStream<string>({ const rs = new ReadableStream<string>({
start(controller) { start(controller) {
controller.enqueue("hello "); controller.enqueue("hello ");

View file

@ -4,10 +4,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function symlinkSyncSuccess() { function symlinkSyncSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -22,7 +21,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function symlinkSyncURL() { function symlinkSyncURL() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -40,13 +39,16 @@ unitTest(
}, },
); );
unitTest(function symlinkSyncPerm() { Deno.test(
{ permissions: { read: false, write: false } },
function symlinkSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.symlinkSync("oldbaddir", "newbaddir"); Deno.symlinkSync("oldbaddir", "newbaddir");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); },
);
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function symlinkSyncAlreadyExist() { function symlinkSyncAlreadyExist() {
const existingFile = Deno.makeTempFileSync(); const existingFile = Deno.makeTempFileSync();
@ -61,7 +63,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function symlinkSuccess() { async function symlinkSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -76,7 +78,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function symlinkURL() { async function symlinkURL() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -94,7 +96,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function symlinkAlreadyExist() { async function symlinkAlreadyExist() {
const existingFile = Deno.makeTempFileSync(); const existingFile = Deno.makeTempFileSync();
@ -109,7 +111,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: ["."] } }, { permissions: { read: true, write: ["."] } },
async function symlinkNoFullWritePermissions() { async function symlinkNoFullWritePermissions() {
await assertRejects( await assertRejects(
@ -123,7 +125,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: ["."], write: true } }, { permissions: { read: ["."], write: true } },
async function symlinkNoFullReadPermissions() { async function symlinkNoFullReadPermissions() {
await assertRejects( await assertRejects(

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function fdatasyncSyncSuccess() { function fdatasyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt"; const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
@ -19,7 +19,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function fdatasyncSuccess() { async function fdatasyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt"; const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
@ -37,7 +37,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function fsyncSyncSuccess() { function fsyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt";
@ -55,7 +55,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function fsyncSuccess() { async function fsyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; const filename = (await Deno.makeTempDir()) + "/test_fsync.txt";

View file

@ -23,72 +23,6 @@ export { delay } from "../../../test_util/std/async/delay.ts";
export { readLines } from "../../../test_util/std/io/bufio.ts"; export { readLines } from "../../../test_util/std/io/bufio.ts";
export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts"; export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts";
interface UnitTestPermissions {
env?: "inherit" | boolean | string[];
hrtime?: "inherit" | boolean;
net?: "inherit" | boolean | string[];
ffi?: "inherit" | boolean;
read?: "inherit" | boolean | Array<string | URL>;
run?: "inherit" | boolean | Array<string | URL>;
write?: "inherit" | boolean | Array<string | URL>;
}
interface UnitTestOptions {
ignore?: boolean;
only?: boolean;
permissions?: UnitTestPermissions;
}
type TestFunction = (tester: Deno.TestContext) => void | Promise<void>;
export function unitTest(fn: TestFunction): void;
export function unitTest(options: UnitTestOptions, fn: TestFunction): void;
export function unitTest(
optionsOrFn: UnitTestOptions | TestFunction,
maybeFn?: TestFunction,
): void {
assert(optionsOrFn, "At least one argument is required");
let options: UnitTestOptions;
let name: string;
let fn: TestFunction;
if (typeof optionsOrFn === "function") {
options = {};
fn = optionsOrFn;
name = fn.name;
assert(name, "Missing test function name");
} else {
options = optionsOrFn;
assert(maybeFn, "Missing test function definition");
assert(
typeof maybeFn === "function",
"Second argument should be test function definition",
);
fn = maybeFn;
name = fn.name;
assert(name, "Missing test function name");
}
const testDefinition: Deno.TestDefinition = {
name,
fn,
ignore: !!options.ignore,
only: !!options.only,
permissions: Object.assign({
read: false,
write: false,
net: false,
env: false,
run: false,
ffi: false,
hrtime: false,
}, options.permissions),
};
Deno.test(testDefinition);
}
export function pathToAbsoluteFileUrl(path: string): URL { export function pathToAbsoluteFileUrl(path: string): URL {
path = resolve(path); path = resolve(path);

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertRejects, assertThrows, unitTest } from "./test_util.ts"; import { assertRejects, assertThrows } from "./test_util.ts";
unitTest(function testWrongOverloads() { Deno.test(function testWrongOverloads() {
assertThrows( assertThrows(
() => { () => {
// @ts-ignore Testing invalid overloads // @ts-ignore Testing invalid overloads
@ -60,7 +60,7 @@ unitTest(function testWrongOverloads() {
); );
}); });
unitTest(function nameOfTestCaseCantBeEmpty() { Deno.test(function nameOfTestCaseCantBeEmpty() {
assertThrows( assertThrows(
() => { () => {
Deno.test("", () => {}); Deno.test("", () => {});
@ -80,7 +80,7 @@ unitTest(function nameOfTestCaseCantBeEmpty() {
); );
}); });
unitTest(function invalidStepArguments(t) { Deno.test(function invalidStepArguments(t) {
assertRejects( assertRejects(
async () => { async () => {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any

View file

@ -1,19 +1,19 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertThrows } from "./test_util.ts";
unitTest(function btoaSuccess() { Deno.test(function btoaSuccess() {
const text = "hello world"; const text = "hello world";
const encoded = btoa(text); const encoded = btoa(text);
assertEquals(encoded, "aGVsbG8gd29ybGQ="); assertEquals(encoded, "aGVsbG8gd29ybGQ=");
}); });
unitTest(function atobSuccess() { Deno.test(function atobSuccess() {
const encoded = "aGVsbG8gd29ybGQ="; const encoded = "aGVsbG8gd29ybGQ=";
const decoded = atob(encoded); const decoded = atob(encoded);
assertEquals(decoded, "hello world"); assertEquals(decoded, "hello world");
}); });
unitTest(function atobWithAsciiWhitespace() { Deno.test(function atobWithAsciiWhitespace() {
const encodedList = [ const encodedList = [
" aGVsbG8gd29ybGQ=", " aGVsbG8gd29ybGQ=",
" aGVsbG8gd29ybGQ=", " aGVsbG8gd29ybGQ=",
@ -30,7 +30,7 @@ unitTest(function atobWithAsciiWhitespace() {
} }
}); });
unitTest(function atobThrows() { Deno.test(function atobThrows() {
let threw = false; let threw = false;
try { try {
atob("aGVsbG8gd29ybGQ=="); atob("aGVsbG8gd29ybGQ==");
@ -40,7 +40,7 @@ unitTest(function atobThrows() {
assert(threw); assert(threw);
}); });
unitTest(function atobThrows2() { Deno.test(function atobThrows2() {
let threw = false; let threw = false;
try { try {
atob("aGVsbG8gd29ybGQ==="); atob("aGVsbG8gd29ybGQ===");
@ -50,7 +50,7 @@ unitTest(function atobThrows2() {
assert(threw); assert(threw);
}); });
unitTest(function atobThrows3() { Deno.test(function atobThrows3() {
let threw = false; let threw = false;
try { try {
atob("foobar!!"); atob("foobar!!");
@ -65,14 +65,14 @@ unitTest(function atobThrows3() {
assert(threw); assert(threw);
}); });
unitTest(function btoaFailed() { Deno.test(function btoaFailed() {
const text = "你好"; const text = "你好";
assertThrows(() => { assertThrows(() => {
btoa(text); btoa(text);
}, DOMException); }, DOMException);
}); });
unitTest(function textDecoder2() { Deno.test(function textDecoder2() {
// deno-fmt-ignore // deno-fmt-ignore
const fixture = new Uint8Array([ const fixture = new Uint8Array([
0xf0, 0x9d, 0x93, 0xbd, 0xf0, 0x9d, 0x93, 0xbd,
@ -86,13 +86,13 @@ unitTest(function textDecoder2() {
// ignoreBOM is tested through WPT // ignoreBOM is tested through WPT
unitTest(function textDecoderASCII() { Deno.test(function textDecoderASCII() {
const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]); const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]);
const decoder = new TextDecoder("ascii"); const decoder = new TextDecoder("ascii");
assertEquals(decoder.decode(fixture), "‰•Ÿ¿"); assertEquals(decoder.decode(fixture), "‰•Ÿ¿");
}); });
unitTest(function textDecoderErrorEncoding() { Deno.test(function textDecoderErrorEncoding() {
let didThrow = false; let didThrow = false;
try { try {
new TextDecoder("Foo"); new TextDecoder("Foo");
@ -104,7 +104,7 @@ unitTest(function textDecoderErrorEncoding() {
assert(didThrow); assert(didThrow);
}); });
unitTest(function textEncoder() { Deno.test(function textEncoder() {
const fixture = "𝓽𝓮𝔁𝓽"; const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
// deno-fmt-ignore // deno-fmt-ignore
@ -116,7 +116,7 @@ unitTest(function textEncoder() {
]); ]);
}); });
unitTest(function textEncodeInto() { Deno.test(function textEncodeInto() {
const fixture = "text"; const fixture = "text";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(5); const bytes = new Uint8Array(5);
@ -129,7 +129,7 @@ unitTest(function textEncodeInto() {
]); ]);
}); });
unitTest(function textEncodeInto2() { Deno.test(function textEncodeInto2() {
const fixture = "𝓽𝓮𝔁𝓽"; const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(17); const bytes = new Uint8Array(17);
@ -145,7 +145,7 @@ unitTest(function textEncodeInto2() {
]); ]);
}); });
unitTest(function textEncodeInto3() { Deno.test(function textEncodeInto3() {
const fixture = "𝓽𝓮𝔁𝓽"; const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(5); const bytes = new Uint8Array(5);
@ -158,7 +158,7 @@ unitTest(function textEncodeInto3() {
]); ]);
}); });
unitTest(function loneSurrogateEncodeInto() { Deno.test(function loneSurrogateEncodeInto() {
const fixture = "lone𝄞\ud888surrogate"; const fixture = "lone𝄞\ud888surrogate";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(20); const bytes = new Uint8Array(20);
@ -175,7 +175,7 @@ unitTest(function loneSurrogateEncodeInto() {
]); ]);
}); });
unitTest(function loneSurrogateEncodeInto2() { Deno.test(function loneSurrogateEncodeInto2() {
const fixture = "\ud800"; const fixture = "\ud800";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(3); const bytes = new Uint8Array(3);
@ -188,7 +188,7 @@ unitTest(function loneSurrogateEncodeInto2() {
]); ]);
}); });
unitTest(function loneSurrogateEncodeInto3() { Deno.test(function loneSurrogateEncodeInto3() {
const fixture = "\udc00"; const fixture = "\udc00";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(3); const bytes = new Uint8Array(3);
@ -201,7 +201,7 @@ unitTest(function loneSurrogateEncodeInto3() {
]); ]);
}); });
unitTest(function swappedSurrogatePairEncodeInto4() { Deno.test(function swappedSurrogatePairEncodeInto4() {
const fixture = "\udc00\ud800"; const fixture = "\udc00\ud800";
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const bytes = new Uint8Array(8); const bytes = new Uint8Array(8);
@ -214,7 +214,7 @@ unitTest(function swappedSurrogatePairEncodeInto4() {
]); ]);
}); });
unitTest(function textDecoderSharedUint8Array() { Deno.test(function textDecoderSharedUint8Array() {
const ab = new SharedArrayBuffer(6); const ab = new SharedArrayBuffer(6);
const dataView = new DataView(ab); const dataView = new DataView(ab);
const charCodeA = "A".charCodeAt(0); const charCodeA = "A".charCodeAt(0);
@ -227,7 +227,7 @@ unitTest(function textDecoderSharedUint8Array() {
assertEquals(actual, "ABCDEF"); assertEquals(actual, "ABCDEF");
}); });
unitTest(function textDecoderSharedInt32Array() { Deno.test(function textDecoderSharedInt32Array() {
const ab = new SharedArrayBuffer(8); const ab = new SharedArrayBuffer(8);
const dataView = new DataView(ab); const dataView = new DataView(ab);
const charCodeA = "A".charCodeAt(0); const charCodeA = "A".charCodeAt(0);
@ -240,14 +240,14 @@ unitTest(function textDecoderSharedInt32Array() {
assertEquals(actual, "ABCDEFGH"); assertEquals(actual, "ABCDEFGH");
}); });
unitTest(function toStringShouldBeWebCompatibility() { Deno.test(function toStringShouldBeWebCompatibility() {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
assertEquals(encoder.toString(), "[object TextEncoder]"); assertEquals(encoder.toString(), "[object TextEncoder]");
const decoder = new TextDecoder(); const decoder = new TextDecoder();
assertEquals(decoder.toString(), "[object TextDecoder]"); assertEquals(decoder.toString(), "[object TextDecoder]");
}); });
unitTest(function textEncoderShouldCoerceToString() { Deno.test(function textEncoderShouldCoerceToString() {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const fixutreText = "text"; const fixutreText = "text";
const fixture = { const fixture = {

View file

@ -6,10 +6,9 @@ import {
Deferred, Deferred,
deferred, deferred,
delay, delay,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest(async function functionParameterBindingSuccess() { Deno.test(async function functionParameterBindingSuccess() {
const promise = deferred(); const promise = deferred();
let count = 0; let count = 0;
@ -26,7 +25,7 @@ unitTest(async function functionParameterBindingSuccess() {
assertEquals(count, 1); assertEquals(count, 1);
}); });
unitTest(async function stringifyAndEvalNonFunctions() { Deno.test(async function stringifyAndEvalNonFunctions() {
// eval can only access global scope // eval can only access global scope
const global = globalThis as unknown as { const global = globalThis as unknown as {
globalPromise: ReturnType<typeof deferred>; globalPromise: ReturnType<typeof deferred>;
@ -50,7 +49,7 @@ unitTest(async function stringifyAndEvalNonFunctions() {
Reflect.deleteProperty(global, "globalCount"); Reflect.deleteProperty(global, "globalCount");
}); });
unitTest(async function timeoutSuccess() { Deno.test(async function timeoutSuccess() {
const promise = deferred(); const promise = deferred();
let count = 0; let count = 0;
setTimeout(() => { setTimeout(() => {
@ -62,7 +61,7 @@ unitTest(async function timeoutSuccess() {
assertEquals(count, 1); assertEquals(count, 1);
}); });
unitTest(async function timeoutEvalNoScopeLeak() { Deno.test(async function timeoutEvalNoScopeLeak() {
// eval can only access global scope // eval can only access global scope
const global = globalThis as unknown as { const global = globalThis as unknown as {
globalPromise: Deferred<Error>; globalPromise: Deferred<Error>;
@ -83,7 +82,7 @@ unitTest(async function timeoutEvalNoScopeLeak() {
Reflect.deleteProperty(global, "globalPromise"); Reflect.deleteProperty(global, "globalPromise");
}); });
unitTest(async function timeoutArgs() { Deno.test(async function timeoutArgs() {
const promise = deferred(); const promise = deferred();
const arg = 1; const arg = 1;
let capturedArgs: unknown[] = []; let capturedArgs: unknown[] = [];
@ -105,7 +104,7 @@ unitTest(async function timeoutArgs() {
]); ]);
}); });
unitTest(async function timeoutCancelSuccess() { Deno.test(async function timeoutCancelSuccess() {
let count = 0; let count = 0;
const id = setTimeout(() => { const id = setTimeout(() => {
count++; count++;
@ -116,7 +115,7 @@ unitTest(async function timeoutCancelSuccess() {
assertEquals(count, 0); assertEquals(count, 0);
}); });
unitTest(async function timeoutCancelMultiple() { Deno.test(async function timeoutCancelMultiple() {
function uncalled(): never { function uncalled(): never {
throw new Error("This function should not be called."); throw new Error("This function should not be called.");
} }
@ -141,7 +140,7 @@ unitTest(async function timeoutCancelMultiple() {
await delay(50); await delay(50);
}); });
unitTest(async function timeoutCancelInvalidSilentFail() { Deno.test(async function timeoutCancelInvalidSilentFail() {
// Expect no panic // Expect no panic
const promise = deferred(); const promise = deferred();
let count = 0; let count = 0;
@ -158,7 +157,7 @@ unitTest(async function timeoutCancelInvalidSilentFail() {
clearTimeout(2147483647); clearTimeout(2147483647);
}); });
unitTest(async function intervalSuccess() { Deno.test(async function intervalSuccess() {
const promise = deferred(); const promise = deferred();
let count = 0; let count = 0;
const id = setInterval(() => { const id = setInterval(() => {
@ -176,7 +175,7 @@ unitTest(async function intervalSuccess() {
await delay(0); await delay(0);
}); });
unitTest(async function intervalCancelSuccess() { Deno.test(async function intervalCancelSuccess() {
let count = 0; let count = 0;
const id = setInterval(() => { const id = setInterval(() => {
count++; count++;
@ -186,7 +185,7 @@ unitTest(async function intervalCancelSuccess() {
assertEquals(count, 0); assertEquals(count, 0);
}); });
unitTest(async function intervalOrdering() { Deno.test(async function intervalOrdering() {
const timers: number[] = []; const timers: number[] = [];
let timeouts = 0; let timeouts = 0;
function onTimeout() { function onTimeout() {
@ -202,12 +201,12 @@ unitTest(async function intervalOrdering() {
assertEquals(timeouts, 1); assertEquals(timeouts, 1);
}); });
unitTest(function intervalCancelInvalidSilentFail() { Deno.test(function intervalCancelInvalidSilentFail() {
// Should silently fail (no panic) // Should silently fail (no panic)
clearInterval(2147483647); clearInterval(2147483647);
}); });
unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { Deno.test(async function fireCallbackImmediatelyWhenDelayOverMaxValue() {
let count = 0; let count = 0;
setTimeout(() => { setTimeout(() => {
count++; count++;
@ -216,7 +215,7 @@ unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() {
assertEquals(count, 1); assertEquals(count, 1);
}); });
unitTest(async function timeoutCallbackThis() { Deno.test(async function timeoutCallbackThis() {
const promise = deferred(); const promise = deferred();
let capturedThis: unknown; let capturedThis: unknown;
const obj = { const obj = {
@ -230,7 +229,7 @@ unitTest(async function timeoutCallbackThis() {
assertEquals(capturedThis, window); assertEquals(capturedThis, window);
}); });
unitTest(async function timeoutBindThis() { Deno.test(async function timeoutBindThis() {
const thisCheckPassed = [null, undefined, window, globalThis]; const thisCheckPassed = [null, undefined, window, globalThis];
const thisCheckFailed = [ const thisCheckFailed = [
@ -278,7 +277,7 @@ unitTest(async function timeoutBindThis() {
} }
}); });
unitTest(function clearTimeoutShouldConvertToNumber() { Deno.test(function clearTimeoutShouldConvertToNumber() {
let called = false; let called = false;
const obj = { const obj = {
valueOf(): number { valueOf(): number {
@ -290,7 +289,7 @@ unitTest(function clearTimeoutShouldConvertToNumber() {
assert(called); assert(called);
}); });
unitTest(function setTimeoutShouldThrowWithBigint() { Deno.test(function setTimeoutShouldThrowWithBigint() {
let hasThrown = 0; let hasThrown = 0;
try { try {
setTimeout(() => {}, (1n as unknown) as number); setTimeout(() => {}, (1n as unknown) as number);
@ -305,7 +304,7 @@ unitTest(function setTimeoutShouldThrowWithBigint() {
assertEquals(hasThrown, 2); assertEquals(hasThrown, 2);
}); });
unitTest(function clearTimeoutShouldThrowWithBigint() { Deno.test(function clearTimeoutShouldThrowWithBigint() {
let hasThrown = 0; let hasThrown = 0;
try { try {
clearTimeout((1n as unknown) as number); clearTimeout((1n as unknown) as number);
@ -320,23 +319,23 @@ unitTest(function clearTimeoutShouldThrowWithBigint() {
assertEquals(hasThrown, 2); assertEquals(hasThrown, 2);
}); });
unitTest(function testFunctionName() { Deno.test(function testFunctionName() {
assertEquals(clearTimeout.name, "clearTimeout"); assertEquals(clearTimeout.name, "clearTimeout");
assertEquals(clearInterval.name, "clearInterval"); assertEquals(clearInterval.name, "clearInterval");
}); });
unitTest(function testFunctionParamsLength() { Deno.test(function testFunctionParamsLength() {
assertEquals(setTimeout.length, 1); assertEquals(setTimeout.length, 1);
assertEquals(setInterval.length, 1); assertEquals(setInterval.length, 1);
assertEquals(clearTimeout.length, 0); assertEquals(clearTimeout.length, 0);
assertEquals(clearInterval.length, 0); assertEquals(clearInterval.length, 0);
}); });
unitTest(function clearTimeoutAndClearIntervalNotBeEquals() { Deno.test(function clearTimeoutAndClearIntervalNotBeEquals() {
assertNotEquals(clearTimeout, clearInterval); assertNotEquals(clearTimeout, clearInterval);
}); });
unitTest(async function timerMaxCpuBug() { Deno.test(async function timerMaxCpuBug() {
// There was a bug where clearing a timeout would cause Deno to use 100% CPU. // There was a bug where clearing a timeout would cause Deno to use 100% CPU.
clearTimeout(setTimeout(() => {}, 1000)); clearTimeout(setTimeout(() => {}, 1000));
// We can check this by counting how many ops have triggered in the interim. // We can check this by counting how many ops have triggered in the interim.
@ -347,7 +346,7 @@ unitTest(async function timerMaxCpuBug() {
assert(opsDispatched_ - opsDispatched < 10); assert(opsDispatched_ - opsDispatched < 10);
}); });
unitTest(async function timerBasicMicrotaskOrdering() { Deno.test(async function timerBasicMicrotaskOrdering() {
let s = ""; let s = "";
let count = 0; let count = 0;
const promise = deferred(); const promise = deferred();
@ -371,7 +370,7 @@ unitTest(async function timerBasicMicrotaskOrdering() {
assertEquals(s, "deno"); assertEquals(s, "deno");
}); });
unitTest(async function timerNestedMicrotaskOrdering() { Deno.test(async function timerNestedMicrotaskOrdering() {
let s = ""; let s = "";
const promise = deferred(); const promise = deferred();
s += "0"; s += "0";
@ -407,11 +406,11 @@ unitTest(async function timerNestedMicrotaskOrdering() {
assertEquals(s, "0123456789AB"); assertEquals(s, "0123456789AB");
}); });
unitTest(function testQueueMicrotask() { Deno.test(function testQueueMicrotask() {
assertEquals(typeof queueMicrotask, "function"); assertEquals(typeof queueMicrotask, "function");
}); });
unitTest(async function timerIgnoresDateOverride() { Deno.test(async function timerIgnoresDateOverride() {
const OriginalDate = Date; const OriginalDate = Date;
const promise = deferred(); const promise = deferred();
let hasThrown = 0; let hasThrown = 0;
@ -445,14 +444,14 @@ unitTest(async function timerIgnoresDateOverride() {
assertEquals(hasThrown, 1); assertEquals(hasThrown, 1);
}); });
unitTest({ permissions: { hrtime: true } }, function sleepSync() { Deno.test({ permissions: { hrtime: true } }, function sleepSync() {
const start = performance.now(); const start = performance.now();
Deno.sleepSync(10); Deno.sleepSync(10);
const after = performance.now(); const after = performance.now();
assert(after - start >= 10); assert(after - start >= 10);
}); });
unitTest( Deno.test(
{ permissions: { hrtime: true } }, { permissions: { hrtime: true } },
async function sleepSyncShorterPromise() { async function sleepSyncShorterPromise() {
const perf = performance; const perf = performance;
@ -471,7 +470,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { hrtime: true } }, { permissions: { hrtime: true } },
async function sleepSyncLongerPromise() { async function sleepSyncLongerPromise() {
const perf = performance; const perf = performance;

View file

@ -8,7 +8,6 @@ import {
assertThrows, assertThrows,
Deferred, Deferred,
deferred, deferred,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
import { BufReader, BufWriter } from "../../../test_util/std/io/bufio.ts"; import { BufReader, BufWriter } from "../../../test_util/std/io/bufio.ts";
import { readAll } from "../../../test_util/std/io/util.ts"; import { readAll } from "../../../test_util/std/io/util.ts";
@ -25,13 +24,13 @@ function unreachable(): never {
throw new Error("Unreachable code reached"); throw new Error("Unreachable code reached");
} }
unitTest(async function connectTLSNoPerm() { Deno.test({ permissions: { net: false } }, async function connectTLSNoPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.connectTls({ hostname: "deno.land", port: 443 }); await Deno.connectTls({ hostname: "deno.land", port: 443 });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSInvalidHost() { async function connectTLSInvalidHost() {
const listener = await Deno.listenTls({ const listener = await Deno.listenTls({
@ -49,7 +48,9 @@ unitTest(
}, },
); );
unitTest(async function connectTLSCertFileNoReadPerm() { Deno.test(
{ permissions: { net: true, read: false } },
async function connectTLSCertFileNoReadPerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.connectTls({ await Deno.connectTls({
hostname: "deno.land", hostname: "deno.land",
@ -57,9 +58,10 @@ unitTest(async function connectTLSCertFileNoReadPerm() {
certFile: "cli/tests/testdata/tls/RootCA.crt", certFile: "cli/tests/testdata/tls/RootCA.crt",
}); });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); },
);
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
function listenTLSNonExistentCertKeyFiles() { function listenTLSNonExistentCertKeyFiles() {
const options = { const options = {
@ -85,7 +87,9 @@ unitTest(
}, },
); );
unitTest({ permissions: { net: true } }, function listenTLSNoReadPerm() { Deno.test(
{ permissions: { net: true, read: false } },
function listenTLSNoReadPerm() {
assertThrows(() => { assertThrows(() => {
Deno.listenTls({ Deno.listenTls({
hostname: "localhost", hostname: "localhost",
@ -94,9 +98,10 @@ unitTest({ permissions: { net: true } }, function listenTLSNoReadPerm() {
keyFile: "cli/tests/testdata/tls/localhost.key", keyFile: "cli/tests/testdata/tls/localhost.key",
}); });
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); },
);
unitTest( Deno.test(
{ {
permissions: { read: true, write: true, net: true }, permissions: { read: true, write: true, net: true },
}, },
@ -123,7 +128,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true, net: true } }, { permissions: { read: true, write: true, net: true } },
function listenTLSEmptyCertFile() { function listenTLSEmptyCertFile() {
const options = { const options = {
@ -148,7 +153,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function dialAndListenTLS() { async function dialAndListenTLS() {
const resolvable = deferred(); const resolvable = deferred();
@ -300,7 +305,7 @@ async function receiveThenSend(
conn.close(); conn.close();
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendOneByte() { async function tlsServerStreamHalfCloseSendOneByte() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -311,7 +316,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendOneByte() { async function tlsClientStreamHalfCloseSendOneByte() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -322,7 +327,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendOneChunk() { async function tlsServerStreamHalfCloseSendOneChunk() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -333,7 +338,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendOneChunk() { async function tlsClientStreamHalfCloseSendOneChunk() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -344,7 +349,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendManyBytes() { async function tlsServerStreamHalfCloseSendManyBytes() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -355,7 +360,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendManyBytes() { async function tlsClientStreamHalfCloseSendManyBytes() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -366,7 +371,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendManyChunks() { async function tlsServerStreamHalfCloseSendManyChunks() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -377,7 +382,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendManyChunks() { async function tlsClientStreamHalfCloseSendManyChunks() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -427,7 +432,7 @@ async function receiveAlotSendNothing(conn: Deno.Conn) {
conn.close(); conn.close();
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamCancelRead() { async function tlsServerStreamCancelRead() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -438,7 +443,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamCancelRead() { async function tlsClientStreamCancelRead() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -484,7 +489,7 @@ async function sendReceiveEmptyBuf(conn: Deno.Conn) {
conn.close(); conn.close();
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsStreamSendReceiveEmptyBuf() { async function tlsStreamSendReceiveEmptyBuf() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -510,7 +515,7 @@ async function closeWriteAndClose(conn: Deno.Conn) {
conn.close(); conn.close();
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsServerStreamImmediateClose() { async function tlsServerStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -521,7 +526,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientStreamImmediateClose() { async function tlsClientStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -532,7 +537,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsClientAndServerStreamImmediateClose() { async function tlsClientAndServerStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair(); const [serverConn, clientConn] = await tlsPair();
@ -775,7 +780,7 @@ async function tlsWithTcpFailureTestImpl(
} }
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpCorruptionImmediately() { async function tlsHandshakeWithTcpCorruptionImmediately() {
await tlsWithTcpFailureTestImpl("handshake", 0, "corruption", false); await tlsWithTcpFailureTestImpl("handshake", 0, "corruption", false);
@ -783,7 +788,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpShutdownImmediately() { async function tlsHandshakeWithTcpShutdownImmediately() {
await tlsWithTcpFailureTestImpl("handshake", 0, "shutdown", false); await tlsWithTcpFailureTestImpl("handshake", 0, "shutdown", false);
@ -791,7 +796,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpCorruptionAfter70Bytes() { async function tlsHandshakeWithTcpCorruptionAfter70Bytes() {
await tlsWithTcpFailureTestImpl("handshake", 76, "corruption", false); await tlsWithTcpFailureTestImpl("handshake", 76, "corruption", false);
@ -799,7 +804,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpShutdownAfter70bytes() { async function tlsHandshakeWithTcpShutdownAfter70bytes() {
await tlsWithTcpFailureTestImpl("handshake", 77, "shutdown", false); await tlsWithTcpFailureTestImpl("handshake", 77, "shutdown", false);
@ -807,7 +812,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpCorruptionAfter200Bytes() { async function tlsHandshakeWithTcpCorruptionAfter200Bytes() {
await tlsWithTcpFailureTestImpl("handshake", 200, "corruption", false); await tlsWithTcpFailureTestImpl("handshake", 200, "corruption", false);
@ -815,7 +820,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeWithTcpShutdownAfter200bytes() { async function tlsHandshakeWithTcpShutdownAfter200bytes() {
await tlsWithTcpFailureTestImpl("handshake", 201, "shutdown", false); await tlsWithTcpFailureTestImpl("handshake", 201, "shutdown", false);
@ -823,7 +828,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsTrafficWithTcpCorruption() { async function tlsTrafficWithTcpCorruption() {
await tlsWithTcpFailureTestImpl("traffic", Infinity, "corruption", false); await tlsWithTcpFailureTestImpl("traffic", Infinity, "corruption", false);
@ -831,7 +836,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsTrafficWithTcpShutdown() { async function tlsTrafficWithTcpShutdown() {
await tlsWithTcpFailureTestImpl("traffic", Infinity, "shutdown", false); await tlsWithTcpFailureTestImpl("traffic", Infinity, "shutdown", false);
@ -912,7 +917,7 @@ async function curl(url: string): Promise<string> {
} }
} }
unitTest( Deno.test(
{ permissions: { read: true, net: true, run: true } }, { permissions: { read: true, net: true, run: true } },
async function curlFakeHttpsServer() { async function curlFakeHttpsServer() {
const port = getPort(); const port = getPort();
@ -936,7 +941,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function startTls() { async function startTls() {
const hostname = "smtp.gmail.com"; const hostname = "smtp.gmail.com";
@ -987,7 +992,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSBadClientCertPrivateKey(): Promise<void> { async function connectTLSBadClientCertPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1003,7 +1008,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSBadPrivateKey(): Promise<void> { async function connectTLSBadPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1019,7 +1024,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSNotPrivateKey(): Promise<void> { async function connectTLSNotPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
@ -1035,7 +1040,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectWithClientCert() { async function connectWithClientCert() {
// The test_server running on port 4552 responds with 'PASS' if client // The test_server running on port 4552 responds with 'PASS' if client
@ -1060,7 +1065,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSCaCerts() { async function connectTLSCaCerts() {
const conn = await Deno.connectTls({ const conn = await Deno.connectTls({
@ -1074,7 +1079,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function connectTLSCertFile() { async function connectTLSCertFile() {
const conn = await Deno.connectTls({ const conn = await Deno.connectTls({
@ -1088,7 +1093,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function startTLSCaCerts() { async function startTLSCaCerts() {
const plainConn = await Deno.connect({ const plainConn = await Deno.connect({
@ -1105,7 +1110,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeSuccess() { async function tlsHandshakeSuccess() {
const hostname = "localhost"; const hostname = "localhost";
@ -1174,7 +1179,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, net: true } }, { permissions: { read: true, net: true } },
async function tlsHandshakeFailure() { async function tlsHandshakeFailure() {
const hostname = "localhost"; const hostname = "localhost";

View file

@ -1,12 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
assertEquals,
assertRejects,
assertThrows,
unitTest,
} from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function ftruncateSyncSuccess() { function ftruncateSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_ftruncateSync.txt"; const filename = Deno.makeTempDirSync() + "/test_ftruncateSync.txt";
@ -28,7 +23,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function ftruncateSuccess() { async function ftruncateSuccess() {
const filename = Deno.makeTempDirSync() + "/test_ftruncate.txt"; const filename = Deno.makeTempDirSync() + "/test_ftruncate.txt";
@ -50,7 +45,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function truncateSyncSuccess() { function truncateSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt"; const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt";
@ -65,7 +60,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function truncateSuccess() { async function truncateSuccess() {
const filename = Deno.makeTempDirSync() + "/test_truncate.txt"; const filename = Deno.makeTempDirSync() + "/test_truncate.txt";
@ -80,19 +75,19 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: false } }, function truncateSyncPerm() { Deno.test({ permissions: { write: false } }, function truncateSyncPerm() {
assertThrows(() => { assertThrows(() => {
Deno.truncateSync("/test_truncateSyncPermission.txt"); Deno.truncateSync("/test_truncateSyncPermission.txt");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest({ permissions: { write: false } }, async function truncatePerm() { Deno.test({ permissions: { write: false } }, async function truncatePerm() {
await assertRejects(async () => { await assertRejects(async () => {
await Deno.truncate("/test_truncatePermission.txt"); await Deno.truncate("/test_truncatePermission.txt");
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function truncateSyncNotFound() { function truncateSyncNotFound() {
const filename = "/badfile.txt"; const filename = "/badfile.txt";
@ -106,7 +101,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function truncateSyncNotFound() { async function truncateSyncNotFound() {
const filename = "/badfile.txt"; const filename = "/badfile.txt";

View file

@ -1,9 +1,9 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertThrows, unitTest } from "./test_util.ts"; import { assert, assertThrows } from "./test_util.ts";
// Note tests for Deno.setRaw is in integration tests. // Note tests for Deno.setRaw is in integration tests.
unitTest({ permissions: { read: true } }, function consoleSizeFile() { Deno.test({ permissions: { read: true } }, function consoleSizeFile() {
const file = Deno.openSync("cli/tests/testdata/hello.txt"); const file = Deno.openSync("cli/tests/testdata/hello.txt");
assertThrows(() => { assertThrows(() => {
Deno.consoleSize(file.rid); Deno.consoleSize(file.rid);
@ -11,21 +11,21 @@ unitTest({ permissions: { read: true } }, function consoleSizeFile() {
file.close(); file.close();
}); });
unitTest(function consoleSizeError() { Deno.test(function consoleSizeError() {
assertThrows(() => { assertThrows(() => {
// Absurdly large rid. // Absurdly large rid.
Deno.consoleSize(0x7fffffff); Deno.consoleSize(0x7fffffff);
}, Deno.errors.BadResource); }, Deno.errors.BadResource);
}); });
unitTest({ permissions: { read: true } }, function isatty() { Deno.test({ permissions: { read: true } }, function isatty() {
// CI not under TTY, so cannot test stdin/stdout/stderr. // CI not under TTY, so cannot test stdin/stdout/stderr.
const f = Deno.openSync("cli/tests/testdata/hello.txt"); const f = Deno.openSync("cli/tests/testdata/hello.txt");
assert(!Deno.isatty(f.rid)); assert(!Deno.isatty(f.rid));
f.close(); f.close();
}); });
unitTest(function isattyError() { Deno.test(function isattyError() {
let caught = false; let caught = false;
try { try {
// Absurdly large rid. // Absurdly large rid.

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts"; import { assertEquals } from "./test_util.ts";
unitTest( Deno.test(
{ {
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
}, },

View file

@ -1,13 +1,13 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
unitTest(function urlSearchParamsWithMultipleSpaces() { Deno.test(function urlSearchParamsWithMultipleSpaces() {
const init = { str: "this string has spaces in it" }; const init = { str: "this string has spaces in it" };
const searchParams = new URLSearchParams(init).toString(); const searchParams = new URLSearchParams(init).toString();
assertEquals(searchParams, "str=this+string+has+spaces+in+it"); assertEquals(searchParams, "str=this+string+has+spaces+in+it");
}); });
unitTest(function urlSearchParamsWithExclamation() { Deno.test(function urlSearchParamsWithExclamation() {
const init = [ const init = [
["str", "hello, world!"], ["str", "hello, world!"],
]; ];
@ -15,7 +15,7 @@ unitTest(function urlSearchParamsWithExclamation() {
assertEquals(searchParams, "str=hello%2C+world%21"); assertEquals(searchParams, "str=hello%2C+world%21");
}); });
unitTest(function urlSearchParamsWithQuotes() { Deno.test(function urlSearchParamsWithQuotes() {
const init = [ const init = [
["str", "'hello world'"], ["str", "'hello world'"],
]; ];
@ -23,7 +23,7 @@ unitTest(function urlSearchParamsWithQuotes() {
assertEquals(searchParams, "str=%27hello+world%27"); assertEquals(searchParams, "str=%27hello+world%27");
}); });
unitTest(function urlSearchParamsWithBraket() { Deno.test(function urlSearchParamsWithBraket() {
const init = [ const init = [
["str", "(hello world)"], ["str", "(hello world)"],
]; ];
@ -31,7 +31,7 @@ unitTest(function urlSearchParamsWithBraket() {
assertEquals(searchParams, "str=%28hello+world%29"); assertEquals(searchParams, "str=%28hello+world%29");
}); });
unitTest(function urlSearchParamsWithTilde() { Deno.test(function urlSearchParamsWithTilde() {
const init = [ const init = [
["str", "hello~world"], ["str", "hello~world"],
]; ];
@ -39,7 +39,7 @@ unitTest(function urlSearchParamsWithTilde() {
assertEquals(searchParams, "str=hello%7Eworld"); assertEquals(searchParams, "str=hello%7Eworld");
}); });
unitTest(function urlSearchParamsInitString() { Deno.test(function urlSearchParamsInitString() {
const init = "c=4&a=2&b=3&%C3%A1=1"; const init = "c=4&a=2&b=3&%C3%A1=1";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assert( assert(
@ -48,7 +48,7 @@ unitTest(function urlSearchParamsInitString() {
); );
}); });
unitTest(function urlSearchParamsInitStringWithPlusCharacter() { Deno.test(function urlSearchParamsInitStringWithPlusCharacter() {
let params = new URLSearchParams("q=a+b"); let params = new URLSearchParams("q=a+b");
assertEquals(params.toString(), "q=a+b"); assertEquals(params.toString(), "q=a+b");
assertEquals(params.get("q"), "a b"); assertEquals(params.get("q"), "a b");
@ -58,7 +58,7 @@ unitTest(function urlSearchParamsInitStringWithPlusCharacter() {
assertEquals(params.get("q"), "a b c"); assertEquals(params.get("q"), "a b c");
}); });
unitTest(function urlSearchParamsInitStringWithMalformedParams() { Deno.test(function urlSearchParamsInitStringWithMalformedParams() {
// These test cases are copied from Web Platform Tests // These test cases are copied from Web Platform Tests
// https://github.com/web-platform-tests/wpt/blob/54c6d64/url/urlsearchparams-constructor.any.js#L60-L80 // https://github.com/web-platform-tests/wpt/blob/54c6d64/url/urlsearchparams-constructor.any.js#L60-L80
let params = new URLSearchParams("id=0&value=%"); let params = new URLSearchParams("id=0&value=%");
@ -84,7 +84,7 @@ unitTest(function urlSearchParamsInitStringWithMalformedParams() {
assertEquals(params.get("b"), "%*"); assertEquals(params.get("b"), "%*");
}); });
unitTest(function urlSearchParamsInitIterable() { Deno.test(function urlSearchParamsInitIterable() {
const init = [ const init = [
["a", "54"], ["a", "54"],
["b", "true"], ["b", "true"],
@ -93,33 +93,33 @@ unitTest(function urlSearchParamsInitIterable() {
assertEquals(searchParams.toString(), "a=54&b=true"); assertEquals(searchParams.toString(), "a=54&b=true");
}); });
unitTest(function urlSearchParamsInitRecord() { Deno.test(function urlSearchParamsInitRecord() {
const init = { a: "54", b: "true" }; const init = { a: "54", b: "true" };
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.toString(), "a=54&b=true"); assertEquals(searchParams.toString(), "a=54&b=true");
}); });
unitTest(function urlSearchParamsInit() { Deno.test(function urlSearchParamsInit() {
const params1 = new URLSearchParams("a=b"); const params1 = new URLSearchParams("a=b");
assertEquals(params1.toString(), "a=b"); assertEquals(params1.toString(), "a=b");
const params2 = new URLSearchParams(params1); const params2 = new URLSearchParams(params1);
assertEquals(params2.toString(), "a=b"); assertEquals(params2.toString(), "a=b");
}); });
unitTest(function urlSearchParamsAppendSuccess() { Deno.test(function urlSearchParamsAppendSuccess() {
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
searchParams.append("a", "true"); searchParams.append("a", "true");
assertEquals(searchParams.toString(), "a=true"); assertEquals(searchParams.toString(), "a=true");
}); });
unitTest(function urlSearchParamsDeleteSuccess() { Deno.test(function urlSearchParamsDeleteSuccess() {
const init = "a=54&b=true"; const init = "a=54&b=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
searchParams.delete("b"); searchParams.delete("b");
assertEquals(searchParams.toString(), "a=54"); assertEquals(searchParams.toString(), "a=54");
}); });
unitTest(function urlSearchParamsGetAllSuccess() { Deno.test(function urlSearchParamsGetAllSuccess() {
const init = "a=54&b=true&a=true"; const init = "a=54&b=true&a=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.getAll("a"), ["54", "true"]); assertEquals(searchParams.getAll("a"), ["54", "true"]);
@ -127,7 +127,7 @@ unitTest(function urlSearchParamsGetAllSuccess() {
assertEquals(searchParams.getAll("c"), []); assertEquals(searchParams.getAll("c"), []);
}); });
unitTest(function urlSearchParamsGetSuccess() { Deno.test(function urlSearchParamsGetSuccess() {
const init = "a=54&b=true&a=true"; const init = "a=54&b=true&a=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.get("a"), "54"); assertEquals(searchParams.get("a"), "54");
@ -135,7 +135,7 @@ unitTest(function urlSearchParamsGetSuccess() {
assertEquals(searchParams.get("c"), null); assertEquals(searchParams.get("c"), null);
}); });
unitTest(function urlSearchParamsHasSuccess() { Deno.test(function urlSearchParamsHasSuccess() {
const init = "a=54&b=true&a=true"; const init = "a=54&b=true&a=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assert(searchParams.has("a")); assert(searchParams.has("a"));
@ -143,28 +143,28 @@ unitTest(function urlSearchParamsHasSuccess() {
assert(!searchParams.has("c")); assert(!searchParams.has("c"));
}); });
unitTest(function urlSearchParamsSetReplaceFirstAndRemoveOthers() { Deno.test(function urlSearchParamsSetReplaceFirstAndRemoveOthers() {
const init = "a=54&b=true&a=true"; const init = "a=54&b=true&a=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
searchParams.set("a", "false"); searchParams.set("a", "false");
assertEquals(searchParams.toString(), "a=false&b=true"); assertEquals(searchParams.toString(), "a=false&b=true");
}); });
unitTest(function urlSearchParamsSetAppendNew() { Deno.test(function urlSearchParamsSetAppendNew() {
const init = "a=54&b=true&a=true"; const init = "a=54&b=true&a=true";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
searchParams.set("c", "foo"); searchParams.set("c", "foo");
assertEquals(searchParams.toString(), "a=54&b=true&a=true&c=foo"); assertEquals(searchParams.toString(), "a=54&b=true&a=true&c=foo");
}); });
unitTest(function urlSearchParamsSortSuccess() { Deno.test(function urlSearchParamsSortSuccess() {
const init = "c=4&a=2&b=3&a=1"; const init = "c=4&a=2&b=3&a=1";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
searchParams.sort(); searchParams.sort();
assertEquals(searchParams.toString(), "a=2&a=1&b=3&c=4"); assertEquals(searchParams.toString(), "a=2&a=1&b=3&c=4");
}); });
unitTest(function urlSearchParamsForEachSuccess() { Deno.test(function urlSearchParamsForEachSuccess() {
const init = [ const init = [
["a", "54"], ["a", "54"],
["b", "true"], ["b", "true"],
@ -180,34 +180,34 @@ unitTest(function urlSearchParamsForEachSuccess() {
assertEquals(callNum, init.length); assertEquals(callNum, init.length);
}); });
unitTest(function urlSearchParamsMissingName() { Deno.test(function urlSearchParamsMissingName() {
const init = "=4"; const init = "=4";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.get(""), "4"); assertEquals(searchParams.get(""), "4");
assertEquals(searchParams.toString(), "=4"); assertEquals(searchParams.toString(), "=4");
}); });
unitTest(function urlSearchParamsMissingValue() { Deno.test(function urlSearchParamsMissingValue() {
const init = "4="; const init = "4=";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.get("4"), "");
assertEquals(searchParams.toString(), "4="); assertEquals(searchParams.toString(), "4=");
}); });
unitTest(function urlSearchParamsMissingEqualSign() { Deno.test(function urlSearchParamsMissingEqualSign() {
const init = "4"; const init = "4";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.get("4"), "");
assertEquals(searchParams.toString(), "4="); assertEquals(searchParams.toString(), "4=");
}); });
unitTest(function urlSearchParamsMissingPair() { Deno.test(function urlSearchParamsMissingPair() {
const init = "c=4&&a=54&"; const init = "c=4&&a=54&";
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.toString(), "c=4&a=54"); assertEquals(searchParams.toString(), "c=4&a=54");
}); });
unitTest(function urlSearchParamsForShortEncodedChar() { Deno.test(function urlSearchParamsForShortEncodedChar() {
const init = { linefeed: "\n", tab: "\t" }; const init = { linefeed: "\n", tab: "\t" };
const searchParams = new URLSearchParams(init); const searchParams = new URLSearchParams(init);
assertEquals(searchParams.toString(), "linefeed=%0A&tab=%09"); assertEquals(searchParams.toString(), "linefeed=%0A&tab=%09");
@ -215,7 +215,7 @@ unitTest(function urlSearchParamsForShortEncodedChar() {
// If pair does not contain exactly two items, then throw a TypeError. // If pair does not contain exactly two items, then throw a TypeError.
// ref https://url.spec.whatwg.org/#interface-urlsearchparams // ref https://url.spec.whatwg.org/#interface-urlsearchparams
unitTest(function urlSearchParamsShouldThrowTypeError() { Deno.test(function urlSearchParamsShouldThrowTypeError() {
let hasThrown = 0; let hasThrown = 0;
try { try {
@ -245,7 +245,7 @@ unitTest(function urlSearchParamsShouldThrowTypeError() {
assertEquals(hasThrown, 2); assertEquals(hasThrown, 2);
}); });
unitTest(function urlSearchParamsAppendArgumentsCheck() { Deno.test(function urlSearchParamsAppendArgumentsCheck() {
const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"]; const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"];
const methodRequireTwoParams = ["append", "set"]; const methodRequireTwoParams = ["append", "set"];
@ -288,7 +288,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck() {
}); });
// ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js
unitTest(function urlSearchParamsDeletingAppendedMultiple() { Deno.test(function urlSearchParamsDeletingAppendedMultiple() {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append("first", (1 as unknown) as string); params.append("first", (1 as unknown) as string);
assert(params.has("first")); assert(params.has("first"));
@ -302,7 +302,7 @@ unitTest(function urlSearchParamsDeletingAppendedMultiple() {
}); });
// ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js#L176-L182 // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js#L176-L182
unitTest(function urlSearchParamsCustomSymbolIterator() { Deno.test(function urlSearchParamsCustomSymbolIterator() {
const params = new URLSearchParams(); const params = new URLSearchParams();
params[Symbol.iterator] = function* (): IterableIterator<[string, string]> { params[Symbol.iterator] = function* (): IterableIterator<[string, string]> {
yield ["a", "b"]; yield ["a", "b"];
@ -311,7 +311,7 @@ unitTest(function urlSearchParamsCustomSymbolIterator() {
assertEquals(params1.get("a"), "b"); assertEquals(params1.get("a"), "b");
}); });
unitTest( Deno.test(
function urlSearchParamsCustomSymbolIteratorWithNonStringParams() { function urlSearchParamsCustomSymbolIteratorWithNonStringParams() {
const params = {}; const params = {};
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
@ -326,7 +326,7 @@ unitTest(
); );
// If a class extends URLSearchParams, override one method should not change another's behavior. // If a class extends URLSearchParams, override one method should not change another's behavior.
unitTest( Deno.test(
function urlSearchParamsOverridingAppendNotChangeConstructorAndSet() { function urlSearchParamsOverridingAppendNotChangeConstructorAndSet() {
let overridedAppendCalled = 0; let overridedAppendCalled = 0;
class CustomSearchParams extends URLSearchParams { class CustomSearchParams extends URLSearchParams {
@ -343,7 +343,7 @@ unitTest(
}, },
); );
unitTest(function urlSearchParamsOverridingEntriesNotChangeForEach() { Deno.test(function urlSearchParamsOverridingEntriesNotChangeForEach() {
class CustomSearchParams extends URLSearchParams { class CustomSearchParams extends URLSearchParams {
*entries(): IterableIterator<[string, string]> { *entries(): IterableIterator<[string, string]> {
yield* []; yield* [];

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertStrictEquals, assertStrictEquals,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest(function urlParsing() { Deno.test(function urlParsing() {
const url = new URL( const url = new URL(
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat",
); );
@ -33,7 +32,7 @@ unitTest(function urlParsing() {
); );
}); });
unitTest(function urlProtocolParsing() { Deno.test(function urlProtocolParsing() {
assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:"); assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:");
assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:"); assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:");
assertThrows(() => new URL("1://foo"), TypeError, "Invalid URL"); assertThrows(() => new URL("1://foo"), TypeError, "Invalid URL");
@ -50,7 +49,7 @@ unitTest(function urlProtocolParsing() {
assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL"); assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL");
}); });
unitTest(function urlAuthenticationParsing() { Deno.test(function urlAuthenticationParsing() {
const specialUrl = new URL("http://foo:bar@baz"); const specialUrl = new URL("http://foo:bar@baz");
assertEquals(specialUrl.username, "foo"); assertEquals(specialUrl.username, "foo");
assertEquals(specialUrl.password, "bar"); assertEquals(specialUrl.password, "bar");
@ -62,7 +61,7 @@ unitTest(function urlAuthenticationParsing() {
assertEquals(nonSpecialUrl.hostname, "baz"); assertEquals(nonSpecialUrl.hostname, "baz");
}); });
unitTest(function urlHostnameParsing() { Deno.test(function urlHostnameParsing() {
// IPv6. // IPv6.
assertEquals(new URL("http://[::1]").hostname, "[::1]"); assertEquals(new URL("http://[::1]").hostname, "[::1]");
assertEquals(new URL("file://[::1]").hostname, "[::1]"); assertEquals(new URL("file://[::1]").hostname, "[::1]");
@ -102,7 +101,7 @@ unitTest(function urlHostnameParsing() {
assertThrows(() => new URL("http://4294967296"), TypeError, "Invalid URL"); assertThrows(() => new URL("http://4294967296"), TypeError, "Invalid URL");
}); });
unitTest(function urlPortParsing() { Deno.test(function urlPortParsing() {
const specialUrl = new URL("http://foo:8000"); const specialUrl = new URL("http://foo:8000");
assertEquals(specialUrl.hostname, "foo"); assertEquals(specialUrl.hostname, "foo");
assertEquals(specialUrl.port, "8000"); assertEquals(specialUrl.port, "8000");
@ -112,7 +111,7 @@ unitTest(function urlPortParsing() {
assertEquals(nonSpecialUrl.port, "8000"); assertEquals(nonSpecialUrl.port, "8000");
}); });
unitTest(function urlModifications() { Deno.test(function urlModifications() {
const url = new URL( const url = new URL(
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat",
); );
@ -167,7 +166,7 @@ unitTest(function urlModifications() {
); );
}); });
unitTest(function urlModifyHref() { Deno.test(function urlModifyHref() {
const url = new URL("http://example.com/"); const url = new URL("http://example.com/");
url.href = "https://foo:bar@example.com:8080/baz/qat#qux"; url.href = "https://foo:bar@example.com:8080/baz/qat#qux";
assertEquals(url.protocol, "https:"); assertEquals(url.protocol, "https:");
@ -179,13 +178,13 @@ unitTest(function urlModifyHref() {
assertEquals(url.hash, "#qux"); assertEquals(url.hash, "#qux");
}); });
unitTest(function urlNormalize() { Deno.test(function urlNormalize() {
const url = new URL("http://example.com"); const url = new URL("http://example.com");
assertEquals(url.pathname, "/"); assertEquals(url.pathname, "/");
assertEquals(url.href, "http://example.com/"); assertEquals(url.href, "http://example.com/");
}); });
unitTest(function urlModifyPathname() { Deno.test(function urlModifyPathname() {
const url = new URL("http://foo.bar/baz%qat/qux%quux"); const url = new URL("http://foo.bar/baz%qat/qux%quux");
assertEquals(url.pathname, "/baz%qat/qux%quux"); assertEquals(url.pathname, "/baz%qat/qux%quux");
// Self-assignment is to invoke the setter. // Self-assignment is to invoke the setter.
@ -201,7 +200,7 @@ unitTest(function urlModifyPathname() {
assertEquals(url.pathname, "/a/b/c"); assertEquals(url.pathname, "/a/b/c");
}); });
unitTest(function urlModifyHash() { Deno.test(function urlModifyHash() {
const url = new URL("http://foo.bar"); const url = new URL("http://foo.bar");
url.hash = "%foo bar/qat%qux#bar"; url.hash = "%foo bar/qat%qux#bar";
assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); assertEquals(url.hash, "#%foo%20bar/qat%qux#bar");
@ -210,7 +209,7 @@ unitTest(function urlModifyHash() {
assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); assertEquals(url.hash, "#%foo%20bar/qat%qux#bar");
}); });
unitTest(function urlSearchParamsReuse() { Deno.test(function urlSearchParamsReuse() {
const url = new URL( const url = new URL(
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat",
); );
@ -219,7 +218,7 @@ unitTest(function urlSearchParamsReuse() {
assert(sp === url.searchParams, "Search params should be reused."); assert(sp === url.searchParams, "Search params should be reused.");
}); });
unitTest(function urlBackSlashes() { Deno.test(function urlBackSlashes() {
const url = new URL( const url = new URL(
"https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat", "https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat",
); );
@ -229,7 +228,7 @@ unitTest(function urlBackSlashes() {
); );
}); });
unitTest(function urlProtocolSlashes() { Deno.test(function urlProtocolSlashes() {
assertEquals(new URL("http:foo").href, "http://foo/"); assertEquals(new URL("http:foo").href, "http://foo/");
assertEquals(new URL("http://foo").href, "http://foo/"); assertEquals(new URL("http://foo").href, "http://foo/");
assertEquals(new URL("file:foo").href, "file:///foo"); assertEquals(new URL("file:foo").href, "file:///foo");
@ -238,7 +237,7 @@ unitTest(function urlProtocolSlashes() {
assertEquals(new URL("abcd://foo").href, "abcd://foo"); assertEquals(new URL("abcd://foo").href, "abcd://foo");
}); });
unitTest(function urlRequireHost() { Deno.test(function urlRequireHost() {
assertEquals(new URL("file:///").href, "file:///"); assertEquals(new URL("file:///").href, "file:///");
assertThrows(() => new URL("ftp:///"), TypeError, "Invalid URL"); assertThrows(() => new URL("ftp:///"), TypeError, "Invalid URL");
assertThrows(() => new URL("http:///"), TypeError, "Invalid URL"); assertThrows(() => new URL("http:///"), TypeError, "Invalid URL");
@ -247,7 +246,7 @@ unitTest(function urlRequireHost() {
assertThrows(() => new URL("wss:///"), TypeError, "Invalid URL"); assertThrows(() => new URL("wss:///"), TypeError, "Invalid URL");
}); });
unitTest(function urlDriveLetter() { Deno.test(function urlDriveLetter() {
assertEquals(new URL("file:///C:").href, "file:///C:"); assertEquals(new URL("file:///C:").href, "file:///C:");
assertEquals(new URL("file:///C:/").href, "file:///C:/"); assertEquals(new URL("file:///C:/").href, "file:///C:/");
assertEquals(new URL("file:///C:/..").href, "file:///C:/"); assertEquals(new URL("file:///C:/..").href, "file:///C:/");
@ -269,28 +268,28 @@ unitTest(function urlDriveLetter() {
// assertEquals(new URL("abcd://foo/C:/..").href, "abcd://foo/"); // assertEquals(new URL("abcd://foo/C:/..").href, "abcd://foo/");
}); });
unitTest(function urlHostnameUpperCase() { Deno.test(function urlHostnameUpperCase() {
assertEquals(new URL("http://EXAMPLE.COM").href, "http://example.com/"); assertEquals(new URL("http://EXAMPLE.COM").href, "http://example.com/");
assertEquals(new URL("abcd://EXAMPLE.COM").href, "abcd://EXAMPLE.COM"); assertEquals(new URL("abcd://EXAMPLE.COM").href, "abcd://EXAMPLE.COM");
}); });
unitTest(function urlEmptyPath() { Deno.test(function urlEmptyPath() {
assertEquals(new URL("http://foo").pathname, "/"); assertEquals(new URL("http://foo").pathname, "/");
assertEquals(new URL("file://foo").pathname, "/"); assertEquals(new URL("file://foo").pathname, "/");
assertEquals(new URL("abcd://foo").pathname, ""); assertEquals(new URL("abcd://foo").pathname, "");
}); });
unitTest(function urlPathRepeatedSlashes() { Deno.test(function urlPathRepeatedSlashes() {
assertEquals(new URL("http://foo//bar//").pathname, "//bar//"); assertEquals(new URL("http://foo//bar//").pathname, "//bar//");
assertEquals(new URL("file://foo///bar//").pathname, "/bar//"); assertEquals(new URL("file://foo///bar//").pathname, "/bar//");
assertEquals(new URL("abcd://foo//bar//").pathname, "//bar//"); assertEquals(new URL("abcd://foo//bar//").pathname, "//bar//");
}); });
unitTest(function urlTrim() { Deno.test(function urlTrim() {
assertEquals(new URL(" http://example.com ").href, "http://example.com/"); assertEquals(new URL(" http://example.com ").href, "http://example.com/");
}); });
unitTest(function urlEncoding() { Deno.test(function urlEncoding() {
assertEquals( assertEquals(
new URL("http://a !$&*()=,;+'\"@example.com").username, new URL("http://a !$&*()=,;+'\"@example.com").username,
"a%20!$&*()%3D,%3B+'%22", "a%20!$&*()%3D,%3B+'%22",
@ -320,7 +319,7 @@ unitTest(function urlEncoding() {
); );
}); });
unitTest(function urlBase() { Deno.test(function urlBase() {
assertEquals(new URL("d", new URL("http://foo/a?b#c")).href, "http://foo/d"); assertEquals(new URL("d", new URL("http://foo/a?b#c")).href, "http://foo/d");
assertEquals(new URL("", "http://foo/a/b?c#d").href, "http://foo/a/b?c"); assertEquals(new URL("", "http://foo/a/b?c#d").href, "http://foo/a/b?c");
@ -362,12 +361,12 @@ unitTest(function urlBase() {
assertEquals(new URL("/foo", "abcd:/").href, "abcd:/foo"); assertEquals(new URL("/foo", "abcd:/").href, "abcd:/foo");
}); });
unitTest(function urlDriveLetterBase() { Deno.test(function urlDriveLetterBase() {
assertEquals(new URL("/b", "file:///C:/a/b").href, "file:///C:/b"); assertEquals(new URL("/b", "file:///C:/a/b").href, "file:///C:/b");
assertEquals(new URL("/D:", "file:///C:/a/b").href, "file:///D:"); assertEquals(new URL("/D:", "file:///C:/a/b").href, "file:///D:");
}); });
unitTest(function urlSameProtocolBase() { Deno.test(function urlSameProtocolBase() {
assertEquals(new URL("http:", "http://foo/a").href, "http://foo/a"); assertEquals(new URL("http:", "http://foo/a").href, "http://foo/a");
assertEquals(new URL("file:", "file://foo/a").href, "file://foo/a"); assertEquals(new URL("file:", "file://foo/a").href, "file://foo/a");
assertEquals(new URL("abcd:", "abcd://foo/a").href, "abcd:"); assertEquals(new URL("abcd:", "abcd://foo/a").href, "abcd:");
@ -377,7 +376,7 @@ unitTest(function urlSameProtocolBase() {
assertEquals(new URL("abcd:b", "abcd://foo/a").href, "abcd:b"); assertEquals(new URL("abcd:b", "abcd://foo/a").href, "abcd:b");
}); });
unitTest(function deletingAllParamsRemovesQuestionMarkFromURL() { Deno.test(function deletingAllParamsRemovesQuestionMarkFromURL() {
const url = new URL("http://example.com/?param1&param2"); const url = new URL("http://example.com/?param1&param2");
url.searchParams.delete("param1"); url.searchParams.delete("param1");
url.searchParams.delete("param2"); url.searchParams.delete("param2");
@ -385,7 +384,7 @@ unitTest(function deletingAllParamsRemovesQuestionMarkFromURL() {
assertEquals(url.search, ""); assertEquals(url.search, "");
}); });
unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL() { Deno.test(function removingNonExistentParamRemovesQuestionMarkFromURL() {
const url = new URL("http://example.com/?"); const url = new URL("http://example.com/?");
assertEquals(url.href, "http://example.com/?"); assertEquals(url.href, "http://example.com/?");
url.searchParams.delete("param1"); url.searchParams.delete("param1");
@ -393,7 +392,7 @@ unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL() {
assertEquals(url.search, ""); assertEquals(url.search, "");
}); });
unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL() { Deno.test(function sortingNonExistentParamRemovesQuestionMarkFromURL() {
const url = new URL("http://example.com/?"); const url = new URL("http://example.com/?");
assertEquals(url.href, "http://example.com/?"); assertEquals(url.href, "http://example.com/?");
url.searchParams.sort(); url.searchParams.sort();
@ -401,7 +400,7 @@ unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL() {
assertEquals(url.search, ""); assertEquals(url.search, "");
}); });
unitTest(function customInspectFunction() { Deno.test(function customInspectFunction() {
const url = new URL("http://example.com/?"); const url = new URL("http://example.com/?");
assertEquals( assertEquals(
Deno.inspect(url), Deno.inspect(url),
@ -421,14 +420,14 @@ unitTest(function customInspectFunction() {
); );
}); });
unitTest(function protocolNotHttpOrFile() { Deno.test(function protocolNotHttpOrFile() {
const url = new URL("about:blank"); const url = new URL("about:blank");
assertEquals(url.href, "about:blank"); assertEquals(url.href, "about:blank");
assertEquals(url.protocol, "about:"); assertEquals(url.protocol, "about:");
assertEquals(url.origin, "null"); assertEquals(url.origin, "null");
}); });
unitTest(function throwForInvalidPortConstructor() { Deno.test(function throwForInvalidPortConstructor() {
const urls = [ const urls = [
// If port is greater than 2^16 1, validation error, return failure. // If port is greater than 2^16 1, validation error, return failure.
`https://baz.qat:${2 ** 16}`, `https://baz.qat:${2 ** 16}`,
@ -447,7 +446,7 @@ unitTest(function throwForInvalidPortConstructor() {
new URL("https://baz.qat:0"); new URL("https://baz.qat:0");
}); });
unitTest(function doNotOverridePortIfInvalid() { Deno.test(function doNotOverridePortIfInvalid() {
const initialPort = "3000"; const initialPort = "3000";
const url = new URL(`https://deno.land:${initialPort}`); const url = new URL(`https://deno.land:${initialPort}`);
// If port is greater than 2^16 1, validation error, return failure. // If port is greater than 2^16 1, validation error, return failure.
@ -455,7 +454,7 @@ unitTest(function doNotOverridePortIfInvalid() {
assertEquals(url.port, initialPort); assertEquals(url.port, initialPort);
}); });
unitTest(function emptyPortForSchemeDefaultPort() { Deno.test(function emptyPortForSchemeDefaultPort() {
const nonDefaultPort = "3500"; const nonDefaultPort = "3500";
const url = new URL("ftp://baz.qat:21"); const url = new URL("ftp://baz.qat:21");
@ -477,7 +476,7 @@ unitTest(function emptyPortForSchemeDefaultPort() {
assertEquals(url2.port, ""); assertEquals(url2.port, "");
}); });
unitTest(function assigningPortPropertyAffectsReceiverOnly() { Deno.test(function assigningPortPropertyAffectsReceiverOnly() {
// Setting `.port` should update only the receiver. // Setting `.port` should update only the receiver.
const u1 = new URL("http://google.com/"); const u1 = new URL("http://google.com/");
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
@ -487,7 +486,7 @@ unitTest(function assigningPortPropertyAffectsReceiverOnly() {
assertStrictEquals(u2.port, "123"); assertStrictEquals(u2.port, "123");
}); });
unitTest(function urlSearchParamsIdentityPreserved() { Deno.test(function urlSearchParamsIdentityPreserved() {
// URLSearchParams identity should not be lost when URL is updated. // URLSearchParams identity should not be lost when URL is updated.
const u = new URL("http://foo.com/"); const u = new URL("http://foo.com/");
const sp1 = u.searchParams; const sp1 = u.searchParams;

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
unitTest(function urlPatternFromString() { Deno.test(function urlPatternFromString() {
const pattern = new URLPattern("https://deno.land/foo/:bar"); const pattern = new URLPattern("https://deno.land/foo/:bar");
assertEquals(pattern.protocol, "https"); assertEquals(pattern.protocol, "https");
assertEquals(pattern.hostname, "deno.land"); assertEquals(pattern.hostname, "deno.land");
@ -15,7 +15,7 @@ unitTest(function urlPatternFromString() {
assertEquals(match.pathname.groups, { bar: "x" }); assertEquals(match.pathname.groups, { bar: "x" });
}); });
unitTest(function urlPatternFromStringWithBase() { Deno.test(function urlPatternFromStringWithBase() {
const pattern = new URLPattern("/foo/:bar", "https://deno.land"); const pattern = new URLPattern("/foo/:bar", "https://deno.land");
assertEquals(pattern.protocol, "https"); assertEquals(pattern.protocol, "https");
assertEquals(pattern.hostname, "deno.land"); assertEquals(pattern.hostname, "deno.land");
@ -29,7 +29,7 @@ unitTest(function urlPatternFromStringWithBase() {
assertEquals(match.pathname.groups, { bar: "x" }); assertEquals(match.pathname.groups, { bar: "x" });
}); });
unitTest(function urlPatternFromInit() { Deno.test(function urlPatternFromInit() {
const pattern = new URLPattern({ const pattern = new URLPattern({
pathname: "/foo/:bar", pathname: "/foo/:bar",
}); });

View file

@ -4,10 +4,9 @@ import {
assertRejects, assertRejects,
assertThrows, assertThrows,
pathToAbsoluteFileUrl, pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function futimeSyncSuccess() { async function futimeSyncSuccess() {
const testDir = await Deno.makeTempDir(); const testDir = await Deno.makeTempDir();
@ -29,7 +28,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function futimeSyncSuccess() { function futimeSyncSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -51,7 +50,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncFileSuccess() { function utimeSyncFileSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -70,7 +69,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncUrlSuccess() { function utimeSyncUrlSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -89,7 +88,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncDirectorySuccess() { function utimeSyncDirectorySuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -104,7 +103,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncDateSuccess() { function utimeSyncDateSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -119,7 +118,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncFileDateSuccess() { function utimeSyncFileDateSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -137,7 +136,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncLargeNumberSuccess() { function utimeSyncLargeNumberSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -154,7 +153,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function utimeSyncNotFound() { function utimeSyncNotFound() {
const atime = 1000; const atime = 1000;
@ -170,7 +169,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
function utimeSyncPerm() { function utimeSyncPerm() {
const atime = 1000; const atime = 1000;
@ -182,7 +181,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeFileSuccess() { async function utimeFileSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -201,7 +200,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeUrlSuccess() { async function utimeUrlSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -220,7 +219,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeDirectorySuccess() { async function utimeDirectorySuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -235,7 +234,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeDateSuccess() { async function utimeDateSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -250,7 +249,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeFileDateSuccess() { async function utimeFileDateSuccess() {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -269,7 +268,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function utimeNotFound() { async function utimeNotFound() {
const atime = 1000; const atime = 1000;
@ -285,7 +284,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
async function utimeSyncPerm() { async function utimeSyncPerm() {
const atime = 1000; const atime = 1000;

View file

@ -1,6 +1,6 @@
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest(function version() { Deno.test(function version() {
const pattern = /^\d+\.\d+\.\d+/; const pattern = /^\d+\.\d+\.\d+/;
assert(pattern.test(Deno.version.deno)); assert(pattern.test(Deno.version.deno));
assert(pattern.test(Deno.version.v8)); assert(pattern.test(Deno.version.v8));

View file

@ -1,4 +1,4 @@
import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertRejects } from "./test_util.ts";
// The following blob can be created by taking the following s-expr and pass // The following blob can be created by taking the following s-expr and pass
// it through wat2wasm. // it through wat2wasm.
@ -17,7 +17,7 @@ const simpleWasm = new Uint8Array([
0x00, 0x20, 0x01, 0x6a, 0x0b 0x00, 0x20, 0x01, 0x6a, 0x0b
]); ]);
unitTest(async function wasmInstantiateWorksWithBuffer() { Deno.test(async function wasmInstantiateWorksWithBuffer() {
const { module, instance } = await WebAssembly.instantiate(simpleWasm); const { module, instance } = await WebAssembly.instantiate(simpleWasm);
assertEquals(WebAssembly.Module.exports(module), [{ assertEquals(WebAssembly.Module.exports(module), [{
name: "add", name: "add",
@ -32,7 +32,7 @@ unitTest(async function wasmInstantiateWorksWithBuffer() {
// V8's default implementation of `WebAssembly.instantiateStreaming()` if you // V8's default implementation of `WebAssembly.instantiateStreaming()` if you
// don't set the WASM streaming callback, is to take a byte source. Here we // don't set the WASM streaming callback, is to take a byte source. Here we
// check that our implementation of the callback disallows it. // check that our implementation of the callback disallows it.
unitTest( Deno.test(
async function wasmInstantiateStreamingFailsWithBuffer() { async function wasmInstantiateStreamingFailsWithBuffer() {
await assertRejects(async () => { await assertRejects(async () => {
await WebAssembly.instantiateStreaming( await WebAssembly.instantiateStreaming(
@ -43,7 +43,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
async function wasmInstantiateStreamingNoContentType() { async function wasmInstantiateStreamingNoContentType() {
await assertRejects( await assertRejects(
async () => { async () => {
@ -56,7 +56,7 @@ unitTest(
}, },
); );
unitTest(async function wasmInstantiateStreaming() { Deno.test(async function wasmInstantiateStreaming() {
let isomorphic = ""; let isomorphic = "";
for (const byte of simpleWasm) { for (const byte of simpleWasm) {
isomorphic += String.fromCharCode(byte); isomorphic += String.fromCharCode(byte);
@ -76,7 +76,7 @@ unitTest(async function wasmInstantiateStreaming() {
assertEquals(add(1, 3), 4); assertEquals(add(1, 3), 4);
}); });
unitTest( Deno.test(
{ permissions: { net: true } }, { permissions: { net: true } },
async function wasmStreamingNonTrivial() { async function wasmStreamingNonTrivial() {
// deno-dom's WASM file is a real-world non-trivial case that gave us // deno-dom's WASM file is a real-world non-trivial case that gave us

View file

@ -1,7 +1,7 @@
import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; import { assert, assertEquals, assertRejects } from "./test_util.ts";
// https://github.com/denoland/deno/issues/11664 // https://github.com/denoland/deno/issues/11664
unitTest(async function testImportArrayBufferKey() { Deno.test(async function testImportArrayBufferKey() {
const subtle = window.crypto.subtle; const subtle = window.crypto.subtle;
assert(subtle); assert(subtle);
@ -22,7 +22,7 @@ unitTest(async function testImportArrayBufferKey() {
}); });
// TODO(@littledivy): Remove this when we enable WPT for sign_verify // TODO(@littledivy): Remove this when we enable WPT for sign_verify
unitTest(async function testSignVerify() { Deno.test(async function testSignVerify() {
const subtle = window.crypto.subtle; const subtle = window.crypto.subtle;
assert(subtle); assert(subtle);
for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) { for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) {
@ -95,7 +95,7 @@ const hashPlainTextVector = [
]; ];
// TODO(@littledivy): Remove this when we enable WPT for encrypt_decrypt // TODO(@littledivy): Remove this when we enable WPT for encrypt_decrypt
unitTest(async function testEncryptDecrypt() { Deno.test(async function testEncryptDecrypt() {
const subtle = window.crypto.subtle; const subtle = window.crypto.subtle;
assert(subtle); assert(subtle);
for ( for (
@ -148,7 +148,7 @@ unitTest(async function testEncryptDecrypt() {
} }
}); });
unitTest(async function testGenerateRSAKey() { Deno.test(async function testGenerateRSAKey() {
const subtle = window.crypto.subtle; const subtle = window.crypto.subtle;
assert(subtle); assert(subtle);
@ -169,7 +169,7 @@ unitTest(async function testGenerateRSAKey() {
assert(keyPair.privateKey.usages.includes("sign")); assert(keyPair.privateKey.usages.includes("sign"));
}); });
unitTest(async function testGenerateHMACKey() { Deno.test(async function testGenerateHMACKey() {
const key = await window.crypto.subtle.generateKey( const key = await window.crypto.subtle.generateKey(
{ {
name: "HMAC", name: "HMAC",
@ -184,7 +184,7 @@ unitTest(async function testGenerateHMACKey() {
assert(key.usages.includes("sign")); assert(key.usages.includes("sign"));
}); });
unitTest(async function testECDSASignVerify() { Deno.test(async function testECDSASignVerify() {
const key = await window.crypto.subtle.generateKey( const key = await window.crypto.subtle.generateKey(
{ {
name: "ECDSA", name: "ECDSA",
@ -215,7 +215,7 @@ unitTest(async function testECDSASignVerify() {
}); });
// Tests the "bad paths" as a temporary replacement for sign_verify/ecdsa WPT. // Tests the "bad paths" as a temporary replacement for sign_verify/ecdsa WPT.
unitTest(async function testECDSASignVerifyFail() { Deno.test(async function testECDSASignVerifyFail() {
const key = await window.crypto.subtle.generateKey( const key = await window.crypto.subtle.generateKey(
{ {
name: "ECDSA", name: "ECDSA",
@ -256,7 +256,7 @@ unitTest(async function testECDSASignVerifyFail() {
}); });
// https://github.com/denoland/deno/issues/11313 // https://github.com/denoland/deno/issues/11313
unitTest(async function testSignRSASSAKey() { Deno.test(async function testSignRSASSAKey() {
const subtle = window.crypto.subtle; const subtle = window.crypto.subtle;
assert(subtle); assert(subtle);
@ -303,7 +303,7 @@ const jwk: JsonWebKey = {
"key_ops": ["sign"], "key_ops": ["sign"],
}; };
unitTest(async function subtleCryptoHmacImportExport() { Deno.test(async function subtleCryptoHmacImportExport() {
const key1 = await crypto.subtle.importKey( const key1 = await crypto.subtle.importKey(
"raw", "raw",
rawKey, rawKey,
@ -353,7 +353,7 @@ unitTest(async function subtleCryptoHmacImportExport() {
}); });
// https://github.com/denoland/deno/issues/12085 // https://github.com/denoland/deno/issues/12085
unitTest(async function generateImportHmacJwk() { Deno.test(async function generateImportHmacJwk() {
const key = await crypto.subtle.generateKey( const key = await crypto.subtle.generateKey(
{ {
name: "HMAC", name: "HMAC",
@ -397,7 +397,7 @@ const pkcs8TestVectors = [
}, },
]; ];
unitTest({ permissions: { read: true } }, async function importRsaPkcs8() { Deno.test({ permissions: { read: true } }, async function importRsaPkcs8() {
const pemHeader = "-----BEGIN PRIVATE KEY-----"; const pemHeader = "-----BEGIN PRIVATE KEY-----";
const pemFooter = "-----END PRIVATE KEY-----"; const pemFooter = "-----END PRIVATE KEY-----";
for (const { pem, hash } of pkcs8TestVectors) { for (const { pem, hash } of pkcs8TestVectors) {
@ -441,7 +441,7 @@ const asn1AlgorithmIdentifier = new Uint8Array([
0x05, 0x00, // NULL 0x05, 0x00, // NULL
]); ]);
unitTest(async function rsaExport() { Deno.test(async function rsaExport() {
for (const algorithm of ["RSASSA-PKCS1-v1_5", "RSA-PSS", "RSA-OAEP"]) { for (const algorithm of ["RSASSA-PKCS1-v1_5", "RSA-PSS", "RSA-OAEP"]) {
const keyPair = await crypto.subtle.generateKey( const keyPair = await crypto.subtle.generateKey(
{ {
@ -489,7 +489,7 @@ unitTest(async function rsaExport() {
} }
}); });
unitTest(async function testHkdfDeriveBits() { Deno.test(async function testHkdfDeriveBits() {
const rawKey = await crypto.getRandomValues(new Uint8Array(16)); const rawKey = await crypto.getRandomValues(new Uint8Array(16));
const key = await crypto.subtle.importKey( const key = await crypto.subtle.importKey(
"raw", "raw",
@ -513,7 +513,7 @@ unitTest(async function testHkdfDeriveBits() {
assertEquals(result.byteLength, 128 / 8); assertEquals(result.byteLength, 128 / 8);
}); });
unitTest(async function testHkdfDeriveBitsWithLargeKeySize() { Deno.test(async function testHkdfDeriveBitsWithLargeKeySize() {
const key = await crypto.subtle.importKey( const key = await crypto.subtle.importKey(
"raw", "raw",
new Uint8Array([0x00]), new Uint8Array([0x00]),
@ -538,7 +538,7 @@ unitTest(async function testHkdfDeriveBitsWithLargeKeySize() {
); );
}); });
unitTest(async function testDeriveKey() { Deno.test(async function testDeriveKey() {
// Test deriveKey // Test deriveKey
const rawKey = await crypto.getRandomValues(new Uint8Array(16)); const rawKey = await crypto.getRandomValues(new Uint8Array(16));
const key = await crypto.subtle.importKey( const key = await crypto.subtle.importKey(
@ -574,7 +574,7 @@ unitTest(async function testDeriveKey() {
assertEquals(algorithm.length, 256); assertEquals(algorithm.length, 256);
}); });
unitTest(async function testAesCbcEncryptDecrypt() { Deno.test(async function testAesCbcEncryptDecrypt() {
const key = await crypto.subtle.generateKey( const key = await crypto.subtle.generateKey(
{ name: "AES-CBC", length: 128 }, { name: "AES-CBC", length: 128 },
true, true,
@ -609,7 +609,7 @@ unitTest(async function testAesCbcEncryptDecrypt() {
}); });
// TODO(@littledivy): Enable WPT when we have importKey support // TODO(@littledivy): Enable WPT when we have importKey support
unitTest(async function testECDH() { Deno.test(async function testECDH() {
const namedCurve = "P-256"; const namedCurve = "P-256";
const keyPair = await crypto.subtle.generateKey( const keyPair = await crypto.subtle.generateKey(
{ {
@ -633,7 +633,7 @@ unitTest(async function testECDH() {
assertEquals(derivedKey.byteLength, 256 / 8); assertEquals(derivedKey.byteLength, 256 / 8);
}); });
unitTest(async function testWrapKey() { Deno.test(async function testWrapKey() {
// Test wrapKey // Test wrapKey
const key = await crypto.subtle.generateKey( const key = await crypto.subtle.generateKey(
{ {
@ -672,7 +672,7 @@ unitTest(async function testWrapKey() {
// Doesn't need to cover all cases. // Doesn't need to cover all cases.
// Only for testing types. // Only for testing types.
unitTest(async function testAesKeyGen() { Deno.test(async function testAesKeyGen() {
const key = await crypto.subtle.generateKey( const key = await crypto.subtle.generateKey(
{ {
name: "AES-GCM", name: "AES-GCM",
@ -691,7 +691,7 @@ unitTest(async function testAesKeyGen() {
assertEquals(algorithm.length, 256); assertEquals(algorithm.length, 256);
}); });
unitTest(async function testDecryptWithInvalidIntializationVector() { Deno.test(async function testDecryptWithInvalidIntializationVector() {
const data = new Uint8Array([42, 42, 42, 42]); const data = new Uint8Array([42, 42, 42, 42]);
const key = await crypto.subtle.generateKey( const key = await crypto.subtle.generateKey(
{ name: "AES-CBC", length: 256 }, { name: "AES-CBC", length: 256 },

View file

@ -1,4 +1,4 @@
import { assert, assertEquals, unitTest } from "./test_util.ts"; import { assert, assertEquals } from "./test_util.ts";
let isCI: boolean; let isCI: boolean;
try { try {
@ -9,7 +9,7 @@ try {
// Skip this test on linux CI, because the vulkan emulator is not good enough // Skip this test on linux CI, because the vulkan emulator is not good enough
// yet, and skip on macOS because these do not have virtual GPUs. // yet, and skip on macOS because these do not have virtual GPUs.
unitTest({ Deno.test({
permissions: { read: true, env: true }, permissions: { read: true, env: true },
ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI, ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI,
}, async function webgpuComputePass() { }, async function webgpuComputePass() {
@ -100,7 +100,7 @@ unitTest({
// Skip this test on linux CI, because the vulkan emulator is not good enough // Skip this test on linux CI, because the vulkan emulator is not good enough
// yet, and skip on macOS because these do not have virtual GPUs. // yet, and skip on macOS because these do not have virtual GPUs.
unitTest({ Deno.test({
permissions: { read: true, env: true }, permissions: { read: true, env: true },
ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI, ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI,
}, async function webgpuHelloTriangle() { }, async function webgpuHelloTriangle() {

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertThrows, unitTest } from "./test_util.ts"; import { assertThrows } from "./test_util.ts";
unitTest(function websocketPermissionless() { Deno.test({ permissions: "none" }, function websocketPermissionless() {
assertThrows( assertThrows(
() => new WebSocket("ws://localhost"), () => new WebSocket("ws://localhost"),
Deno.errors.PermissionDenied, Deno.errors.PermissionDenied,

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, deferred, unitTest } from "./test_util.ts"; import { assertEquals, deferred } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { env: true, read: true } }, { permissions: { env: true, read: true } },
async function workerEnvArrayPermissions() { async function workerEnvArrayPermissions() {
const promise = deferred<boolean[]>(); const promise = deferred<boolean[]>();

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts"; import { assert } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true } }, { permissions: { read: true } },
function utimeSyncFileSuccess() { function utimeSyncFileSuccess() {
const w = new Worker( const w = new Worker(

View file

@ -4,10 +4,9 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeFileSyncSuccess() { function writeFileSyncSuccess() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -21,7 +20,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeFileSyncUrl() { function writeFileSyncUrl() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -40,7 +39,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, function writeFileSyncFail() { Deno.test({ permissions: { write: true } }, function writeFileSyncFail() {
const enc = new TextEncoder(); const enc = new TextEncoder();
const data = enc.encode("Hello"); const data = enc.encode("Hello");
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
@ -50,7 +49,7 @@ unitTest({ permissions: { write: true } }, function writeFileSyncFail() {
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest({ permissions: { write: false } }, function writeFileSyncPerm() { Deno.test({ permissions: { write: false } }, function writeFileSyncPerm() {
const enc = new TextEncoder(); const enc = new TextEncoder();
const data = enc.encode("Hello"); const data = enc.encode("Hello");
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
@ -60,7 +59,7 @@ unitTest({ permissions: { write: false } }, function writeFileSyncPerm() {
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeFileSyncUpdateMode() { function writeFileSyncUpdateMode() {
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -75,7 +74,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeFileSyncCreate() { function writeFileSyncCreate() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -96,7 +95,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeFileSyncAppend() { function writeFileSyncAppend() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -121,7 +120,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileSuccess() { async function writeFileSuccess() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -135,7 +134,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileUrl() { async function writeFileUrl() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -154,7 +153,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileNotFound() { async function writeFileNotFound() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -167,7 +166,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: false } }, { permissions: { read: true, write: false } },
async function writeFilePerm() { async function writeFilePerm() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -180,7 +179,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileUpdateMode() { async function writeFileUpdateMode() {
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -195,7 +194,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileCreate() { async function writeFileCreate() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -216,7 +215,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileAppend() { async function writeFileAppend() {
const enc = new TextEncoder(); const enc = new TextEncoder();
@ -241,7 +240,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileAbortSignal(): Promise<void> { async function writeFileAbortSignal(): Promise<void> {
const ac = new AbortController(); const ac = new AbortController();
@ -260,7 +259,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeFileAbortSignalPreAborted(): Promise<void> { async function writeFileAbortSignalPreAborted(): Promise<void> {
const ac = new AbortController(); const ac = new AbortController();

View file

@ -3,10 +3,9 @@ import {
assertEquals, assertEquals,
assertRejects, assertRejects,
assertThrows, assertThrows,
unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeTextFileSyncSuccess() { function writeTextFileSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test.txt"; const filename = Deno.makeTempDirSync() + "/test.txt";
@ -16,7 +15,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeTextFileSyncByUrl() { function writeTextFileSyncByUrl() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -31,7 +30,7 @@ unitTest(
}, },
); );
unitTest({ permissions: { write: true } }, function writeTextFileSyncFail() { Deno.test({ permissions: { write: true } }, function writeTextFileSyncFail() {
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
// The following should fail because /baddir doesn't exist (hopefully). // The following should fail because /baddir doesn't exist (hopefully).
assertThrows(() => { assertThrows(() => {
@ -39,7 +38,7 @@ unitTest({ permissions: { write: true } }, function writeTextFileSyncFail() {
}, Deno.errors.NotFound); }, Deno.errors.NotFound);
}); });
unitTest({ permissions: { write: false } }, function writeTextFileSyncPerm() { Deno.test({ permissions: { write: false } }, function writeTextFileSyncPerm() {
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
// The following should fail due to no write permission // The following should fail due to no write permission
assertThrows(() => { assertThrows(() => {
@ -47,7 +46,7 @@ unitTest({ permissions: { write: false } }, function writeTextFileSyncPerm() {
}, Deno.errors.PermissionDenied); }, Deno.errors.PermissionDenied);
}); });
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeTextFileSyncUpdateMode() { function writeTextFileSyncUpdateMode() {
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -61,7 +60,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeTextFileSyncCreate() { function writeTextFileSyncCreate() {
const data = "Hello"; const data = "Hello";
@ -83,7 +82,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
function writeTextFileSyncAppend() { function writeTextFileSyncAppend() {
const data = "Hello"; const data = "Hello";
@ -100,7 +99,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileSuccess() { async function writeTextFileSuccess() {
const filename = Deno.makeTempDirSync() + "/test.txt"; const filename = Deno.makeTempDirSync() + "/test.txt";
@ -110,7 +109,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileByUrl() { async function writeTextFileByUrl() {
const tempDir = Deno.makeTempDirSync(); const tempDir = Deno.makeTempDirSync();
@ -125,7 +124,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileNotFound() { async function writeTextFileNotFound() {
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
@ -136,7 +135,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { write: false } }, { permissions: { write: false } },
async function writeTextFilePerm() { async function writeTextFilePerm() {
const filename = "/baddir/test.txt"; const filename = "/baddir/test.txt";
@ -147,7 +146,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileUpdateMode() { async function writeTextFileUpdateMode() {
if (Deno.build.os !== "windows") { if (Deno.build.os !== "windows") {
@ -161,7 +160,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileCreate() { async function writeTextFileCreate() {
const data = "Hello"; const data = "Hello";
@ -183,7 +182,7 @@ unitTest(
}, },
); );
unitTest( Deno.test(
{ permissions: { read: true, write: true } }, { permissions: { read: true, write: true } },
async function writeTextFileAppend() { async function writeTextFileAppend() {
const data = "Hello"; const data = "Hello";