mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
Enable TS strict mode by default (#3899)
Fixes #3324 Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
This commit is contained in:
parent
852823fa50
commit
90125566bb
56 changed files with 314 additions and 179 deletions
|
@ -714,7 +714,7 @@ mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.code
|
.code
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.starts_with(b"console.log(\"Hello World\");"));
|
.starts_with(b"\"use strict\";\nconsole.log(\"Hello World\");"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @ts-nocheck
|
||||||
const importObject = Object.create(null);
|
const importObject = Object.create(null);
|
||||||
//IMPORTS
|
//IMPORTS
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ testPerm({ net: true }, async function bodyMultipartFormData(): Promise<void> {
|
||||||
|
|
||||||
const formData = await body.formData();
|
const formData = await body.formData();
|
||||||
assert(formData.has("field_1"));
|
assert(formData.has("field_1"));
|
||||||
assertEquals(formData.get("field_1").toString(), "value_1 \r\n");
|
assertEquals(formData.get("field_1")!.toString(), "value_1 \r\n");
|
||||||
assert(formData.has("field_2"));
|
assert(formData.has("field_2"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ testPerm({ net: true }, async function bodyURLEncodedFormData(): Promise<void> {
|
||||||
|
|
||||||
const formData = await body.formData();
|
const formData = await body.formData();
|
||||||
assert(formData.has("field_1"));
|
assert(formData.has("field_1"));
|
||||||
assertEquals(formData.get("field_1").toString(), "Hi");
|
assertEquals(formData.get("field_1")!.toString(), "Hi");
|
||||||
assert(formData.has("field_2"));
|
assert(formData.has("field_2"));
|
||||||
assertEquals(formData.get("field_2").toString(), "<Deno>");
|
assertEquals(formData.get("field_2")!.toString(), "<Deno>");
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// This code has been ported almost directly from Go's src/bytes/buffer_test.go
|
// This code has been ported almost directly from Go's src/bytes/buffer_test.go
|
||||||
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
||||||
// https://github.com/golang/go/blob/master/LICENSE
|
// https://github.com/golang/go/blob/master/LICENSE
|
||||||
import { assertEquals, test } from "./test_util.ts";
|
import { assert, assertEquals, test } from "./test_util.ts";
|
||||||
|
|
||||||
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
|
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
|
||||||
type Buffer = Deno.Buffer;
|
type Buffer = Deno.Buffer;
|
||||||
|
@ -78,12 +78,16 @@ function repeat(c: string, bytes: number): Uint8Array {
|
||||||
|
|
||||||
test(function bufferNewBuffer(): void {
|
test(function bufferNewBuffer(): void {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
|
assert(testString);
|
||||||
const buf = new Buffer(testBytes.buffer as ArrayBuffer);
|
const buf = new Buffer(testBytes.buffer as ArrayBuffer);
|
||||||
check(buf, testString);
|
check(buf, testString);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(async function bufferBasicOperations(): Promise<void> {
|
test(async function bufferBasicOperations(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
|
assert(testString);
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
check(buf, "");
|
check(buf, "");
|
||||||
|
@ -134,8 +138,8 @@ test(async function bufferLargeByteWrites(): Promise<void> {
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
const limit = 9;
|
const limit = 9;
|
||||||
for (let i = 3; i < limit; i += 3) {
|
for (let i = 3; i < limit; i += 3) {
|
||||||
const s = await fillBytes(buf, "", 5, testBytes);
|
const s = await fillBytes(buf, "", 5, testBytes!);
|
||||||
await empty(buf, s, new Uint8Array(Math.floor(testString.length / i)));
|
await empty(buf, s, new Uint8Array(Math.floor(testString!.length / i)));
|
||||||
}
|
}
|
||||||
check(buf, "");
|
check(buf, "");
|
||||||
});
|
});
|
||||||
|
@ -161,6 +165,8 @@ test(async function bufferTooLargeByteWrites(): Promise<void> {
|
||||||
|
|
||||||
test(async function bufferLargeByteReads(): Promise<void> {
|
test(async function bufferLargeByteReads(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
|
assert(testString);
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
for (let i = 3; i < 30; i += 3) {
|
for (let i = 3; i < 30; i += 3) {
|
||||||
const n = Math.floor(testBytes.byteLength / i);
|
const n = Math.floor(testBytes.byteLength / i);
|
||||||
|
@ -177,6 +183,8 @@ test(function bufferCapWithPreallocatedSlice(): void {
|
||||||
|
|
||||||
test(async function bufferReadFrom(): Promise<void> {
|
test(async function bufferReadFrom(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
|
assert(testString);
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
for (let i = 3; i < 30; i += 3) {
|
for (let i = 3; i < 30; i += 3) {
|
||||||
const s = await fillBytes(
|
const s = await fillBytes(
|
||||||
|
@ -194,6 +202,8 @@ test(async function bufferReadFrom(): Promise<void> {
|
||||||
|
|
||||||
test(async function bufferReadFromSync(): Promise<void> {
|
test(async function bufferReadFromSync(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
|
assert(testString);
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
for (let i = 3; i < 30; i += 3) {
|
for (let i = 3; i < 30; i += 3) {
|
||||||
const s = await fillBytes(
|
const s = await fillBytes(
|
||||||
|
@ -236,6 +246,7 @@ test(async function bufferTestGrow(): Promise<void> {
|
||||||
|
|
||||||
test(async function testReadAll(): Promise<void> {
|
test(async function testReadAll(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
const reader = new Buffer(testBytes.buffer as ArrayBuffer);
|
const reader = new Buffer(testBytes.buffer as ArrayBuffer);
|
||||||
const actualBytes = await readAll(reader);
|
const actualBytes = await readAll(reader);
|
||||||
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
||||||
|
@ -246,6 +257,7 @@ test(async function testReadAll(): Promise<void> {
|
||||||
|
|
||||||
test(function testReadAllSync(): void {
|
test(function testReadAllSync(): void {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
const reader = new Buffer(testBytes.buffer as ArrayBuffer);
|
const reader = new Buffer(testBytes.buffer as ArrayBuffer);
|
||||||
const actualBytes = readAllSync(reader);
|
const actualBytes = readAllSync(reader);
|
||||||
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
||||||
|
@ -256,6 +268,7 @@ test(function testReadAllSync(): void {
|
||||||
|
|
||||||
test(async function testWriteAll(): Promise<void> {
|
test(async function testWriteAll(): Promise<void> {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
const writer = new Buffer();
|
const writer = new Buffer();
|
||||||
await writeAll(writer, testBytes);
|
await writeAll(writer, testBytes);
|
||||||
const actualBytes = writer.bytes();
|
const actualBytes = writer.bytes();
|
||||||
|
@ -267,6 +280,7 @@ test(async function testWriteAll(): Promise<void> {
|
||||||
|
|
||||||
test(function testWriteAllSync(): void {
|
test(function testWriteAllSync(): void {
|
||||||
init();
|
init();
|
||||||
|
assert(testBytes);
|
||||||
const writer = new Buffer();
|
const writer = new Buffer();
|
||||||
writeAllSync(writer, testBytes);
|
writeAllSync(writer, testBytes);
|
||||||
const actualBytes = writer.bytes();
|
const actualBytes = writer.bytes();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assertEquals } from "./test_util.ts";
|
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
||||||
|
|
||||||
const isNotWindows = Deno.build.os !== "win";
|
const isNotWindows = Deno.build.os !== "win";
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ testPerm({ read: true, write: true }, function chmodSyncSuccess(): void {
|
||||||
// Check success when not on windows
|
// Check success when not on windows
|
||||||
if (isNotWindows) {
|
if (isNotWindows) {
|
||||||
const fileInfo = Deno.statSync(filename);
|
const fileInfo = Deno.statSync(filename);
|
||||||
|
assert(fileInfo.mode);
|
||||||
assertEquals(fileInfo.mode & 0o777, 0o777);
|
assertEquals(fileInfo.mode & 0o777, 0o777);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -35,14 +36,17 @@ if (isNotWindows) {
|
||||||
Deno.symlinkSync(filename, symlinkName);
|
Deno.symlinkSync(filename, symlinkName);
|
||||||
|
|
||||||
let symlinkInfo = Deno.lstatSync(symlinkName);
|
let symlinkInfo = Deno.lstatSync(symlinkName);
|
||||||
|
assert(symlinkInfo.mode);
|
||||||
const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent
|
const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent
|
||||||
|
|
||||||
Deno.chmodSync(symlinkName, 0o777);
|
Deno.chmodSync(symlinkName, 0o777);
|
||||||
|
|
||||||
// Change actual file mode, not symlink
|
// Change actual file mode, not symlink
|
||||||
const fileInfo = Deno.statSync(filename);
|
const fileInfo = Deno.statSync(filename);
|
||||||
|
assert(fileInfo.mode);
|
||||||
assertEquals(fileInfo.mode & 0o777, 0o777);
|
assertEquals(fileInfo.mode & 0o777, 0o777);
|
||||||
symlinkInfo = Deno.lstatSync(symlinkName);
|
symlinkInfo = Deno.lstatSync(symlinkName);
|
||||||
|
assert(symlinkInfo.mode);
|
||||||
assertEquals(symlinkInfo.mode & 0o777, symlinkMode);
|
assertEquals(symlinkInfo.mode & 0o777, symlinkMode);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -86,6 +90,7 @@ testPerm({ read: true, write: true }, async function chmodSuccess(): Promise<
|
||||||
// Check success when not on windows
|
// Check success when not on windows
|
||||||
if (isNotWindows) {
|
if (isNotWindows) {
|
||||||
const fileInfo = Deno.statSync(filename);
|
const fileInfo = Deno.statSync(filename);
|
||||||
|
assert(fileInfo.mode);
|
||||||
assertEquals(fileInfo.mode & 0o777, 0o777);
|
assertEquals(fileInfo.mode & 0o777, 0o777);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -105,14 +110,17 @@ if (isNotWindows) {
|
||||||
Deno.symlinkSync(filename, symlinkName);
|
Deno.symlinkSync(filename, symlinkName);
|
||||||
|
|
||||||
let symlinkInfo = Deno.lstatSync(symlinkName);
|
let symlinkInfo = Deno.lstatSync(symlinkName);
|
||||||
|
assert(symlinkInfo.mode);
|
||||||
const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent
|
const symlinkMode = symlinkInfo.mode & 0o777; // platform dependent
|
||||||
|
|
||||||
await Deno.chmod(symlinkName, 0o777);
|
await Deno.chmod(symlinkName, 0o777);
|
||||||
|
|
||||||
// Just change actual file mode, not symlink
|
// Just change actual file mode, not symlink
|
||||||
const fileInfo = Deno.statSync(filename);
|
const fileInfo = Deno.statSync(filename);
|
||||||
|
assert(fileInfo.mode);
|
||||||
assertEquals(fileInfo.mode & 0o777, 0o777);
|
assertEquals(fileInfo.mode & 0o777, 0o777);
|
||||||
symlinkInfo = Deno.lstatSync(symlinkName);
|
symlinkInfo = Deno.lstatSync(symlinkName);
|
||||||
|
assert(symlinkInfo.mode);
|
||||||
assertEquals(symlinkInfo.mode & 0o777, symlinkMode);
|
assertEquals(symlinkInfo.mode & 0o777, symlinkMode);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -49,8 +49,7 @@ export const defaultBundlerOptions: ts.CompilerOptions = {
|
||||||
export const defaultCompileOptions: ts.CompilerOptions = {
|
export const defaultCompileOptions: ts.CompilerOptions = {
|
||||||
allowJs: true,
|
allowJs: true,
|
||||||
allowNonTsExtensions: true,
|
allowNonTsExtensions: true,
|
||||||
// TODO(#3324) Enable strict mode for user code.
|
strict: true,
|
||||||
// strict: true,
|
|
||||||
checkJs: false,
|
checkJs: false,
|
||||||
esModuleInterop: true,
|
esModuleInterop: true,
|
||||||
module: ts.ModuleKind.ESNext,
|
module: ts.ModuleKind.ESNext,
|
||||||
|
|
|
@ -14,8 +14,8 @@ const customInspect = Deno.symbols.customInspect;
|
||||||
const {
|
const {
|
||||||
Console,
|
Console,
|
||||||
stringifyArgs
|
stringifyArgs
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
} = Deno[Deno.symbols.internal] as any;
|
} = Deno[Deno.symbols.internal];
|
||||||
|
|
||||||
function stringify(...args: unknown[]): string {
|
function stringify(...args: unknown[]): string {
|
||||||
return stringifyArgs(args).replace(/\n$/, "");
|
return stringifyArgs(args).replace(/\n$/, "");
|
||||||
|
@ -306,6 +306,7 @@ test(function consoleTestCallToStringOnLabel(): void {
|
||||||
for (const method of methods) {
|
for (const method of methods) {
|
||||||
let hasCalled = false;
|
let hasCalled = false;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
console[method]({
|
console[method]({
|
||||||
toString(): void {
|
toString(): void {
|
||||||
hasCalled = true;
|
hasCalled = true;
|
||||||
|
@ -451,6 +452,7 @@ test(function consoleGroup(): void {
|
||||||
// console.group with console.warn test
|
// console.group with console.warn test
|
||||||
test(function consoleGroupWarn(): void {
|
test(function consoleGroupWarn(): void {
|
||||||
mockConsole((console, _out, _err, both): void => {
|
mockConsole((console, _out, _err, both): void => {
|
||||||
|
assert(both);
|
||||||
console.warn("1");
|
console.warn("1");
|
||||||
console.group();
|
console.group();
|
||||||
console.warn("2");
|
console.warn("2");
|
||||||
|
@ -694,6 +696,7 @@ test(function consoleDirXml(): void {
|
||||||
test(function consoleTrace(): void {
|
test(function consoleTrace(): void {
|
||||||
mockConsole((console, _out, err): void => {
|
mockConsole((console, _out, err): void => {
|
||||||
console.trace("%s", "custom message");
|
console.trace("%s", "custom message");
|
||||||
|
assert(err);
|
||||||
assert(err.toString().includes("Trace: custom message"));
|
assert(err.toString().includes("Trace: custom message"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { test, assert } from "./test_util.ts";
|
import { test, assert } from "./test_util.ts";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
const { setPrepareStackTrace } = Deno[Deno.symbols.internal] as any;
|
const { setPrepareStackTrace } = Deno[Deno.symbols.internal];
|
||||||
|
|
||||||
interface CallSite {
|
interface CallSite {
|
||||||
getThis(): unknown;
|
getThis(): unknown;
|
||||||
|
|
|
@ -4,8 +4,11 @@ import { test, assertEquals } from "./test_util.ts";
|
||||||
test(function addEventListenerTest(): void {
|
test(function addEventListenerTest(): void {
|
||||||
const document = new EventTarget();
|
const document = new EventTarget();
|
||||||
|
|
||||||
|
// @ts-ignore tests ignoring the type system for resilience
|
||||||
assertEquals(document.addEventListener("x", null, false), undefined);
|
assertEquals(document.addEventListener("x", null, false), undefined);
|
||||||
|
// @ts-ignore
|
||||||
assertEquals(document.addEventListener("x", null, true), undefined);
|
assertEquals(document.addEventListener("x", null, true), undefined);
|
||||||
|
// @ts-ignore
|
||||||
assertEquals(document.addEventListener("x", null), undefined);
|
assertEquals(document.addEventListener("x", null), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,7 +17,7 @@ test(function constructedEventTargetCanBeUsedAsExpected(): void {
|
||||||
const event = new Event("foo", { bubbles: true, cancelable: false });
|
const event = new Event("foo", { bubbles: true, cancelable: false });
|
||||||
let callCount = 0;
|
let callCount = 0;
|
||||||
|
|
||||||
const listener = (e): void => {
|
const listener = (e: Event): void => {
|
||||||
assertEquals(e, event);
|
assertEquals(e, event);
|
||||||
++callCount;
|
++callCount;
|
||||||
};
|
};
|
||||||
|
@ -34,11 +37,19 @@ test(function constructedEventTargetCanBeUsedAsExpected(): void {
|
||||||
|
|
||||||
test(function anEventTargetCanBeSubclassed(): void {
|
test(function anEventTargetCanBeSubclassed(): void {
|
||||||
class NicerEventTarget extends EventTarget {
|
class NicerEventTarget extends EventTarget {
|
||||||
on(type, callback?, options?): void {
|
on(
|
||||||
|
type: string,
|
||||||
|
callback: (e: Event) => void | null,
|
||||||
|
options?: __domTypes.AddEventListenerOptions
|
||||||
|
): void {
|
||||||
this.addEventListener(type, callback, options);
|
this.addEventListener(type, callback, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
off(type, callback?, options?): void {
|
off(
|
||||||
|
type: string,
|
||||||
|
callback: (e: Event) => void | null,
|
||||||
|
options?: __domTypes.EventListenerOptions
|
||||||
|
): void {
|
||||||
this.removeEventListener(type, callback, options);
|
this.removeEventListener(type, callback, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,8 +71,11 @@ test(function anEventTargetCanBeSubclassed(): void {
|
||||||
|
|
||||||
test(function removingNullEventListenerShouldSucceed(): void {
|
test(function removingNullEventListenerShouldSucceed(): void {
|
||||||
const document = new EventTarget();
|
const document = new EventTarget();
|
||||||
|
// @ts-ignore
|
||||||
assertEquals(document.removeEventListener("x", null, false), undefined);
|
assertEquals(document.removeEventListener("x", null, false), undefined);
|
||||||
|
// @ts-ignore
|
||||||
assertEquals(document.removeEventListener("x", null, true), undefined);
|
assertEquals(document.removeEventListener("x", null, true), undefined);
|
||||||
|
// @ts-ignore
|
||||||
assertEquals(document.removeEventListener("x", null), undefined);
|
assertEquals(document.removeEventListener("x", null), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,7 +84,7 @@ test(function constructedEventTargetUseObjectPrototype(): void {
|
||||||
const event = new Event("toString", { bubbles: true, cancelable: false });
|
const event = new Event("toString", { bubbles: true, cancelable: false });
|
||||||
let callCount = 0;
|
let callCount = 0;
|
||||||
|
|
||||||
const listener = (e): void => {
|
const listener = (e: Event): void => {
|
||||||
assertEquals(e, event);
|
assertEquals(e, event);
|
||||||
++callCount;
|
++callCount;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { test, assertEquals, assertNotEquals } from "./test_util.ts";
|
import { test, assertEquals, assert } from "./test_util.ts";
|
||||||
|
|
||||||
test(function eventInitializedWithType(): void {
|
test(function eventInitializedWithType(): void {
|
||||||
const type = "click";
|
const type = "click";
|
||||||
|
@ -70,7 +70,8 @@ test(function eventPreventDefaultSuccess(): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function eventInitializedWithNonStringType(): void {
|
test(function eventInitializedWithNonStringType(): void {
|
||||||
const type = undefined;
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const type: any = undefined;
|
||||||
const event = new Event(type);
|
const event = new Event(type);
|
||||||
|
|
||||||
assertEquals(event.isTrusted, false);
|
assertEquals(event.isTrusted, false);
|
||||||
|
@ -84,12 +85,12 @@ test(function eventInitializedWithNonStringType(): void {
|
||||||
// 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
|
||||||
test(function eventIsTrusted(): void {
|
test(function eventIsTrusted(): void {
|
||||||
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
||||||
assertNotEquals(desc1, undefined);
|
assert(desc1);
|
||||||
assertEquals(typeof desc1.get, "function");
|
assertEquals(typeof desc1.get, "function");
|
||||||
|
|
||||||
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
||||||
assertNotEquals(desc2, undefined);
|
assert(desc2);
|
||||||
assertEquals(typeof desc2.get, "function");
|
assertEquals(typeof desc2!.get, "function");
|
||||||
|
|
||||||
assertEquals(desc1.get, desc2.get);
|
assertEquals(desc1!.get, desc2!.get);
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,7 +54,7 @@ testPerm({ net: true }, async function fetchHeaders(): Promise<void> {
|
||||||
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
|
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
|
||||||
const headers = response.headers;
|
const headers = response.headers;
|
||||||
assertEquals(headers.get("Content-Type"), "application/json");
|
assertEquals(headers.get("Content-Type"), "application/json");
|
||||||
assert(headers.get("Server").startsWith("SimpleHTTP"));
|
assert(headers.get("Server")!.startsWith("SimpleHTTP"));
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function fetchBlob(): Promise<void> {
|
testPerm({ net: true }, async function fetchBlob(): Promise<void> {
|
||||||
|
@ -93,10 +93,10 @@ testPerm({ net: true }, async function responseClone(): Promise<void> {
|
||||||
assert(response !== response1);
|
assert(response !== response1);
|
||||||
assertEquals(response.status, response1.status);
|
assertEquals(response.status, response1.status);
|
||||||
assertEquals(response.statusText, response1.statusText);
|
assertEquals(response.statusText, response1.statusText);
|
||||||
const ab = await response.arrayBuffer();
|
const u8a = new Uint8Array(await response.arrayBuffer());
|
||||||
const ab1 = await response1.arrayBuffer();
|
const u8a1 = new Uint8Array(await response1.arrayBuffer());
|
||||||
for (let i = 0; i < ab.byteLength; i++) {
|
for (let i = 0; i < u8a.byteLength; i++) {
|
||||||
assertEquals(ab[i], ab1[i]);
|
assertEquals(u8a[i], u8a1[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ testPerm({ net: true }, async function fetchMultipartFormDataSuccess(): Promise<
|
||||||
);
|
);
|
||||||
const formData = await response.formData();
|
const formData = await response.formData();
|
||||||
assert(formData.has("field_1"));
|
assert(formData.has("field_1"));
|
||||||
assertEquals(formData.get("field_1").toString(), "value_1 \r\n");
|
assertEquals(formData.get("field_1")!.toString(), "value_1 \r\n");
|
||||||
assert(formData.has("field_2"));
|
assert(formData.has("field_2"));
|
||||||
/* TODO(ry) Re-enable this test once we bring back the global File type.
|
/* TODO(ry) Re-enable this test once we bring back the global File type.
|
||||||
const file = formData.get("field_2") as File;
|
const file = formData.get("field_2") as File;
|
||||||
|
@ -136,9 +136,9 @@ testPerm(
|
||||||
);
|
);
|
||||||
const formData = await response.formData();
|
const formData = await response.formData();
|
||||||
assert(formData.has("field_1"));
|
assert(formData.has("field_1"));
|
||||||
assertEquals(formData.get("field_1").toString(), "Hi");
|
assertEquals(formData.get("field_1")!.toString(), "Hi");
|
||||||
assert(formData.has("field_2"));
|
assert(formData.has("field_2"));
|
||||||
assertEquals(formData.get("field_2").toString(), "<Deno>");
|
assertEquals(formData.get("field_2")!.toString(), "<Deno>");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ testPerm({ net: true }, async function fetchInitStringBody(): Promise<void> {
|
||||||
});
|
});
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
assertEquals(text, data);
|
assertEquals(text, data);
|
||||||
assert(response.headers.get("content-type").startsWith("text/plain"));
|
assert(response.headers.get("content-type")!.startsWith("text/plain"));
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function fetchRequestInitStringBody(): Promise<
|
testPerm({ net: true }, async function fetchRequestInitStringBody(): Promise<
|
||||||
|
@ -220,7 +220,7 @@ testPerm({ net: true }, async function fetchInitURLSearchParamsBody(): Promise<
|
||||||
assertEquals(text, data);
|
assertEquals(text, data);
|
||||||
assert(
|
assert(
|
||||||
response.headers
|
response.headers
|
||||||
.get("content-type")
|
.get("content-type")!
|
||||||
.startsWith("application/x-www-form-urlencoded")
|
.startsWith("application/x-www-form-urlencoded")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -236,7 +236,7 @@ testPerm({ net: true }, async function fetchInitBlobBody(): Promise<void> {
|
||||||
});
|
});
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
assertEquals(text, data);
|
assertEquals(text, data);
|
||||||
assert(response.headers.get("content-type").startsWith("text/javascript"));
|
assert(response.headers.get("content-type")!.startsWith("text/javascript"));
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function fetchUserAgent(): Promise<void> {
|
testPerm({ net: true }, async function fetchUserAgent(): Promise<void> {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { test, assert, assertEquals } from "./test_util.ts";
|
import { test, assert, assertEquals } from "./test_util.ts";
|
||||||
|
|
||||||
function testFirstArgument(arg1, expectedSize): void {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function testFirstArgument(arg1: any[], expectedSize: number): void {
|
||||||
const file = new File(arg1, "name");
|
const file = new File(arg1, "name");
|
||||||
assert(file instanceof File);
|
assert(file instanceof File);
|
||||||
assertEquals(file.name, "name");
|
assertEquals(file.name, "name");
|
||||||
|
@ -76,7 +77,8 @@ test(function fileObjectInFileBits(): void {
|
||||||
testFirstArgument([{}], 15);
|
testFirstArgument([{}], 15);
|
||||||
});
|
});
|
||||||
|
|
||||||
function testSecondArgument(arg2, expectedFileName): void {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function testSecondArgument(arg2: any, expectedFileName: string): void {
|
||||||
const file = new File(["bits"], arg2);
|
const file = new File(["bits"], arg2);
|
||||||
assert(file instanceof File);
|
assert(file instanceof File);
|
||||||
assertEquals(file.name, expectedFileName);
|
assertEquals(file.name, expectedFileName);
|
||||||
|
|
|
@ -157,6 +157,7 @@ testPerm({ write: true }, async function writeNullBufferFailure(): Promise<
|
||||||
// writing null should throw an error
|
// writing null should throw an error
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
await file.write(null);
|
await file.write(null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
|
@ -182,6 +183,7 @@ testPerm(
|
||||||
// reading file into null buffer should throw an error
|
// reading file into null buffer should throw an error
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
await file.read(null);
|
await file.read(null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
|
|
|
@ -36,7 +36,9 @@ test(function formDataParamsGetSuccess(): void {
|
||||||
formData.append("a", "true");
|
formData.append("a", "true");
|
||||||
formData.append("b", "false");
|
formData.append("b", "false");
|
||||||
formData.append("a", "null");
|
formData.append("a", "null");
|
||||||
|
// @ts-ignore
|
||||||
formData.append("d", undefined);
|
formData.append("d", undefined);
|
||||||
|
// @ts-ignore
|
||||||
formData.append("e", null);
|
formData.append("e", null);
|
||||||
assertEquals(formData.get("a"), "true");
|
assertEquals(formData.get("a"), "true");
|
||||||
assertEquals(formData.get("b"), "false");
|
assertEquals(formData.get("b"), "false");
|
||||||
|
@ -63,8 +65,10 @@ test(function formDataParamsSetSuccess(): void {
|
||||||
assertEquals(formData.getAll("b"), ["false"]);
|
assertEquals(formData.getAll("b"), ["false"]);
|
||||||
formData.set("a", "false");
|
formData.set("a", "false");
|
||||||
assertEquals(formData.getAll("a"), ["false"]);
|
assertEquals(formData.getAll("a"), ["false"]);
|
||||||
|
// @ts-ignore
|
||||||
formData.set("d", undefined);
|
formData.set("d", undefined);
|
||||||
assertEquals(formData.get("d"), "undefined");
|
assertEquals(formData.get("d"), "undefined");
|
||||||
|
// @ts-ignore
|
||||||
formData.set("e", null);
|
formData.set("e", null);
|
||||||
assertEquals(formData.get("e"), "null");
|
assertEquals(formData.get("e"), "null");
|
||||||
});
|
});
|
||||||
|
@ -101,15 +105,22 @@ test(function formDataParamsForEachSuccess(): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function formDataParamsArgumentsCheck(): void {
|
test(function formDataParamsArgumentsCheck(): void {
|
||||||
const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"];
|
const methodRequireOneParam = [
|
||||||
|
"delete",
|
||||||
|
"getAll",
|
||||||
|
"get",
|
||||||
|
"has",
|
||||||
|
"forEach"
|
||||||
|
] as const;
|
||||||
|
|
||||||
const methodRequireTwoParams = ["append", "set"];
|
const methodRequireTwoParams = ["append", "set"] as const;
|
||||||
|
|
||||||
methodRequireOneParam.forEach((method): void => {
|
methodRequireOneParam.forEach((method): void => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
let hasThrown = 0;
|
let hasThrown = 0;
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
formData[method]();
|
formData[method]();
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -133,6 +144,7 @@ test(function formDataParamsArgumentsCheck(): void {
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
formData[method]();
|
formData[method]();
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -152,6 +164,7 @@ test(function formDataParamsArgumentsCheck(): void {
|
||||||
hasThrown = 0;
|
hasThrown = 0;
|
||||||
errMsg = "";
|
errMsg = "";
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
formData[method]("foo");
|
formData[method]("foo");
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import { test, assert, assertEquals } from "./test_util.ts";
|
import { test, assert, assertEquals } from "./test_util.ts";
|
||||||
const {
|
const {
|
||||||
stringifyArgs
|
stringifyArgs
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
} = Deno[Deno.symbols.internal] as any;
|
} = Deno[Deno.symbols.internal];
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -13,6 +13,7 @@ test(function newHeaderTest(): void {
|
||||||
new Headers(undefined);
|
new Headers(undefined);
|
||||||
new Headers({});
|
new Headers({});
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
new Headers(null);
|
new Headers(null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -22,14 +23,16 @@ test(function newHeaderTest(): void {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const headerDict = {
|
const headerDict: Record<string, string> = {
|
||||||
name1: "value1",
|
name1: "value1",
|
||||||
name2: "value2",
|
name2: "value2",
|
||||||
name3: "value3",
|
name3: "value3",
|
||||||
|
// @ts-ignore
|
||||||
name4: undefined,
|
name4: undefined,
|
||||||
"Content-Type": "value4"
|
"Content-Type": "value4"
|
||||||
};
|
};
|
||||||
const headerSeq = [];
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const headerSeq: any[] = [];
|
||||||
for (const name in headerDict) {
|
for (const name in headerDict) {
|
||||||
headerSeq.push([name, headerDict[name]]);
|
headerSeq.push([name, headerDict[name]]);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +136,7 @@ test(function headerValuesSuccess(): void {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const headerEntriesDict = {
|
const headerEntriesDict: Record<string, string> = {
|
||||||
name1: "value1",
|
name1: "value1",
|
||||||
Name2: "value2",
|
Name2: "value2",
|
||||||
name: "value3",
|
name: "value3",
|
||||||
|
@ -261,6 +264,7 @@ test(function headerParamsArgumentsCheck(): void {
|
||||||
let hasThrown = 0;
|
let hasThrown = 0;
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
headers[method]();
|
headers[method]();
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -284,6 +288,7 @@ test(function headerParamsArgumentsCheck(): void {
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
headers[method]();
|
headers[method]();
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -303,6 +308,7 @@ test(function headerParamsArgumentsCheck(): void {
|
||||||
hasThrown = 0;
|
hasThrown = 0;
|
||||||
errMsg = "";
|
errMsg = "";
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
headers[method]("foo");
|
headers[method]("foo");
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { test, assert } from "./test_util.ts";
|
||||||
test(function internalsExists(): void {
|
test(function internalsExists(): void {
|
||||||
const {
|
const {
|
||||||
stringifyArgs
|
stringifyArgs
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
} = Deno[Deno.symbols.internal] as any;
|
} = Deno[Deno.symbols.internal];
|
||||||
assert(!!stringifyArgs);
|
assert(!!stringifyArgs);
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,11 +20,8 @@ function setup() {
|
||||||
Base,
|
Base,
|
||||||
// This is using an internal API we don't want published as types, so having
|
// This is using an internal API we don't want published as types, so having
|
||||||
// to cast to any to "trick" TypeScript
|
// to cast to any to "trick" TypeScript
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
DomIterable: (Deno[Deno.symbols.internal] as any).DomIterableMixin(
|
DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol)
|
||||||
Base,
|
|
||||||
dataSymbol
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +49,12 @@ test(function testDomIterable(): void {
|
||||||
|
|
||||||
result = [];
|
result = [];
|
||||||
const scope = {};
|
const scope = {};
|
||||||
function callback(value, key, parent): void {
|
function callback(
|
||||||
|
this: typeof scope,
|
||||||
|
value: number,
|
||||||
|
key: string,
|
||||||
|
parent: typeof domIterable
|
||||||
|
): void {
|
||||||
assertEquals(parent, domIterable);
|
assertEquals(parent, domIterable);
|
||||||
assert(key != null);
|
assert(key != null);
|
||||||
assert(value != null);
|
assert(value != null);
|
||||||
|
@ -72,7 +74,7 @@ test(function testDomIterableScope(): void {
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function checkScope(thisArg: any, expected: any): void {
|
function checkScope(thisArg: any, expected: any): void {
|
||||||
function callback(): void {
|
function callback(this: typeof thisArg): void {
|
||||||
assertEquals(this, expected);
|
assertEquals(this, expected);
|
||||||
}
|
}
|
||||||
domIterable.forEach(callback, thisArg);
|
domIterable.forEach(callback, thisArg);
|
||||||
|
|
|
@ -27,7 +27,7 @@ testPerm({ net: true }, async function netCloseWhileAccept(): Promise<void> {
|
||||||
testPerm({ net: true }, async function netConcurrentAccept(): Promise<void> {
|
testPerm({ net: true }, async function netConcurrentAccept(): Promise<void> {
|
||||||
const listener = Deno.listen({ port: 4502 });
|
const listener = Deno.listen({ port: 4502 });
|
||||||
let acceptErrCount = 0;
|
let acceptErrCount = 0;
|
||||||
const checkErr = (e): void => {
|
const checkErr = (e: Deno.DenoError<Deno.ErrorKind>): void => {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.Other);
|
assertEquals(e.kind, Deno.ErrorKind.Other);
|
||||||
if (e.message === "Listener has been closed") {
|
if (e.message === "Listener has been closed") {
|
||||||
assertEquals(acceptErrCount, 1);
|
assertEquals(acceptErrCount, 1);
|
||||||
|
|
|
@ -56,7 +56,10 @@ if (Deno.build.os === "win") {
|
||||||
// specified in `inputEnv`. The subprocess reads the environment variables
|
// specified in `inputEnv`. The subprocess reads the environment variables
|
||||||
// which are in the keys of `expectedEnv` and writes them to stdout as JSON.
|
// which are in the keys of `expectedEnv` and writes them to stdout as JSON.
|
||||||
// It is then verified that these match with the values of `expectedEnv`.
|
// It is then verified that these match with the values of `expectedEnv`.
|
||||||
const checkChildEnv = async (inputEnv, expectedEnv): Promise<void> => {
|
const checkChildEnv = async (
|
||||||
|
inputEnv: Record<string, string>,
|
||||||
|
expectedEnv: Record<string, string>
|
||||||
|
): Promise<void> => {
|
||||||
const src = `
|
const src = `
|
||||||
console.log(
|
console.log(
|
||||||
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k))
|
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k))
|
||||||
|
@ -249,6 +252,7 @@ testPerm({ env: true }, function getDir(): void {
|
||||||
if (Deno.build.os !== r.os) continue;
|
if (Deno.build.os !== r.os) continue;
|
||||||
if (r.shouldHaveValue) {
|
if (r.shouldHaveValue) {
|
||||||
const d = Deno.dir(s.kind);
|
const d = Deno.dir(s.kind);
|
||||||
|
assert(d);
|
||||||
assert(d.length > 0);
|
assert(d.length > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ testPerm({ run: true }, async function runStdinPiped(): Promise<void> {
|
||||||
args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
|
args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
|
||||||
stdin: "piped"
|
stdin: "piped"
|
||||||
});
|
});
|
||||||
|
assert(p.stdin);
|
||||||
assert(!p.stdout);
|
assert(!p.stdout);
|
||||||
assert(!p.stderr);
|
assert(!p.stderr);
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ testPerm({ run: true }, async function runStdinPiped(): Promise<void> {
|
||||||
const n = await p.stdin.write(msg);
|
const n = await p.stdin.write(msg);
|
||||||
assertEquals(n, msg.byteLength);
|
assertEquals(n, msg.byteLength);
|
||||||
|
|
||||||
p.stdin.close();
|
p.stdin!.close();
|
||||||
|
|
||||||
const status = await p.status();
|
const status = await p.status();
|
||||||
assertEquals(status.success, true);
|
assertEquals(status.success, true);
|
||||||
|
@ -155,16 +156,16 @@ testPerm({ run: true }, async function runStdoutPiped(): Promise<void> {
|
||||||
assert(!p.stderr);
|
assert(!p.stderr);
|
||||||
|
|
||||||
const data = new Uint8Array(10);
|
const data = new Uint8Array(10);
|
||||||
let r = await p.stdout.read(data);
|
let r = await p.stdout!.read(data);
|
||||||
if (r === Deno.EOF) {
|
if (r === Deno.EOF) {
|
||||||
throw new Error("p.stdout.read(...) should not be EOF");
|
throw new Error("p.stdout.read(...) should not be EOF");
|
||||||
}
|
}
|
||||||
assertEquals(r, 5);
|
assertEquals(r, 5);
|
||||||
const s = new TextDecoder().decode(data.subarray(0, r));
|
const s = new TextDecoder().decode(data.subarray(0, r));
|
||||||
assertEquals(s, "hello");
|
assertEquals(s, "hello");
|
||||||
r = await p.stdout.read(data);
|
r = await p.stdout!.read(data);
|
||||||
assertEquals(r, Deno.EOF);
|
assertEquals(r, Deno.EOF);
|
||||||
p.stdout.close();
|
p.stdout!.close();
|
||||||
|
|
||||||
const status = await p.status();
|
const status = await p.status();
|
||||||
assertEquals(status.success, true);
|
assertEquals(status.success, true);
|
||||||
|
@ -182,16 +183,16 @@ testPerm({ run: true }, async function runStderrPiped(): Promise<void> {
|
||||||
assert(!p.stdout);
|
assert(!p.stdout);
|
||||||
|
|
||||||
const data = new Uint8Array(10);
|
const data = new Uint8Array(10);
|
||||||
let r = await p.stderr.read(data);
|
let r = await p.stderr!.read(data);
|
||||||
if (r === Deno.EOF) {
|
if (r === Deno.EOF) {
|
||||||
throw new Error("p.stderr.read should not return EOF here");
|
throw new Error("p.stderr.read should not return EOF here");
|
||||||
}
|
}
|
||||||
assertEquals(r, 5);
|
assertEquals(r, 5);
|
||||||
const s = new TextDecoder().decode(data.subarray(0, r));
|
const s = new TextDecoder().decode(data.subarray(0, r));
|
||||||
assertEquals(s, "hello");
|
assertEquals(s, "hello");
|
||||||
r = await p.stderr.read(data);
|
r = await p.stderr!.read(data);
|
||||||
assertEquals(r, Deno.EOF);
|
assertEquals(r, Deno.EOF);
|
||||||
p.stderr.close();
|
p.stderr!.close();
|
||||||
|
|
||||||
const status = await p.status();
|
const status = await p.status();
|
||||||
assertEquals(status.success, true);
|
assertEquals(status.success, true);
|
||||||
|
@ -307,7 +308,7 @@ testPerm({ run: true }, async function runClose(): Promise<void> {
|
||||||
p.close();
|
p.close();
|
||||||
|
|
||||||
const data = new Uint8Array(10);
|
const data = new Uint8Array(10);
|
||||||
const r = await p.stderr.read(data);
|
const r = await p.stderr!.read(data);
|
||||||
assertEquals(r, Deno.EOF);
|
assertEquals(r, Deno.EOF);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ testPerm({ read: true }, async function resourcesFile(): Promise<void> {
|
||||||
Object.keys(resourcesAfter).length,
|
Object.keys(resourcesAfter).length,
|
||||||
Object.keys(resourcesBefore).length + 1
|
Object.keys(resourcesBefore).length + 1
|
||||||
);
|
);
|
||||||
const newRid = Object.keys(resourcesAfter).find((rid): boolean => {
|
const newRid = +Object.keys(resourcesAfter).find((rid): boolean => {
|
||||||
return !resourcesBefore.hasOwnProperty(rid);
|
return !resourcesBefore.hasOwnProperty(rid);
|
||||||
});
|
})!;
|
||||||
assertEquals(resourcesAfter[newRid], "fsFile");
|
assertEquals(resourcesAfter[newRid], "fsFile");
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
|
||||||
function defer(n: number): Promise<void> {
|
function defer(n: number): Promise<void> {
|
||||||
return new Promise((resolve, _) => {
|
return new Promise((resolve: () => void, _) => {
|
||||||
setTimeout(resolve, n);
|
setTimeout(resolve, n);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,7 @@ if (isWindows) {
|
||||||
const s = Deno.statSync(filename);
|
const s = Deno.statSync(filename);
|
||||||
assert(s.dev !== null);
|
assert(s.dev !== null);
|
||||||
assert(s.ino !== null);
|
assert(s.ino !== null);
|
||||||
assertEquals(s.mode & 0o666, 0o666);
|
assertEquals(s.mode! & 0o666, 0o666);
|
||||||
assertEquals(s.nlink, 2);
|
assertEquals(s.nlink, 2);
|
||||||
assert(s.uid !== null);
|
assert(s.uid !== null);
|
||||||
assert(s.gid !== null);
|
assert(s.gid !== null);
|
||||||
|
|
|
@ -62,7 +62,10 @@ function permissionsMatch(
|
||||||
requiredPerms: Permissions
|
requiredPerms: Permissions
|
||||||
): boolean {
|
): boolean {
|
||||||
for (const permName in processPerms) {
|
for (const permName in processPerms) {
|
||||||
if (processPerms[permName] !== requiredPerms[permName]) {
|
if (
|
||||||
|
processPerms[permName as keyof Permissions] !==
|
||||||
|
requiredPerms[permName as keyof Permissions]
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +305,7 @@ testPerm(
|
||||||
async function assertAllUnitTestFilesImported(): Promise<void> {
|
async function assertAllUnitTestFilesImported(): Promise<void> {
|
||||||
const directoryTestFiles = Deno.readDirSync("./cli/js")
|
const directoryTestFiles = Deno.readDirSync("./cli/js")
|
||||||
.map(k => k.name)
|
.map(k => k.name)
|
||||||
.filter(file => file.endsWith("_test.ts"));
|
.filter(file => file!.endsWith("_test.ts"));
|
||||||
const unitTestsFile: Uint8Array = Deno.readFileSync(
|
const unitTestsFile: Uint8Array = Deno.readFileSync(
|
||||||
"./cli/js/unit_tests.ts"
|
"./cli/js/unit_tests.ts"
|
||||||
);
|
);
|
||||||
|
@ -311,11 +314,11 @@ testPerm(
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter(line => line.startsWith("import") && line.includes("_test.ts"));
|
.filter(line => line.startsWith("import") && line.includes("_test.ts"));
|
||||||
const importedTestFiles = importLines.map(
|
const importedTestFiles = importLines.map(
|
||||||
relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)[1]
|
relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)![1]
|
||||||
);
|
);
|
||||||
|
|
||||||
directoryTestFiles.forEach(dirFile => {
|
directoryTestFiles.forEach(dirFile => {
|
||||||
if (!importedTestFiles.includes(dirFile)) {
|
if (!importedTestFiles.includes(dirFile!)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"cil/js/unit_tests.ts is missing import of test file: cli/js/" +
|
"cil/js/unit_tests.ts is missing import of test file: cli/js/" +
|
||||||
dirFile
|
dirFile
|
||||||
|
|
|
@ -7,21 +7,22 @@ function deferred(): {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
reject: (reason?: any) => void;
|
reject: (reason?: any) => void;
|
||||||
} {
|
} {
|
||||||
let resolve;
|
let resolve: (value?: {} | PromiseLike<{}>) => void;
|
||||||
let reject;
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const promise = new Promise((res, rej): void => {
|
let reject: ((reason?: any) => void) | undefined = undefined;
|
||||||
|
const promise = new Promise<{}>((res, rej): void => {
|
||||||
resolve = res;
|
resolve = res;
|
||||||
reject = rej;
|
reject = rej;
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
promise,
|
promise,
|
||||||
resolve,
|
resolve: resolve!,
|
||||||
reject
|
reject: reject!
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitForMs(ms): Promise<number> {
|
async function waitForMs(ms: number): Promise<number> {
|
||||||
return new Promise((resolve): number => setTimeout(resolve, ms));
|
return new Promise((resolve: () => void): number => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
test(async function timeoutSuccess(): Promise<void> {
|
test(async function timeoutSuccess(): Promise<void> {
|
||||||
|
@ -133,7 +134,7 @@ test(async function intervalCancelSuccess(): Promise<void> {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(async function intervalOrdering(): Promise<void> {
|
test(async function intervalOrdering(): Promise<void> {
|
||||||
const timers = [];
|
const timers: number[] = [];
|
||||||
let timeouts = 0;
|
let timeouts = 0;
|
||||||
function onTimeout(): void {
|
function onTimeout(): void {
|
||||||
++timeouts;
|
++timeouts;
|
||||||
|
|
|
@ -195,7 +195,7 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise<
|
||||||
assertEquals(ok, "OK");
|
assertEquals(ok, "OK");
|
||||||
const headers = await tpr.readMIMEHeader();
|
const headers = await tpr.readMIMEHeader();
|
||||||
assert(headers !== Deno.EOF);
|
assert(headers !== Deno.EOF);
|
||||||
const contentLength = parseInt(headers.get("content-length"));
|
const contentLength = parseInt(headers.get("content-length")!);
|
||||||
const bodyBuf = new Uint8Array(contentLength);
|
const bodyBuf = new Uint8Array(contentLength);
|
||||||
await r.readFull(bodyBuf);
|
await r.readFull(bodyBuf);
|
||||||
assertEquals(decoder.decode(bodyBuf), "Hello World\n");
|
assertEquals(decoder.decode(bodyBuf), "Hello World\n");
|
||||||
|
|
|
@ -177,6 +177,7 @@ test(function urlSearchParamsAppendArgumentsCheck(): void {
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
let hasThrown = 0;
|
let hasThrown = 0;
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
searchParams[method]();
|
searchParams[method]();
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -193,6 +194,7 @@ test(function urlSearchParamsAppendArgumentsCheck(): void {
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
let hasThrown = 0;
|
let hasThrown = 0;
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
searchParams[method]("foo");
|
searchParams[method]("foo");
|
||||||
hasThrown = 1;
|
hasThrown = 1;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -232,6 +234,7 @@ test(function urlSearchParamsCustomSymbolIterator(): void {
|
||||||
|
|
||||||
test(function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
|
test(function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
// @ts-ignore
|
||||||
params[Symbol.iterator] = function*(): IterableIterator<[number, number]> {
|
params[Symbol.iterator] = function*(): IterableIterator<[number, number]> {
|
||||||
yield [1, 2];
|
yield [1, 2];
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { testPerm, assert, assertEquals } from "./test_util.ts";
|
||||||
|
|
||||||
// Allow 10 second difference.
|
// Allow 10 second difference.
|
||||||
// Note this might not be enough for FAT (but we are not testing on such fs).
|
// Note this might not be enough for FAT (but we are not testing on such fs).
|
||||||
function assertFuzzyTimestampEquals(t1: number, t2: number): void {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function assertFuzzyTimestampEquals(t1: any, t2: number): void {
|
||||||
|
assert(typeof t1 === "number");
|
||||||
assert(Math.abs(t1 - t2) < 10);
|
assert(Math.abs(t1 - t2) < 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ testPerm({ read: true, write: true }, function writeFileSyncUpdatePerm(): void {
|
||||||
const data = enc.encode("Hello");
|
const data = enc.encode("Hello");
|
||||||
const filename = Deno.makeTempDirSync() + "/test.txt";
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
||||||
Deno.writeFileSync(filename, data, { perm: 0o755 });
|
Deno.writeFileSync(filename, data, { perm: 0o755 });
|
||||||
assertEquals(Deno.statSync(filename).mode & 0o777, 0o755);
|
assertEquals(Deno.statSync(filename).mode! & 0o777, 0o755);
|
||||||
Deno.writeFileSync(filename, data, { perm: 0o666 });
|
Deno.writeFileSync(filename, data, { perm: 0o666 });
|
||||||
assertEquals(Deno.statSync(filename).mode & 0o777, 0o666);
|
assertEquals(Deno.statSync(filename).mode! & 0o777, 0o666);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -161,9 +161,9 @@ testPerm(
|
||||||
const data = enc.encode("Hello");
|
const data = enc.encode("Hello");
|
||||||
const filename = Deno.makeTempDirSync() + "/test.txt";
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
||||||
await Deno.writeFile(filename, data, { perm: 0o755 });
|
await Deno.writeFile(filename, data, { perm: 0o755 });
|
||||||
assertEquals(Deno.statSync(filename).mode & 0o777, 0o755);
|
assertEquals(Deno.statSync(filename).mode! & 0o777, 0o755);
|
||||||
await Deno.writeFile(filename, data, { perm: 0o666 });
|
await Deno.writeFile(filename, data, { perm: 0o666 });
|
||||||
assertEquals(Deno.statSync(filename).mode & 0o777, 0o666);
|
assertEquals(Deno.statSync(filename).mode! & 0o777, 0o666);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
declare namespace JSX {
|
||||||
|
interface IntrinsicElements {
|
||||||
|
[elemName: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
const React = {
|
const React = {
|
||||||
createElement(factory: any, props: any, ...children: any[]) {
|
createElement(factory: any, props: any, ...children: any[]) {
|
||||||
return {factory, props, children}
|
return {factory, props, children}
|
||||||
|
|
|
@ -10,6 +10,16 @@ import { loaded as loadedJsx2 } from "http://localhost:4545/cli/tests/subdir/mt_
|
||||||
import { loaded as loadedJsx3 } from "http://localhost:4545/cli/tests/subdir/mt_text_ecmascript_jsx.j3.jsx";
|
import { loaded as loadedJsx3 } from "http://localhost:4545/cli/tests/subdir/mt_text_ecmascript_jsx.j3.jsx";
|
||||||
import { loaded as loadedJsx4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_javascript_jsx.j4.jsx";
|
import { loaded as loadedJsx4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_javascript_jsx.j4.jsx";
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
namespace JSX {
|
||||||
|
interface IntrinsicElements {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
[elemName: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
"success",
|
"success",
|
||||||
loadedTsx1,
|
loadedTsx1,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { encode, decode } from "./base32.ts";
|
||||||
|
|
||||||
// Lifted from https://stackoverflow.com/questions/38987784
|
// Lifted from https://stackoverflow.com/questions/38987784
|
||||||
const fromHexString = (hexString: string): Uint8Array =>
|
const fromHexString = (hexString: string): Uint8Array =>
|
||||||
new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
|
||||||
const toHexString = (bytes: Uint8Array): string =>
|
const toHexString = (bytes: Uint8Array): string =>
|
||||||
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ function chkOptions(opt: ReadOptions): void {
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
INVALID_RUNE.includes(opt.comma) ||
|
INVALID_RUNE.includes(opt.comma) ||
|
||||||
INVALID_RUNE.includes(opt.comment) ||
|
(typeof opt.comment === "string" && INVALID_RUNE.includes(opt.comment)) ||
|
||||||
opt.comma === opt.comment
|
opt.comma === opt.comment
|
||||||
) {
|
) {
|
||||||
throw new Error("Invalid Delimiter");
|
throw new Error("Invalid Delimiter");
|
||||||
|
@ -122,7 +122,7 @@ export async function readMatrix(
|
||||||
}
|
}
|
||||||
): Promise<string[][]> {
|
): Promise<string[][]> {
|
||||||
const result: string[][] = [];
|
const result: string[][] = [];
|
||||||
let _nbFields: number;
|
let _nbFields: number | undefined;
|
||||||
let lineResult: string[];
|
let lineResult: string[];
|
||||||
let first = true;
|
let first = true;
|
||||||
let lineIndex = 0;
|
let lineIndex = 0;
|
||||||
|
@ -253,8 +253,10 @@ export async function parse(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (opt.parse) {
|
if (opt.parse) {
|
||||||
assert(opt.parse != null, "opt.parse must be set");
|
return r.map((e: string[]): unknown => {
|
||||||
return r.map((e: string[]): unknown => opt.parse(e));
|
assert(opt.parse, "opt.parse must be set");
|
||||||
|
return opt.parse(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,26 +476,32 @@ for (const t of testCases) {
|
||||||
if (t.Error) {
|
if (t.Error) {
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
actual = await readMatrix(new BufReader(new StringReader(t.Input)), {
|
actual = await readMatrix(
|
||||||
comma: comma,
|
new BufReader(new StringReader(t.Input ?? "")),
|
||||||
comment: comment,
|
{
|
||||||
trimLeadingSpace: trim,
|
comma: comma,
|
||||||
fieldsPerRecord: fieldsPerRec,
|
comment: comment,
|
||||||
lazyQuotes: lazyquote
|
trimLeadingSpace: trim,
|
||||||
});
|
fieldsPerRecord: fieldsPerRec,
|
||||||
|
lazyQuotes: lazyquote
|
||||||
|
}
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(err);
|
assert(err);
|
||||||
assertEquals(err.message, t.Error);
|
assertEquals(err.message, t.Error);
|
||||||
} else {
|
} else {
|
||||||
actual = await readMatrix(new BufReader(new StringReader(t.Input)), {
|
actual = await readMatrix(
|
||||||
comma: comma,
|
new BufReader(new StringReader(t.Input ?? "")),
|
||||||
comment: comment,
|
{
|
||||||
trimLeadingSpace: trim,
|
comma: comma,
|
||||||
fieldsPerRecord: fieldsPerRec,
|
comment: comment,
|
||||||
lazyQuotes: lazyquote
|
trimLeadingSpace: trim,
|
||||||
});
|
fieldsPerRecord: fieldsPerRec,
|
||||||
|
lazyQuotes: lazyquote
|
||||||
|
}
|
||||||
|
);
|
||||||
const expected = t.Output;
|
const expected = t.Output;
|
||||||
assertEquals(actual, expected);
|
assertEquals(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ interface DirectiveHandlers {
|
||||||
[directive: string]: (
|
[directive: string]: (
|
||||||
state: LoaderState,
|
state: LoaderState,
|
||||||
name: string,
|
name: string,
|
||||||
...args: unknown[]
|
...args: string[]
|
||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ function storeMappingPair(
|
||||||
mergeMappings(state, result, valueNode[index], overridableKeys);
|
mergeMappings(state, result, valueNode[index], overridableKeys);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mergeMappings(state, result, valueNode, overridableKeys);
|
mergeMappings(state, result, valueNode as ArrayObject, overridableKeys);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
|
@ -1610,7 +1610,7 @@ function readDocument(state: LoaderState): void {
|
||||||
const documentStart = state.position;
|
const documentStart = state.position;
|
||||||
let position: number,
|
let position: number,
|
||||||
directiveName: string,
|
directiveName: string,
|
||||||
directiveArgs: unknown[],
|
directiveArgs: string[],
|
||||||
hasDirectives = false,
|
hasDirectives = false,
|
||||||
ch: number;
|
ch: number;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ if (parsedArgs._.length === 0) {
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = {};
|
const files: Record<string, { content: string }> = {};
|
||||||
for (const filename of parsedArgs._) {
|
for (const filename of parsedArgs._) {
|
||||||
const base = pathBase(filename);
|
const base = pathBase(filename);
|
||||||
const content = await Deno.readFile(filename);
|
const content = await Deno.readFile(filename);
|
||||||
|
|
|
@ -85,6 +85,8 @@ async function copyFile(
|
||||||
await Deno.copyFile(src, dest);
|
await Deno.copyFile(src, dest);
|
||||||
if (options.preserveTimestamps) {
|
if (options.preserveTimestamps) {
|
||||||
const statInfo = await Deno.stat(src);
|
const statInfo = await Deno.stat(src);
|
||||||
|
assert(statInfo.accessed != null, `statInfo.accessed is unavailable`);
|
||||||
|
assert(statInfo.modified != null, `statInfo.modified is unavailable`);
|
||||||
await Deno.utime(dest, statInfo.accessed, statInfo.modified);
|
await Deno.utime(dest, statInfo.accessed, statInfo.modified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import {
|
import {
|
||||||
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertStrContains,
|
assertStrContains,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
|
@ -225,6 +226,8 @@ Deno.test(async function emptyDirPermission(): Promise<void> {
|
||||||
args: args
|
args: args
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert(stdout);
|
||||||
|
|
||||||
const output = await Deno.readAll(stdout);
|
const output = await Deno.readAll(stdout);
|
||||||
|
|
||||||
assertStrContains(new TextDecoder().decode(output), s.output);
|
assertStrContains(new TextDecoder().decode(output), s.output);
|
||||||
|
|
|
@ -131,7 +131,7 @@ Deno.test(async function existsPermission(): Promise<void> {
|
||||||
args: args
|
args: args
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = await Deno.readAll(stdout);
|
const output = await Deno.readAll(stdout!);
|
||||||
|
|
||||||
assertStrContains(new TextDecoder().decode(output), s.output);
|
assertStrContains(new TextDecoder().decode(output), s.output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,9 @@ export async function* walk(
|
||||||
includeFiles = true,
|
includeFiles = true,
|
||||||
includeDirs = true,
|
includeDirs = true,
|
||||||
followSymlinks = false,
|
followSymlinks = false,
|
||||||
exts = null,
|
exts = undefined,
|
||||||
match = null,
|
match = undefined,
|
||||||
skip = null
|
skip = undefined
|
||||||
}: WalkOptions = {}
|
}: WalkOptions = {}
|
||||||
): AsyncIterableIterator<WalkInfo> {
|
): AsyncIterableIterator<WalkInfo> {
|
||||||
if (maxDepth < 0) {
|
if (maxDepth < 0) {
|
||||||
|
@ -76,7 +76,7 @@ export async function* walk(
|
||||||
if (includeDirs && include(root, exts, match, skip)) {
|
if (includeDirs && include(root, exts, match, skip)) {
|
||||||
yield { filename: root, info: await stat(root) };
|
yield { filename: root, info: await stat(root) };
|
||||||
}
|
}
|
||||||
if (maxDepth < 1 || !include(root, null, null, skip)) {
|
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ls: FileInfo[] = await readDir(root);
|
const ls: FileInfo[] = await readDir(root);
|
||||||
|
@ -119,9 +119,9 @@ export function* walkSync(
|
||||||
includeFiles = true,
|
includeFiles = true,
|
||||||
includeDirs = true,
|
includeDirs = true,
|
||||||
followSymlinks = false,
|
followSymlinks = false,
|
||||||
exts = null,
|
exts = undefined,
|
||||||
match = null,
|
match = undefined,
|
||||||
skip = null
|
skip = undefined
|
||||||
}: WalkOptions = {}
|
}: WalkOptions = {}
|
||||||
): IterableIterator<WalkInfo> {
|
): IterableIterator<WalkInfo> {
|
||||||
if (maxDepth < 0) {
|
if (maxDepth < 0) {
|
||||||
|
@ -130,7 +130,7 @@ export function* walkSync(
|
||||||
if (includeDirs && include(root, exts, match, skip)) {
|
if (includeDirs && include(root, exts, match, skip)) {
|
||||||
yield { filename: root, info: statSync(root) };
|
yield { filename: root, info: statSync(root) };
|
||||||
}
|
}
|
||||||
if (maxDepth < 1 || !include(root, null, null, skip)) {
|
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ls: FileInfo[] = readDirSync(root);
|
const ls: FileInfo[] = readDirSync(root);
|
||||||
|
|
|
@ -45,7 +45,7 @@ function toString(cookie: Cookie): string {
|
||||||
if (cookie.httpOnly) {
|
if (cookie.httpOnly) {
|
||||||
out.push("HttpOnly");
|
out.push("HttpOnly");
|
||||||
}
|
}
|
||||||
if (Number.isInteger(cookie.maxAge)) {
|
if (typeof cookie.maxAge === "number" && Number.isInteger(cookie.maxAge)) {
|
||||||
assert(cookie.maxAge > 0, "Max-Age must be an integer superior to 0");
|
assert(cookie.maxAge > 0, "Max-Age must be an integer superior to 0");
|
||||||
out.push(`Max-Age=${cookie.maxAge}`);
|
out.push(`Max-Age=${cookie.maxAge}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
Response
|
Response
|
||||||
} from "./server.ts";
|
} from "./server.ts";
|
||||||
import { parse } from "../flags/mod.ts";
|
import { parse } from "../flags/mod.ts";
|
||||||
|
import { assert } from "../testing/asserts.ts";
|
||||||
|
|
||||||
interface EntryInfo {
|
interface EntryInfo {
|
||||||
mode: string;
|
mode: string;
|
||||||
|
@ -40,10 +41,10 @@ const encoder = new TextEncoder();
|
||||||
const serverArgs = parse(args) as FileServerArgs;
|
const serverArgs = parse(args) as FileServerArgs;
|
||||||
|
|
||||||
const CORSEnabled = serverArgs.cors ? true : false;
|
const CORSEnabled = serverArgs.cors ? true : false;
|
||||||
const target = posix.resolve(serverArgs._[1] || "");
|
const target = posix.resolve(serverArgs._[1] ?? "");
|
||||||
const addr = `0.0.0.0:${serverArgs.port || serverArgs.p || 4500}`;
|
const addr = `0.0.0.0:${serverArgs.port ?? serverArgs.p ?? 4500}`;
|
||||||
|
|
||||||
if (serverArgs.h || serverArgs.help) {
|
if (serverArgs.h ?? serverArgs.help) {
|
||||||
console.log(`Deno File Server
|
console.log(`Deno File Server
|
||||||
Serves a local directory in HTTP.
|
Serves a local directory in HTTP.
|
||||||
|
|
||||||
|
@ -125,8 +126,8 @@ async function serveDir(
|
||||||
const listEntry: EntryInfo[] = [];
|
const listEntry: EntryInfo[] = [];
|
||||||
const fileInfos = await readDir(dirPath);
|
const fileInfos = await readDir(dirPath);
|
||||||
for (const fileInfo of fileInfos) {
|
for (const fileInfo of fileInfos) {
|
||||||
const filePath = posix.join(dirPath, fileInfo.name);
|
const filePath = posix.join(dirPath, fileInfo.name ?? "");
|
||||||
const fileUrl = posix.join(dirUrl, fileInfo.name);
|
const fileUrl = posix.join(dirUrl, fileInfo.name ?? "");
|
||||||
if (fileInfo.name === "index.html" && fileInfo.isFile()) {
|
if (fileInfo.name === "index.html" && fileInfo.isFile()) {
|
||||||
// in case index.html as dir...
|
// in case index.html as dir...
|
||||||
return await serveFile(req, filePath);
|
return await serveFile(req, filePath);
|
||||||
|
@ -139,7 +140,7 @@ async function serveDir(
|
||||||
listEntry.push({
|
listEntry.push({
|
||||||
mode: modeToString(fileInfo.isDirectory(), mode),
|
mode: modeToString(fileInfo.isDirectory(), mode),
|
||||||
size: fileInfo.isFile() ? fileLenToString(fileInfo.len) : "",
|
size: fileInfo.isFile() ? fileLenToString(fileInfo.len) : "",
|
||||||
name: fileInfo.name,
|
name: fileInfo.name ?? "",
|
||||||
url: fileUrl
|
url: fileUrl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -311,7 +312,7 @@ listenAndServe(
|
||||||
}
|
}
|
||||||
const fsPath = posix.join(target, normalizedUrl);
|
const fsPath = posix.join(target, normalizedUrl);
|
||||||
|
|
||||||
let response: Response;
|
let response: Response | undefined;
|
||||||
try {
|
try {
|
||||||
const info = await stat(fsPath);
|
const info = await stat(fsPath);
|
||||||
if (info.isDirectory()) {
|
if (info.isDirectory()) {
|
||||||
|
@ -324,10 +325,11 @@ listenAndServe(
|
||||||
response = await serveFallback(req, e);
|
response = await serveFallback(req, e);
|
||||||
} finally {
|
} finally {
|
||||||
if (CORSEnabled) {
|
if (CORSEnabled) {
|
||||||
|
assert(response);
|
||||||
setCORS(response);
|
setCORS(response);
|
||||||
}
|
}
|
||||||
serverLog(req, response);
|
serverLog(req, response!);
|
||||||
req.respond(response);
|
req.respond(response!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,7 +38,7 @@ test(async function serveFile(): Promise<void> {
|
||||||
assert(res.headers.has("access-control-allow-origin"));
|
assert(res.headers.has("access-control-allow-origin"));
|
||||||
assert(res.headers.has("access-control-allow-headers"));
|
assert(res.headers.has("access-control-allow-headers"));
|
||||||
assert(res.headers.has("content-type"));
|
assert(res.headers.has("content-type"));
|
||||||
assert(res.headers.get("content-type").includes("charset=utf-8"));
|
assert(res.headers.get("content-type")!.includes("charset=utf-8"));
|
||||||
const downloadedFile = await res.text();
|
const downloadedFile = await res.text();
|
||||||
const localFile = new TextDecoder().decode(
|
const localFile = new TextDecoder().decode(
|
||||||
await Deno.readFile("README.md")
|
await Deno.readFile("README.md")
|
||||||
|
|
|
@ -436,7 +436,7 @@ export class Server implements AsyncIterable<ServerRequest> {
|
||||||
): AsyncIterableIterator<ServerRequest> {
|
): AsyncIterableIterator<ServerRequest> {
|
||||||
const bufr = new BufReader(conn);
|
const bufr = new BufReader(conn);
|
||||||
const w = new BufWriter(conn);
|
const w = new BufWriter(conn);
|
||||||
let req: ServerRequest | Deno.EOF;
|
let req: ServerRequest | Deno.EOF | undefined;
|
||||||
let err: Error | undefined;
|
let err: Error | undefined;
|
||||||
|
|
||||||
while (!this.closing) {
|
while (!this.closing) {
|
||||||
|
|
|
@ -545,7 +545,7 @@ test(async function testReadRequestError(): Promise<void> {
|
||||||
for (const test of testCases) {
|
for (const test of testCases) {
|
||||||
const reader = new BufReader(new StringReader(test.in));
|
const reader = new BufReader(new StringReader(test.in));
|
||||||
let err;
|
let err;
|
||||||
let req: ServerRequest | Deno.EOF;
|
let req: ServerRequest | Deno.EOF | undefined;
|
||||||
try {
|
try {
|
||||||
req = await readRequest(mockConn as Deno.Conn, reader);
|
req = await readRequest(mockConn as Deno.Conn, reader);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -559,7 +559,7 @@ test(async function testReadRequestError(): Promise<void> {
|
||||||
assert(err instanceof (test.err as typeof UnexpectedEOFError));
|
assert(err instanceof (test.err as typeof UnexpectedEOFError));
|
||||||
} else {
|
} else {
|
||||||
assert(req instanceof ServerRequest);
|
assert(req instanceof ServerRequest);
|
||||||
assert(test.headers != null);
|
assert(test.headers);
|
||||||
assertEquals(err, undefined);
|
assertEquals(err, undefined);
|
||||||
assertNotEquals(req, Deno.EOF);
|
assertNotEquals(req, Deno.EOF);
|
||||||
for (const h of test.headers) {
|
for (const h of test.headers) {
|
||||||
|
@ -719,6 +719,7 @@ if (Deno.build.os !== "win") {
|
||||||
const serverRoutine = async (): Promise<void> => {
|
const serverRoutine = async (): Promise<void> => {
|
||||||
let reqCount = 0;
|
let reqCount = 0;
|
||||||
const server = serve(":8124");
|
const server = serve(":8124");
|
||||||
|
// @ts-ignore
|
||||||
const serverRid = server.listener["rid"];
|
const serverRid = server.listener["rid"];
|
||||||
let connRid = -1;
|
let connRid = -1;
|
||||||
for await (const req of server) {
|
for await (const req of server) {
|
||||||
|
|
|
@ -311,7 +311,7 @@ export class BufReader implements Reader {
|
||||||
*/
|
*/
|
||||||
async readSlice(delim: number): Promise<Uint8Array | Deno.EOF> {
|
async readSlice(delim: number): Promise<Uint8Array | Deno.EOF> {
|
||||||
let s = 0; // search start index
|
let s = 0; // search start index
|
||||||
let slice: Uint8Array;
|
let slice: Uint8Array | undefined;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Search buffer.
|
// Search buffer.
|
||||||
|
|
|
@ -1538,7 +1538,7 @@ Build with Cargo:
|
||||||
cargo build -vv
|
cargo build -vv
|
||||||
|
|
||||||
# Run:
|
# Run:
|
||||||
./target/debug/deno tests/002_hello.ts
|
./target/debug/deno cli/tests/002_hello.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Testing and Tools
|
#### Testing and Tools
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import { validateIntegerRange } from "./util.ts";
|
import { validateIntegerRange } from "./util.ts";
|
||||||
|
import { assert } from "../testing/asserts.ts";
|
||||||
|
|
||||||
export interface WrappedFunction extends Function {
|
export interface WrappedFunction extends Function {
|
||||||
listener: Function;
|
listener: Function;
|
||||||
|
@ -163,7 +164,8 @@ export default class EventEmitter {
|
||||||
private unwrapListeners(arr: Function[]): Function[] {
|
private unwrapListeners(arr: Function[]): Function[] {
|
||||||
const unwrappedListeners: Function[] = new Array(arr.length) as Function[];
|
const unwrappedListeners: Function[] = new Array(arr.length) as Function[];
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
unwrappedListeners[i] = arr[i]["listener"] || arr[i];
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
unwrappedListeners[i] = (arr[i] as any)["listener"] || arr[i];
|
||||||
}
|
}
|
||||||
return unwrappedListeners;
|
return unwrappedListeners;
|
||||||
}
|
}
|
||||||
|
@ -232,10 +234,12 @@ export default class EventEmitter {
|
||||||
const wrapperContext = {
|
const wrapperContext = {
|
||||||
eventName: eventName,
|
eventName: eventName,
|
||||||
listener: listener,
|
listener: listener,
|
||||||
rawListener: wrapper,
|
rawListener: (wrapper as unknown) as WrappedFunction,
|
||||||
context: this
|
context: this
|
||||||
};
|
};
|
||||||
const wrapped = wrapper.bind(wrapperContext);
|
const wrapped = (wrapper.bind(
|
||||||
|
wrapperContext
|
||||||
|
) as unknown) as WrappedFunction;
|
||||||
wrapperContext.rawListener = wrapped;
|
wrapperContext.rawListener = wrapped;
|
||||||
wrapped.listener = listener;
|
wrapped.listener = listener;
|
||||||
return wrapped as WrappedFunction;
|
return wrapped as WrappedFunction;
|
||||||
|
@ -275,7 +279,7 @@ export default class EventEmitter {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._events.has(eventName)) {
|
if (eventName && this._events.has(eventName)) {
|
||||||
const listeners = (this._events.get(eventName) as Array<
|
const listeners = (this._events.get(eventName) as Array<
|
||||||
Function | WrappedFunction
|
Function | WrappedFunction
|
||||||
>).slice(); // Create a copy; We use it AFTER it's deleted.
|
>).slice(); // Create a copy; We use it AFTER it's deleted.
|
||||||
|
@ -299,14 +303,19 @@ export default class EventEmitter {
|
||||||
*/
|
*/
|
||||||
public removeListener(eventName: string | symbol, listener: Function): this {
|
public removeListener(eventName: string | symbol, listener: Function): this {
|
||||||
if (this._events.has(eventName)) {
|
if (this._events.has(eventName)) {
|
||||||
const arr: Array<Function | WrappedFunction> = this._events.get(
|
const arr:
|
||||||
eventName
|
| Array<Function | WrappedFunction>
|
||||||
);
|
| undefined = this._events.get(eventName);
|
||||||
|
|
||||||
|
assert(arr);
|
||||||
|
|
||||||
let listenerIndex = -1;
|
let listenerIndex = -1;
|
||||||
for (let i = arr.length - 1; i >= 0; i--) {
|
for (let i = arr.length - 1; i >= 0; i--) {
|
||||||
// arr[i]["listener"] is the reference to the listener inside a bound 'once' wrapper
|
// arr[i]["listener"] is the reference to the listener inside a bound 'once' wrapper
|
||||||
if (arr[i] == listener || arr[i]["listener"] == listener) {
|
if (
|
||||||
|
arr[i] == listener ||
|
||||||
|
(arr[i] && (arr[i] as WrappedFunction)["listener"] == listener)
|
||||||
|
) {
|
||||||
listenerIndex = i;
|
listenerIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -421,8 +430,10 @@ export function on(
|
||||||
): AsyncInterable {
|
): AsyncInterable {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const unconsumedEventValues: any[] = [];
|
const unconsumedEventValues: any[] = [];
|
||||||
const unconsumedPromises = [];
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
let error = null;
|
const unconsumedPromises: any[] = [];
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
let error: Error | null = null;
|
||||||
let finished = false;
|
let finished = false;
|
||||||
|
|
||||||
const iterator = {
|
const iterator = {
|
||||||
|
@ -476,7 +487,7 @@ export function on(
|
||||||
},
|
},
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
[Symbol.asyncIterator](): AsyncIterable<any> {
|
[Symbol.asyncIterator](): any {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ test({
|
||||||
fn() {
|
fn() {
|
||||||
let eventsFired: string[] = [];
|
let eventsFired: string[] = [];
|
||||||
const testEmitter = new EventEmitter();
|
const testEmitter = new EventEmitter();
|
||||||
testEmitter.on("newListener", event => {
|
testEmitter.on("newListener", (event: string) => {
|
||||||
if (event !== "newListener") {
|
if (event !== "newListener") {
|
||||||
eventsFired.push("newListener");
|
eventsFired.push("newListener");
|
||||||
}
|
}
|
||||||
|
@ -81,20 +81,23 @@ test({
|
||||||
fn() {
|
fn() {
|
||||||
const testEmitter = new EventEmitter();
|
const testEmitter = new EventEmitter();
|
||||||
const eventsFired: string[] = [];
|
const eventsFired: string[] = [];
|
||||||
testEmitter.on("event", oneArg => {
|
testEmitter.on("event", (oneArg: string) => {
|
||||||
eventsFired.push("event(" + oneArg + ")");
|
eventsFired.push("event(" + oneArg + ")");
|
||||||
});
|
});
|
||||||
testEmitter.on("event", (oneArg, twoArg) => {
|
testEmitter.on("event", (oneArg: string, twoArg: string) => {
|
||||||
eventsFired.push("event(" + oneArg + ", " + twoArg + ")");
|
eventsFired.push("event(" + oneArg + ", " + twoArg + ")");
|
||||||
});
|
});
|
||||||
|
|
||||||
testEmitter.on("non-event", shouldNeverBeEmitted);
|
testEmitter.on("non-event", shouldNeverBeEmitted);
|
||||||
|
|
||||||
testEmitter.on("event", (oneArg, twoArg, threeArg) => {
|
testEmitter.on(
|
||||||
eventsFired.push(
|
"event",
|
||||||
"event(" + oneArg + ", " + twoArg + ", " + threeArg + ")"
|
(oneArg: string, twoArg: string, threeArg: string) => {
|
||||||
);
|
eventsFired.push(
|
||||||
});
|
"event(" + oneArg + ", " + twoArg + ", " + threeArg + ")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
testEmitter.emit("event", 1, 2, 3);
|
testEmitter.emit("event", 1, 2, 3);
|
||||||
assertEquals(eventsFired, ["event(1)", "event(1, 2)", "event(1, 2, 3)"]);
|
assertEquals(eventsFired, ["event(1)", "event(1, 2)", "event(1, 2, 3)"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
window["global"] = window;
|
// @ts-ignore
|
||||||
|
globalThis["global"] = globalThis;
|
||||||
|
|
|
@ -40,7 +40,7 @@ const isWindows = path.isWindows;
|
||||||
const relativeResolveCache = Object.create(null);
|
const relativeResolveCache = Object.create(null);
|
||||||
|
|
||||||
let requireDepth = 0;
|
let requireDepth = 0;
|
||||||
let statCache = null;
|
let statCache: Map<string, StatResult> | null = null;
|
||||||
|
|
||||||
type StatResult = -1 | 0 | 1;
|
type StatResult = -1 | 0 | 1;
|
||||||
// Returns 0 if the path refers to
|
// Returns 0 if the path refers to
|
||||||
|
@ -64,7 +64,11 @@ function stat(filename: string): StatResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateChildren(parent: Module, child: Module, scan: boolean): void {
|
function updateChildren(
|
||||||
|
parent: Module | null,
|
||||||
|
child: Module,
|
||||||
|
scan: boolean
|
||||||
|
): void {
|
||||||
const children = parent && parent.children;
|
const children = parent && parent.children;
|
||||||
if (children && !(scan && children.includes(child))) {
|
if (children && !(scan && children.includes(child))) {
|
||||||
children.push(child);
|
children.push(child);
|
||||||
|
@ -75,17 +79,17 @@ class Module {
|
||||||
id: string;
|
id: string;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
exports: any;
|
exports: any;
|
||||||
parent?: Module;
|
parent: Module | null;
|
||||||
filename: string;
|
filename: string | null;
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
children: Module[];
|
children: Module[];
|
||||||
paths: string[];
|
paths: string[];
|
||||||
path: string;
|
path: string;
|
||||||
constructor(id = "", parent?: Module) {
|
constructor(id = "", parent?: Module | null) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.exports = {};
|
this.exports = {};
|
||||||
this.parent = parent;
|
this.parent = parent || null;
|
||||||
updateChildren(parent, this, false);
|
updateChildren(parent || null, this, false);
|
||||||
this.filename = null;
|
this.filename = null;
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -229,25 +233,25 @@ class Module {
|
||||||
fakeParent.paths = Module._nodeModulePaths(path);
|
fakeParent.paths = Module._nodeModulePaths(path);
|
||||||
const lookupPaths = Module._resolveLookupPaths(request, fakeParent);
|
const lookupPaths = Module._resolveLookupPaths(request, fakeParent);
|
||||||
|
|
||||||
for (let j = 0; j < lookupPaths.length; j++) {
|
for (let j = 0; j < lookupPaths!.length; j++) {
|
||||||
if (!paths.includes(lookupPaths[j])) paths.push(lookupPaths[j]);
|
if (!paths.includes(lookupPaths![j])) paths.push(lookupPaths![j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (options.paths === undefined) {
|
} else if (options.paths === undefined) {
|
||||||
paths = Module._resolveLookupPaths(request, parent);
|
paths = Module._resolveLookupPaths(request, parent)!;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("options.paths is invalid");
|
throw new Error("options.paths is invalid");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
paths = Module._resolveLookupPaths(request, parent);
|
paths = Module._resolveLookupPaths(request, parent)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up the filename first, since that's the cache key.
|
// Look up the filename first, since that's the cache key.
|
||||||
const filename = Module._findPath(request, paths, isMain);
|
const filename = Module._findPath(request, paths, isMain);
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
const requireStack = [];
|
const requireStack = [];
|
||||||
for (let cursor = parent; cursor; cursor = cursor.parent) {
|
for (let cursor: Module | null = parent; cursor; cursor = cursor.parent) {
|
||||||
requireStack.push(cursor.filename || cursor.id);
|
requireStack.push(cursor.filename || cursor.id);
|
||||||
}
|
}
|
||||||
let message = `Cannot find module '${request}'`;
|
let message = `Cannot find module '${request}'`;
|
||||||
|
@ -341,7 +345,7 @@ class Module {
|
||||||
// object.
|
// object.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
static _load(request: string, parent: Module, isMain: boolean): any {
|
static _load(request: string, parent: Module, isMain: boolean): any {
|
||||||
let relResolveCacheIdentifier;
|
let relResolveCacheIdentifier: string | undefined;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
// Fast path for (lazy loaded) modules in the same directory. The indirect
|
// Fast path for (lazy loaded) modules in the same directory. The indirect
|
||||||
// caching is required to allow cache invalidation without changing the old
|
// caching is required to allow cache invalidation without changing the old
|
||||||
|
@ -385,6 +389,7 @@ class Module {
|
||||||
|
|
||||||
Module._cache[filename] = module;
|
Module._cache[filename] = module;
|
||||||
if (parent !== undefined) {
|
if (parent !== undefined) {
|
||||||
|
assert(relResolveCacheIdentifier);
|
||||||
relativeResolveCache[relResolveCacheIdentifier] = filename;
|
relativeResolveCache[relResolveCacheIdentifier] = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +402,7 @@ class Module {
|
||||||
if (threw) {
|
if (threw) {
|
||||||
delete Module._cache[filename];
|
delete Module._cache[filename];
|
||||||
if (parent !== undefined) {
|
if (parent !== undefined) {
|
||||||
|
assert(relResolveCacheIdentifier);
|
||||||
delete relativeResolveCache[relResolveCacheIdentifier];
|
delete relativeResolveCache[relResolveCacheIdentifier];
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -602,7 +608,7 @@ for (const id of nativeModulePolyfill.keys()) {
|
||||||
Module.builtinModules.push(id);
|
Module.builtinModules.push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let modulePaths = [];
|
let modulePaths: string[] = [];
|
||||||
|
|
||||||
// Given a module name, and a list of paths to test, returns the first
|
// Given a module name, and a list of paths to test, returns the first
|
||||||
// matching file in the following precedence.
|
// matching file in the following precedence.
|
||||||
|
@ -664,7 +670,7 @@ function readPackage(requestPath: string): PackageInfo | null {
|
||||||
}
|
}
|
||||||
|
|
||||||
function readPackageScope(
|
function readPackageScope(
|
||||||
checkPath
|
checkPath: string
|
||||||
): { path: string; data: PackageInfo } | false {
|
): { path: string; data: PackageInfo } | false {
|
||||||
const rootSeparatorIndex = checkPath.indexOf(path.sep);
|
const rootSeparatorIndex = checkPath.indexOf(path.sep);
|
||||||
let separatorIndex;
|
let separatorIndex;
|
||||||
|
@ -987,6 +993,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy(
|
||||||
{
|
{
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
get(target, prop): any {
|
get(target, prop): any {
|
||||||
|
// @ts-ignore
|
||||||
if (prop in target) return target[prop];
|
if (prop in target) return target[prop];
|
||||||
emitCircularRequireWarning(prop);
|
emitCircularRequireWarning(prop);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -1150,7 +1157,7 @@ function getPathFromURLWin32(url: URL): string {
|
||||||
let pathname = url.pathname;
|
let pathname = url.pathname;
|
||||||
for (let n = 0; n < pathname.length; n++) {
|
for (let n = 0; n < pathname.length; n++) {
|
||||||
if (pathname[n] === "%") {
|
if (pathname[n] === "%") {
|
||||||
const third = pathname.codePointAt(n + 2) | 0x20;
|
const third = pathname.codePointAt(n + 2)! | 0x20;
|
||||||
if (
|
if (
|
||||||
(pathname[n + 1] === "2" && third === 102) || // 2f 2F /
|
(pathname[n + 1] === "2" && third === 102) || // 2f 2F /
|
||||||
(pathname[n + 1] === "5" && third === 99)
|
(pathname[n + 1] === "5" && third === 99)
|
||||||
|
@ -1165,7 +1172,7 @@ function getPathFromURLWin32(url: URL): string {
|
||||||
pathname = pathname.replace(forwardSlashRegEx, "\\");
|
pathname = pathname.replace(forwardSlashRegEx, "\\");
|
||||||
pathname = decodeURIComponent(pathname);
|
pathname = decodeURIComponent(pathname);
|
||||||
// TODO: handle windows hostname case (needs bindings)
|
// TODO: handle windows hostname case (needs bindings)
|
||||||
const letter = pathname.codePointAt(1) | 0x20;
|
const letter = pathname.codePointAt(1)! | 0x20;
|
||||||
const sep = pathname[2];
|
const sep = pathname[2];
|
||||||
if (
|
if (
|
||||||
letter < CHAR_LOWERCASE_A ||
|
letter < CHAR_LOWERCASE_A ||
|
||||||
|
@ -1184,7 +1191,7 @@ function getPathFromURLPosix(url: URL): string {
|
||||||
const pathname = url.pathname;
|
const pathname = url.pathname;
|
||||||
for (let n = 0; n < pathname.length; n++) {
|
for (let n = 0; n < pathname.length; n++) {
|
||||||
if (pathname[n] === "%") {
|
if (pathname[n] === "%") {
|
||||||
const third = pathname.codePointAt(n + 2) | 0x20;
|
const third = pathname.codePointAt(n + 2)! | 0x20;
|
||||||
if (pathname[n + 1] === "2" && third === 102) {
|
if (pathname[n + 1] === "2" && third === 102) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Invalid file URL path: must not include encoded / characters"
|
"Invalid file URL path: must not include encoded / characters"
|
||||||
|
|
|
@ -123,7 +123,7 @@ export function getPriority(pid = 0): number {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the string path of the current user's home directory. */
|
/** Returns the string path of the current user's home directory. */
|
||||||
export function homedir(): string {
|
export function homedir(): string | null {
|
||||||
return Deno.dir("home");
|
return Deno.dir("home");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ export function release(): string {
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Not yet implemented */
|
||||||
export function setPriority(pid: number, priority?: number): void {
|
export function setPriority(pid: number, priority?: number): void {
|
||||||
/* The node API has the 'pid' as the first parameter and as optional.
|
/* The node API has the 'pid' as the first parameter and as optional.
|
||||||
This makes for a problematic implementation in Typescript. */
|
This makes for a problematic implementation in Typescript. */
|
||||||
if (priority === undefined) {
|
if (priority === undefined) {
|
||||||
priority = pid;
|
priority = pid;
|
||||||
|
|
|
@ -46,13 +46,13 @@ export function normalizeString(
|
||||||
let lastSegmentLength = 0;
|
let lastSegmentLength = 0;
|
||||||
let lastSlash = -1;
|
let lastSlash = -1;
|
||||||
let dots = 0;
|
let dots = 0;
|
||||||
let code: number;
|
let code: number | undefined;
|
||||||
for (let i = 0, len = path.length; i <= len; ++i) {
|
for (let i = 0, len = path.length; i <= len; ++i) {
|
||||||
if (i < len) code = path.charCodeAt(i);
|
if (i < len) code = path.charCodeAt(i);
|
||||||
else if (isPathSeparator(code)) break;
|
else if (isPathSeparator(code!)) break;
|
||||||
else code = CHAR_FORWARD_SLASH;
|
else code = CHAR_FORWARD_SLASH;
|
||||||
|
|
||||||
if (isPathSeparator(code)) {
|
if (isPathSeparator(code!)) {
|
||||||
if (lastSlash === i - 1 || dots === 1) {
|
if (lastSlash === i - 1 || dots === 1) {
|
||||||
// NOOP
|
// NOOP
|
||||||
} else if (lastSlash !== i - 1 && dots === 2) {
|
} else if (lastSlash !== i - 1 && dots === 2) {
|
||||||
|
|
|
@ -303,7 +303,7 @@ export function join(...paths: string[]): string {
|
||||||
if (pathsCount === 0) return ".";
|
if (pathsCount === 0) return ".";
|
||||||
|
|
||||||
let joined: string | undefined;
|
let joined: string | undefined;
|
||||||
let firstPart: string;
|
let firstPart: string | null = null;
|
||||||
for (let i = 0; i < pathsCount; ++i) {
|
for (let i = 0; i < pathsCount; ++i) {
|
||||||
const path = paths[i];
|
const path = paths[i];
|
||||||
assertPath(path);
|
assertPath(path);
|
||||||
|
|
|
@ -67,7 +67,7 @@ export class TextProtoReader {
|
||||||
*/
|
*/
|
||||||
async readMIMEHeader(): Promise<Headers | Deno.EOF> {
|
async readMIMEHeader(): Promise<Headers | Deno.EOF> {
|
||||||
const m = new Headers();
|
const m = new Headers();
|
||||||
let line: Uint8Array;
|
let line: Uint8Array | undefined;
|
||||||
|
|
||||||
// The first line cannot start with a leading space.
|
// The first line cannot start with a leading space.
|
||||||
let buf = await this.r.peek(1);
|
let buf = await this.r.peek(1);
|
||||||
|
@ -135,7 +135,7 @@ export class TextProtoReader {
|
||||||
|
|
||||||
async readLineSlice(): Promise<Uint8Array | Deno.EOF> {
|
async readLineSlice(): Promise<Uint8Array | Deno.EOF> {
|
||||||
// this.closeDot();
|
// this.closeDot();
|
||||||
let line: Uint8Array;
|
let line: Uint8Array | undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
const r = await this.r.readLine();
|
const r = await this.r.readLine();
|
||||||
if (r === Deno.EOF) return Deno.EOF;
|
if (r === Deno.EOF) return Deno.EOF;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
import { assert } from "../testing/asserts.ts";
|
||||||
|
|
||||||
export function deepAssign(
|
export function deepAssign(
|
||||||
target: Record<string, unknown>,
|
target: Record<string, unknown>,
|
||||||
...sources: object[]
|
...sources: object[]
|
||||||
|
@ -24,6 +26,7 @@ export function deepAssign(
|
||||||
if (typeof target[key] !== `object` || !target[key]) {
|
if (typeof target[key] !== `object` || !target[key]) {
|
||||||
target[key] = {};
|
target[key] = {};
|
||||||
}
|
}
|
||||||
|
assert(value);
|
||||||
deepAssign(target[key] as Record<string, unknown>, value);
|
deepAssign(target[key] as Record<string, unknown>, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue