1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Reland "test: run unit tests with DENO_FUTURE=1" (#25212)

Reverted in https://github.com/denoland/deno/pull/25060
This commit is contained in:
Bartek Iwańczuk 2024-08-26 22:58:28 +01:00 committed by GitHub
parent 631d931973
commit ba58628601
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 489 additions and 224 deletions

View file

@ -117,6 +117,10 @@ util::unit_test_factory!(
);
fn js_unit_test(test: String) {
js_unit_test_inner(test, false);
}
pub fn js_unit_test_inner(test: String, future: bool) {
let _g = util::http_server();
let deno = util::deno_cmd()
@ -129,6 +133,12 @@ fn js_unit_test(test: String) {
.arg("--location=http://127.0.0.1:4545/")
.arg("--no-prompt");
let deno = if future {
deno.env("DENO_FUTURE", "1")
} else {
deno
};
// TODO(mmastrac): it would be better to just load a test CA for all tests
let deno = if test == "websocket_test" || test == "tls_sni_test" {
deno.arg("--unsafely-ignore-certificate-errors")

View file

@ -0,0 +1,118 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use super::js_unit_tests::js_unit_test_inner;
use test_util as util;
util::unit_test_factory!(
js_unit_test_future,
"../tests/unit",
"*.ts",
[
abort_controller_test,
blob_test,
body_test,
broadcast_channel_test,
buffer_test,
build_test,
cache_api_test,
chmod_test,
chown_test,
command_test,
console_test,
copy_file_test,
custom_event_test,
cron_test,
dir_test,
dom_exception_test,
error_stack_test,
error_test,
esnext_test,
event_source_test,
event_target_test,
event_test,
fetch_test,
ffi_test,
file_test,
filereader_test,
files_test,
flock_test,
fs_events_test,
get_random_values_test,
globals_test,
headers_test,
http_test,
image_bitmap_test,
image_data_test,
internals_test,
intl_test,
io_test,
jupyter_test,
kv_test,
kv_queue_test_no_db_close,
kv_queue_test,
kv_queue_undelivered_test,
link_test,
make_temp_test,
message_channel_test,
mkdir_test,
navigator_test,
net_test,
network_interfaces_test,
os_test,
ops_test,
path_from_url_test,
performance_test,
permissions_test,
process_test,
progressevent_test,
promise_hooks_test,
read_dir_test,
read_file_test,
read_link_test,
read_text_file_test,
real_path_test,
ref_unref_test,
remove_test,
rename_test,
request_test,
resources_test,
response_test,
serve_test,
signal_test,
stat_test,
stdio_test,
streams_test,
structured_clone_test,
symbol_test,
symlink_test,
sync_test,
test_util,
testing_test,
text_encoding_test,
timers_test,
tls_test,
tls_sni_test,
truncate_test,
tty_color_test,
tty_test,
umask_test,
url_search_params_test,
url_test,
urlpattern_test,
utime_test,
version_test,
wasm_test,
webcrypto_test,
webgpu_test,
websocket_test,
webstorage_test,
worker_permissions_test,
worker_test,
write_file_test,
write_text_file_test,
]
);
fn js_unit_test_future(test: String) {
js_unit_test_inner(test, true);
}

View file

@ -37,6 +37,8 @@ mod inspector;
mod install;
#[path = "js_unit_tests.rs"]
mod js_unit_tests;
#[path = "js_unit_tests_future.rs"]
mod js_unit_tests_future;
#[path = "jsr_tests.rs"]
mod jsr;
#[path = "jupyter_tests.rs"]

View file

@ -10,6 +10,7 @@ import {
assertEquals,
assertRejects,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
import { writeAllSync } from "@std/io/write-all";
@ -87,7 +88,7 @@ function repeat(c: string, bytes: number): Uint8Array {
return ui8;
}
Deno.test(function bufferNewBuffer() {
Deno.test({ ignore: DENO_FUTURE }, function bufferNewBuffer() {
init();
assert(testBytes);
assert(testString);
@ -95,7 +96,7 @@ Deno.test(function bufferNewBuffer() {
check(buf, testString);
});
Deno.test(async function bufferBasicOperations() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferBasicOperations() {
init();
assert(testBytes);
assert(testString);
@ -135,7 +136,7 @@ Deno.test(async function bufferBasicOperations() {
}
});
Deno.test(async function bufferReadEmptyAtEOF() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferReadEmptyAtEOF() {
// 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)
const buf = new Deno.Buffer();
@ -144,7 +145,7 @@ Deno.test(async function bufferReadEmptyAtEOF() {
assertEquals(result, 0);
});
Deno.test(async function bufferLargeByteWrites() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferLargeByteWrites() {
init();
const buf = new Deno.Buffer();
const limit = 9;
@ -155,7 +156,7 @@ Deno.test(async function bufferLargeByteWrites() {
check(buf, "");
});
Deno.test(async function bufferTooLargeByteWrites() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferTooLargeByteWrites() {
init();
const tmp = new Uint8Array(72);
const growLen = Number.MAX_VALUE;
@ -173,7 +174,7 @@ Deno.test(async function bufferTooLargeByteWrites() {
});
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
function bufferGrowWriteMaxBuffer() {
const bufSize = 16 * 1024;
const capacities = [MAX_SIZE, MAX_SIZE - 1];
@ -195,7 +196,7 @@ Deno.test(
);
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
async function bufferGrowReadCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
const buf = new Deno.Buffer();
@ -211,7 +212,7 @@ Deno.test(
);
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
function bufferGrowReadSyncCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
const buf = new Deno.Buffer();
@ -227,7 +228,7 @@ Deno.test(
);
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
function bufferGrowReadSyncCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1];
for (const capacity of capacities) {
@ -241,7 +242,7 @@ Deno.test(
);
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
async function bufferGrowReadCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1];
for (const capacity of capacities) {
@ -254,7 +255,7 @@ Deno.test(
);
Deno.test(
{ ignore: ignoreMaxSizeTests },
{ ignore: ignoreMaxSizeTests || DENO_FUTURE },
async function bufferReadCloseToMaxBufferWithInitialGrow() {
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
for (const capacity of capacities) {
@ -267,7 +268,7 @@ Deno.test(
},
);
Deno.test(async function bufferLargeByteReads() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferLargeByteReads() {
init();
assert(testBytes);
assert(testString);
@ -280,12 +281,12 @@ Deno.test(async function bufferLargeByteReads() {
check(buf, "");
});
Deno.test(function bufferCapWithPreallocatedSlice() {
Deno.test({ ignore: DENO_FUTURE }, function bufferCapWithPreallocatedSlice() {
const buf = new Deno.Buffer(new ArrayBuffer(10));
assertEquals(buf.capacity, 10);
});
Deno.test(async function bufferReadFrom() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferReadFrom() {
init();
assert(testBytes);
assert(testString);
@ -307,7 +308,7 @@ Deno.test(async function bufferReadFrom() {
});
});
Deno.test(async function bufferReadFromSync() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferReadFromSync() {
init();
assert(testBytes);
assert(testString);
@ -329,7 +330,7 @@ Deno.test(async function bufferReadFromSync() {
});
});
Deno.test(async function bufferTestGrow() {
Deno.test({ ignore: DENO_FUTURE }, async function bufferTestGrow() {
const tmp = new Uint8Array(72);
for (const startLen of [0, 100, 1000, 10000]) {
const xBytes = repeat("x", startLen);
@ -353,7 +354,7 @@ Deno.test(async function bufferTestGrow() {
}
});
Deno.test(async function testReadAll() {
Deno.test({ ignore: DENO_FUTURE }, async function testReadAll() {
init();
assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -364,7 +365,7 @@ Deno.test(async function testReadAll() {
}
});
Deno.test(function testReadAllSync() {
Deno.test({ ignore: DENO_FUTURE }, function testReadAllSync() {
init();
assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -375,7 +376,7 @@ Deno.test(function testReadAllSync() {
}
});
Deno.test(async function testWriteAll() {
Deno.test({ ignore: DENO_FUTURE }, async function testWriteAll() {
init();
assert(testBytes);
const writer = new Deno.Buffer();
@ -387,7 +388,7 @@ Deno.test(async function testWriteAll() {
}
});
Deno.test(function testWriteAllSync() {
Deno.test({ ignore: DENO_FUTURE }, function testWriteAllSync() {
init();
assert(testBytes);
const writer = new Deno.Buffer();
@ -399,7 +400,7 @@ Deno.test(function testWriteAllSync() {
}
});
Deno.test(function testBufferBytesArrayBufferLength() {
Deno.test({ ignore: DENO_FUTURE }, function testBufferBytesArrayBufferLength() {
// defaults to copy
const args = [{}, { copy: undefined }, undefined, { copy: true }];
for (const arg of args) {
@ -418,7 +419,7 @@ Deno.test(function testBufferBytesArrayBufferLength() {
}
});
Deno.test(function testBufferBytesCopyFalse() {
Deno.test({ ignore: DENO_FUTURE }, function testBufferBytesCopyFalse() {
const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer();
@ -433,30 +434,36 @@ Deno.test(function testBufferBytesCopyFalse() {
assert(actualBytes.buffer.byteLength > actualBytes.byteLength);
});
Deno.test(function testBufferBytesCopyFalseGrowExactBytes() {
const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer();
writeAllSync(reader, bytes);
Deno.test(
{ ignore: DENO_FUTURE },
function testBufferBytesCopyFalseGrowExactBytes() {
const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer();
writeAllSync(reader, bytes);
const writer = new Deno.Buffer();
writer.grow(bufSize);
writer.readFromSync(reader);
const actualBytes = writer.bytes({ copy: false });
const writer = new Deno.Buffer();
writer.grow(bufSize);
writer.readFromSync(reader);
const actualBytes = writer.bytes({ copy: false });
assertEquals(actualBytes.byteLength, bufSize);
assertEquals(actualBytes.buffer.byteLength, actualBytes.byteLength);
});
assertEquals(actualBytes.byteLength, bufSize);
assertEquals(actualBytes.buffer.byteLength, actualBytes.byteLength);
},
);
Deno.test(function testThrowsErrorWhenBufferExceedsMaxLength() {
const kStringMaxLengthPlusOne = 536870888 + 1;
const bytes = new Uint8Array(kStringMaxLengthPlusOne);
Deno.test(
{ ignore: DENO_FUTURE },
function testThrowsErrorWhenBufferExceedsMaxLength() {
const kStringMaxLengthPlusOne = 536870888 + 1;
const bytes = new Uint8Array(kStringMaxLengthPlusOne);
assertThrows(
() => {
new TextDecoder().decode(bytes);
},
TypeError,
"buffer exceeds maximum length",
);
});
assertThrows(
() => {
new TextDecoder().decode(bytes);
},
TypeError,
"buffer exceeds maximum length",
);
},
);

View file

@ -9,6 +9,7 @@ import {
assertStringIncludes,
assertThrows,
delay,
DENO_FUTURE,
fail,
unimplemented,
} from "./test_util.ts";
@ -1358,7 +1359,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function fetchCustomClientPrivateKey(): Promise<
void
> {

View file

@ -7,6 +7,7 @@ import {
assertEquals,
assertRejects,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
import { copy } from "@std/io/copy";
@ -18,31 +19,37 @@ Deno.test(function filesStdioFileDescriptors() {
assertEquals(Deno.stderr.rid, 2);
});
Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() {
const filename = "tests/testdata/assets/fixture.json";
using file = await Deno.open(filename);
assert(file instanceof Deno.File);
assert(file instanceof Deno.FsFile);
assert(file.rid > 2);
const bytesWritten = await copy(file, Deno.stdout);
const fileSize = Deno.statSync(filename).size;
assertEquals(bytesWritten, fileSize);
});
Deno.test({ permissions: { read: true } }, async function filesIter() {
const filename = "tests/testdata/assets/hello.txt";
using file = await Deno.open(filename);
let totalSize = 0;
for await (const buf of Deno.iter(file)) {
totalSize += buf.byteLength;
}
assertEquals(totalSize, 12);
});
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function filesCopyToStdout() {
const filename = "tests/testdata/assets/fixture.json";
using file = await Deno.open(filename);
assert(file instanceof Deno.File);
assert(file instanceof Deno.FsFile);
assert(file.rid > 2);
const bytesWritten = await copy(file, Deno.stdout);
const fileSize = Deno.statSync(filename).size;
assertEquals(bytesWritten, fileSize);
},
);
Deno.test(
{ permissions: { read: true } },
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function filesIter() {
const filename = "tests/testdata/assets/hello.txt";
using file = await Deno.open(filename);
let totalSize = 0;
for await (const buf of Deno.iter(file)) {
totalSize += buf.byteLength;
}
assertEquals(totalSize, 12);
},
);
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function filesIterCustomBufSize() {
const filename = "tests/testdata/assets/hello.txt";
using file = await Deno.open(filename);
@ -59,20 +66,23 @@ Deno.test(
},
);
Deno.test({ permissions: { read: true } }, function filesIterSync() {
const filename = "tests/testdata/assets/hello.txt";
using file = Deno.openSync(filename);
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
function filesIterSync() {
const filename = "tests/testdata/assets/hello.txt";
using file = Deno.openSync(filename);
let totalSize = 0;
for (const buf of Deno.iterSync(file)) {
totalSize += buf.byteLength;
}
let totalSize = 0;
for (const buf of Deno.iterSync(file)) {
totalSize += buf.byteLength;
}
assertEquals(totalSize, 12);
});
assertEquals(totalSize, 12);
},
);
Deno.test(
{ permissions: { read: true } },
{ ignore: DENO_FUTURE, permissions: { read: true } },
function filesIterSyncCustomBufSize() {
const filename = "tests/testdata/assets/hello.txt";
using file = Deno.openSync(filename);
@ -89,7 +99,7 @@ Deno.test(
},
);
Deno.test(async function readerIter() {
Deno.test({ ignore: DENO_FUTURE }, async function readerIter() {
// ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder();
@ -124,7 +134,7 @@ Deno.test(async function readerIter() {
assertEquals(totalSize, 12);
});
Deno.test(async function readerIterSync() {
Deno.test({ ignore: DENO_FUTURE }, async function readerIterSync() {
// ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder();

View file

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

View file

@ -6,6 +6,7 @@ import {
assertEquals,
assertRejects,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
Deno.test(function globalThisExists() {
@ -19,7 +20,7 @@ Deno.test(function noInternalGlobals() {
}
});
Deno.test(function windowExists() {
Deno.test({ ignore: DENO_FUTURE }, function windowExists() {
assert(window != null);
});
@ -27,15 +28,15 @@ Deno.test(function selfExists() {
assert(self != null);
});
Deno.test(function windowWindowExists() {
Deno.test({ ignore: DENO_FUTURE }, function windowWindowExists() {
assert(window.window === window);
});
Deno.test(function windowSelfExists() {
Deno.test({ ignore: DENO_FUTURE }, function windowSelfExists() {
assert(window.self === window);
});
Deno.test(function globalThisEqualsWindow() {
Deno.test({ ignore: DENO_FUTURE }, function globalThisEqualsWindow() {
assert(globalThis === window);
});
@ -43,7 +44,7 @@ Deno.test(function globalThisEqualsSelf() {
assert(globalThis === self);
});
Deno.test(function globalThisInstanceofWindow() {
Deno.test({ ignore: DENO_FUTURE }, function globalThisInstanceofWindow() {
assert(globalThis instanceof Window);
});
@ -65,7 +66,7 @@ Deno.test(function DenoNamespaceExists() {
assert(Deno != null);
});
Deno.test(function DenoNamespaceEqualsWindowDeno() {
Deno.test({ ignore: DENO_FUTURE }, function DenoNamespaceEqualsWindowDeno() {
assert(Deno === window.Deno);
});
@ -119,7 +120,11 @@ Deno.test(async function windowQueueMicrotask() {
res();
};
});
window.queueMicrotask(resolve1!);
if (DENO_FUTURE) {
globalThis.queueMicrotask(resolve1!);
} else {
window.queueMicrotask(resolve1!);
}
setTimeout(resolve2!, 0);
await p1;
await p2;
@ -138,12 +143,18 @@ Deno.test(function webApiGlobalThis() {
Deno.test(function windowNameIsDefined() {
assertEquals(typeof globalThis.name, "string");
assertEquals(name, "");
assertEquals(window.name, name);
if (!DENO_FUTURE) {
assertEquals(window.name, name);
}
name = "foobar";
assertEquals(window.name, "foobar");
if (!DENO_FUTURE) {
assertEquals(window.name, "foobar");
}
assertEquals(name, "foobar");
name = "";
assertEquals(window.name, "");
if (!DENO_FUTURE) {
assertEquals(window.name, "");
}
assertEquals(name, "");
});

View file

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

View file

@ -6,6 +6,7 @@ import {
assertRejects,
assertThrows,
delay,
DENO_FUTURE,
execCode,
execCode2,
tmpUnixSocketPath,
@ -27,7 +28,9 @@ Deno.test({ permissions: { net: true } }, function netTcpListenClose() {
assert(listener.addr.transport === "tcp");
assertEquals(listener.addr.hostname, "127.0.0.1");
assertEquals(listener.addr.port, listenPort);
assertNotEquals(listener.rid, 0);
if (!DENO_FUTURE) {
assertNotEquals(listener.rid, 0);
}
listener.close();
});
@ -233,7 +236,9 @@ Deno.test({ permissions: { net: true } }, async function netTcpDialListen() {
assertEquals(1, buf[0]);
assertEquals(2, buf[1]);
assertEquals(3, buf[2]);
assert(conn.rid > 0);
if (!DENO_FUTURE) {
assert(conn.rid > 0);
}
assert(readResult !== null);
@ -269,7 +274,9 @@ Deno.test({ permissions: { net: true } }, async function netTcpSetNoDelay() {
assertEquals(1, buf[0]);
assertEquals(2, buf[1]);
assertEquals(3, buf[2]);
assert(conn.rid > 0);
if (!DENO_FUTURE) {
assert(conn.rid > 0);
}
assert(readResult !== null);
@ -305,7 +312,9 @@ Deno.test({ permissions: { net: true } }, async function netTcpSetKeepAlive() {
assertEquals(1, buf[0]);
assertEquals(2, buf[1]);
assertEquals(3, buf[2]);
assert(conn.rid > 0);
if (!DENO_FUTURE) {
assert(conn.rid > 0);
}
assert(readResult !== null);
@ -343,7 +352,9 @@ Deno.test(
assertEquals(1, buf[0]);
assertEquals(2, buf[1]);
assertEquals(3, buf[2]);
assert(conn.rid > 0);
if (!DENO_FUTURE) {
assert(conn.rid > 0);
}
assert(readResult !== null);
@ -839,7 +850,9 @@ Deno.test(
assertEquals(1, buf[0]);
assertEquals(2, buf[1]);
assertEquals(3, buf[2]);
assert(conn.rid > 0);
if (!DENO_FUTURE) {
assert(conn.rid > 0);
}
assert(readResult !== null);

View file

@ -5,6 +5,7 @@ import {
assertStrictEquals,
assertStringIncludes,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
Deno.test(
@ -363,7 +364,11 @@ Deno.test(
);
Deno.test(
{ permissions: { run: true, write: true, read: true } },
{
// Ignoring because uses `file.rid`
ignore: DENO_FUTURE,
permissions: { run: true, write: true, read: true },
},
async function runRedirectStdoutStderr() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
@ -392,11 +397,16 @@ Deno.test(
assertStringIncludes(text, "error");
assertStringIncludes(text, "output");
console.log("finished tgis test");
},
);
Deno.test(
{ permissions: { run: true, write: true, read: true } },
{
// Ignoring because uses `file.rid`
ignore: DENO_FUTURE,
permissions: { run: true, write: true, read: true },
},
async function runRedirectStdin() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";

View file

@ -2,7 +2,12 @@
// deno-lint-ignore-file no-deprecated-deno-api
import { assert, assertEquals, assertThrows } from "./test_util.ts";
import {
assert,
assertEquals,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
const listenPort = 4505;
@ -12,7 +17,7 @@ Deno.test(function resourcesCloseBadArgs() {
}, TypeError);
});
Deno.test(function resourcesStdio() {
Deno.test({ ignore: DENO_FUTURE }, function resourcesStdio() {
const res = Deno.resources();
assertEquals(res[0], "stdin");
@ -20,39 +25,45 @@ Deno.test(function resourcesStdio() {
assertEquals(res[2], "stderr");
});
Deno.test({ permissions: { net: true } }, async function resourcesNet() {
const listener = Deno.listen({ port: listenPort });
const dialerConn = await Deno.connect({ port: listenPort });
const listenerConn = await listener.accept();
Deno.test(
{ ignore: DENO_FUTURE, permissions: { net: true } },
async function resourcesNet() {
const listener = Deno.listen({ port: listenPort });
const dialerConn = await Deno.connect({ port: listenPort });
const listenerConn = await listener.accept();
const res = Deno.resources();
assertEquals(
Object.values(res).filter((r): boolean => r === "tcpListener").length,
1,
);
const tcpStreams = Object.values(res).filter(
(r): boolean => r === "tcpStream",
);
assert(tcpStreams.length >= 2);
const res = Deno.resources();
assertEquals(
Object.values(res).filter((r): boolean => r === "tcpListener").length,
1,
);
const tcpStreams = Object.values(res).filter(
(r): boolean => r === "tcpStream",
);
assert(tcpStreams.length >= 2);
listenerConn.close();
dialerConn.close();
listener.close();
});
listenerConn.close();
dialerConn.close();
listener.close();
},
);
Deno.test({ permissions: { read: true } }, async function resourcesFile() {
const resourcesBefore = Deno.resources();
const f = await Deno.open("tests/testdata/assets/hello.txt");
const resourcesAfter = Deno.resources();
f.close();
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function resourcesFile() {
const resourcesBefore = Deno.resources();
const f = await Deno.open("tests/testdata/assets/hello.txt");
const resourcesAfter = Deno.resources();
f.close();
// check that exactly one new resource (file) was added
assertEquals(
Object.keys(resourcesAfter).length,
Object.keys(resourcesBefore).length + 1,
);
const newRid = +Object.keys(resourcesAfter).find((rid): boolean => {
return !Object.prototype.hasOwnProperty.call(resourcesBefore, rid);
})!;
assertEquals(resourcesAfter[newRid], "fsFile");
});
// check that exactly one new resource (file) was added
assertEquals(
Object.keys(resourcesAfter).length,
Object.keys(resourcesBefore).length + 1,
);
const newRid = +Object.keys(resourcesAfter).find((rid): boolean => {
return !Object.prototype.hasOwnProperty.call(resourcesBefore, rid);
})!;
assertEquals(resourcesAfter[newRid], "fsFile");
},
);

View file

@ -12,6 +12,7 @@ import {
assertThrows,
curlRequest,
curlRequestWithStdErr,
DENO_FUTURE,
execCode,
execCode3,
fail,
@ -19,7 +20,7 @@ import {
} from "./test_util.ts";
// Since these tests may run in parallel, ensure this port is unique to this file
const servePort = 4502;
const servePort = DENO_FUTURE ? 4511 : 4502;
const {
upgradeHttpRaw,

View file

@ -7,34 +7,41 @@ import {
assertEquals,
assertRejects,
assertThrows,
DENO_FUTURE,
pathToAbsoluteFileUrl,
} from "./test_util.ts";
Deno.test({ permissions: { read: true } }, function fstatSyncSuccess() {
using file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
});
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
function fstatSyncSuccess() {
using file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
},
);
Deno.test({ permissions: { read: true } }, async function fstatSuccess() {
using file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
});
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
async function fstatSuccess() {
using file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid);
assert(fileInfo.isFile);
assert(!fileInfo.isSymlink);
assert(!fileInfo.isDirectory);
assert(fileInfo.size);
assert(fileInfo.atime);
assert(fileInfo.mtime);
// The `birthtime` field is not available on Linux before kernel version 4.11.
assert(fileInfo.birthtime || Deno.build.os === "linux");
},
);
Deno.test(
{ permissions: { read: true, write: true } },

View file

@ -1,8 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "./test_util.ts";
import { assertEquals, DENO_FUTURE } from "./test_util.ts";
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
function fdatasyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
using file = Deno.openSync(filename, {
@ -18,7 +18,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
async function fdatasyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
using file = await Deno.open(filename, {
@ -35,7 +35,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
function fsyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt";
using file = Deno.openSync(filename, {
@ -52,7 +52,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
async function fsyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt";
using file = await Deno.open(filename, {

View file

@ -25,6 +25,8 @@ export { delay } from "@std/async/delay";
export { readLines } from "@std/io/read-lines";
export { parseArgs } from "@std/cli/parse-args";
export const DENO_FUTURE = Deno.env.get("DENO_FUTURE") === "1";
export function pathToAbsoluteFileUrl(path: string): URL {
path = resolve(path);

View file

@ -7,6 +7,7 @@ import {
assertEquals,
assertNotEquals,
delay,
DENO_FUTURE,
execCode,
unreachable,
} from "./test_util.ts";
@ -311,11 +312,63 @@ Deno.test(async function timeoutCallbackThis() {
};
setTimeout(obj.foo, 1);
await promise;
assertEquals(capturedThis, window);
if (!DENO_FUTURE) {
assertEquals(capturedThis, window);
} else {
assertEquals(capturedThis, globalThis);
}
});
Deno.test(async function timeoutBindThis() {
const thisCheckPassed = [null, undefined, window, globalThis];
Deno.test({ ignore: DENO_FUTURE }, async function timeoutBindThis() {
const thisCheckPassed = [null, undefined, globalThis, window];
const thisCheckFailed = [
0,
"",
true,
false,
{},
[],
"foo",
() => {},
Object.prototype,
];
for (const thisArg of thisCheckPassed) {
const { promise, resolve } = Promise.withResolvers<void>();
let hasThrown = 0;
try {
setTimeout.call(thisArg, () => resolve(), 1);
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
hasThrown = 2;
} else {
hasThrown = 3;
}
}
await promise;
assertEquals(hasThrown, 1);
}
for (const thisArg of thisCheckFailed) {
let hasThrown = 0;
try {
setTimeout.call(thisArg, () => {}, 1);
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
hasThrown = 2;
} else {
hasThrown = 3;
}
}
assertEquals(hasThrown, 2);
}
});
Deno.test({ ignore: !DENO_FUTURE }, async function timeoutBindThis() {
const thisCheckPassed = [null, undefined, globalThis];
const thisCheckFailed = [
0,

View file

@ -6,6 +6,7 @@ import {
assertRejects,
assertStrictEquals,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";
import { BufReader, BufWriter } from "@std/io";
import { readAll } from "@std/io/read-all";
@ -67,7 +68,7 @@ Deno.test(
);
Deno.test(
{ permissions: { net: true, read: false } },
{ permissions: { net: true, read: false }, ignore: DENO_FUTURE },
async function connectTLSCertFileNoReadPerm() {
await assertRejects(async () => {
await Deno.connectTls({
@ -80,7 +81,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
function listenTLSNonExistentCertKeyFiles() {
const options = {
hostname: "localhost",
@ -106,7 +107,7 @@ Deno.test(
);
Deno.test(
{ permissions: { net: true, read: false } },
{ permissions: { net: true, read: false }, ignore: DENO_FUTURE },
function listenTLSNoReadPerm() {
assertThrows(() => {
Deno.listenTls({
@ -122,6 +123,7 @@ Deno.test(
Deno.test(
{
permissions: { read: true, write: true, net: true },
ignore: DENO_FUTURE,
},
function listenTLSEmptyKeyFile() {
const options = {
@ -219,7 +221,7 @@ Deno.test(
);
const conn = await Deno.connectTls({ hostname, port, caCerts });
assert(conn.rid > 0);
assert(DENO_FUTURE || conn.rid > 0);
const w = new BufWriter(conn);
const r = new BufReader(conn);
const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`;
@ -271,7 +273,7 @@ Deno.test(
);
const conn = await Deno.connectTls({ hostname, port, caCerts });
assert(conn.rid > 0);
assert(DENO_FUTURE || conn.rid > 0);
const w = new BufWriter(conn);
const r = new BufReader(conn);
const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`;
@ -1146,7 +1148,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTLSBadClientCertPrivateKey(): Promise<void> {
await assertRejects(async () => {
await Deno.connectTls({
@ -1162,7 +1164,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTLSBadCertKey(): Promise<void> {
await assertRejects(async () => {
await Deno.connectTls({
@ -1178,7 +1180,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTLSBadPrivateKey(): Promise<void> {
await assertRejects(async () => {
await Deno.connectTls({
@ -1210,7 +1212,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTLSNotPrivateKey(): Promise<void> {
await assertRejects(async () => {
await Deno.connectTls({
@ -1226,7 +1228,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTLSNotKey(): Promise<void> {
await assertRejects(async () => {
await Deno.connectTls({
@ -1242,7 +1244,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectWithClientCert() {
// The test_server running on port 4552 responds with 'PASS' if client
// authentication was successful. Try it by running test_server and
@ -1292,7 +1294,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTlsConflictingCertOptions(): Promise<void> {
await assertRejects(
async () => {
@ -1317,7 +1319,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, net: true } },
{ permissions: { read: true, net: true }, ignore: DENO_FUTURE },
async function connectTlsConflictingKeyOptions(): Promise<void> {
await assertRejects(
async () => {
@ -1635,7 +1637,7 @@ Deno.test(
);
Deno.test(
{ permissions: { net: true, read: true } },
{ ignore: DENO_FUTURE, permissions: { net: true, read: true } },
function listenTLSEcKey() {
const listener = Deno.listenTls({
hostname: "localhost",

View file

@ -2,7 +2,7 @@
// deno-lint-ignore-file no-deprecated-deno-api
import { assert } from "./test_util.ts";
import { assert, DENO_FUTURE } from "./test_util.ts";
// Note tests for Deno.stdin.setRaw is in integration tests.
@ -15,12 +15,15 @@ Deno.test(function consoleSize() {
assert(typeof result.rows !== "undefined");
});
Deno.test({ permissions: { read: true } }, function isatty() {
// CI not under TTY, so cannot test stdin/stdout/stderr.
const f = Deno.openSync("tests/testdata/assets/hello.txt");
assert(!Deno.isatty(f.rid));
f.close();
});
Deno.test(
{ ignore: DENO_FUTURE, permissions: { read: true } },
function isatty() {
// CI not under TTY, so cannot test stdin/stdout/stderr.
const f = Deno.openSync("tests/testdata/assets/hello.txt");
assert(!Deno.isatty(f.rid));
f.close();
},
);
Deno.test(function isattyError() {
let caught = false;

View file

@ -6,11 +6,12 @@ import {
assertEquals,
assertRejects,
assertThrows,
DENO_FUTURE,
pathToAbsoluteFileUrl,
} from "./test_util.ts";
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
async function futimeSyncSuccess() {
const testDir = await Deno.makeTempDir();
const filename = testDir + "/file.txt";
@ -52,7 +53,7 @@ Deno.test(
);
Deno.test(
{ permissions: { read: true, write: true } },
{ ignore: DENO_FUTURE, permissions: { read: true, write: true } },
function futimeSyncSuccess() {
const testDir = Deno.makeTempDirSync();
const filename = testDir + "/file.txt";

View file

@ -9,7 +9,7 @@ import {
// https://github.com/denoland/deno/issues/11664
Deno.test(async function testImportArrayBufferKey() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
// deno-fmt-ignore
@ -29,7 +29,7 @@ Deno.test(async function testImportArrayBufferKey() {
});
Deno.test(async function testSignVerify() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) {
for (
@ -101,7 +101,7 @@ const hashPlainTextVector = [
];
Deno.test(async function testEncryptDecrypt() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
for (
const { hash, plainText } of hashPlainTextVector
@ -154,7 +154,7 @@ Deno.test(async function testEncryptDecrypt() {
});
Deno.test(async function testGenerateRSAKey() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
const keyPair = await subtle.generateKey(
@ -175,7 +175,7 @@ Deno.test(async function testGenerateRSAKey() {
});
Deno.test(async function testGenerateHMACKey() {
const key = await window.crypto.subtle.generateKey(
const key = await globalThis.crypto.subtle.generateKey(
{
name: "HMAC",
hash: "SHA-512",
@ -190,7 +190,7 @@ Deno.test(async function testGenerateHMACKey() {
});
Deno.test(async function testECDSASignVerify() {
const key = await window.crypto.subtle.generateKey(
const key = await globalThis.crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-384",
@ -201,7 +201,7 @@ Deno.test(async function testECDSASignVerify() {
const encoder = new TextEncoder();
const encoded = encoder.encode("Hello, World!");
const signature = await window.crypto.subtle.sign(
const signature = await globalThis.crypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-384" },
key.privateKey,
encoded,
@ -210,7 +210,7 @@ Deno.test(async function testECDSASignVerify() {
assert(signature);
assert(signature instanceof ArrayBuffer);
const verified = await window.crypto.subtle.verify(
const verified = await globalThis.crypto.subtle.verify(
{ hash: { name: "SHA-384" }, name: "ECDSA" },
key.publicKey,
signature,
@ -221,7 +221,7 @@ Deno.test(async function testECDSASignVerify() {
// Tests the "bad paths" as a temporary replacement for sign_verify/ecdsa WPT.
Deno.test(async function testECDSASignVerifyFail() {
const key = await window.crypto.subtle.generateKey(
const key = await globalThis.crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-384",
@ -233,7 +233,7 @@ Deno.test(async function testECDSASignVerifyFail() {
const encoded = new Uint8Array([1]);
// Signing with a public key (InvalidAccessError)
await assertRejects(async () => {
await window.crypto.subtle.sign(
await globalThis.crypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-384" },
key.publicKey,
new Uint8Array([1]),
@ -242,7 +242,7 @@ Deno.test(async function testECDSASignVerifyFail() {
}, DOMException);
// Do a valid sign for later verifying.
const signature = await window.crypto.subtle.sign(
const signature = await globalThis.crypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-384" },
key.privateKey,
encoded,
@ -250,7 +250,7 @@ Deno.test(async function testECDSASignVerifyFail() {
// Verifying with a private key (InvalidAccessError)
await assertRejects(async () => {
await window.crypto.subtle.verify(
await globalThis.crypto.subtle.verify(
{ hash: { name: "SHA-384" }, name: "ECDSA" },
key.privateKey,
signature,
@ -262,7 +262,7 @@ Deno.test(async function testECDSASignVerifyFail() {
// https://github.com/denoland/deno/issues/11313
Deno.test(async function testSignRSASSAKey() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
const keyPair = await subtle.generateKey(
@ -284,7 +284,7 @@ Deno.test(async function testSignRSASSAKey() {
const encoder = new TextEncoder();
const encoded = encoder.encode("Hello, World!");
const signature = await window.crypto.subtle.sign(
const signature = await globalThis.crypto.subtle.sign(
{ name: "RSASSA-PKCS1-v1_5" },
keyPair.privateKey,
encoded,
@ -1056,7 +1056,7 @@ const jwtRSAKeys = {
};
Deno.test(async function testImportRsaJwk() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
for (const [_key, jwkData] of Object.entries(jwtRSAKeys)) {
@ -1496,7 +1496,7 @@ const ecTestKeys = [
];
Deno.test(async function testImportEcSpkiPkcs8() {
const subtle = window.crypto.subtle;
const subtle = globalThis.crypto.subtle;
assert(subtle);
for (