summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-06-02 14:24:44 +1000
committerGitHub <noreply@github.com>2020-06-02 00:24:44 -0400
commit3fe6bc1b82a10bed1d907b749b1cc200659df612 (patch)
tree02e14128039d015a7256494a50476f61785e6f33 /cli/tests
parent8b1b4766a1e747437a2b88fcadc26162a1bec640 (diff)
fix: Better use of @ts-expect-error (#6038)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/body_test.ts8
-rw-r--r--cli/tests/unit/dispatch_json_test.ts13
-rw-r--r--cli/tests/unit/dispatch_minimal_test.ts10
-rw-r--r--cli/tests/unit/fetch_test.ts8
-rw-r--r--cli/tests/unit/files_test.ts8
-rw-r--r--cli/tests/unit/form_data_test.ts28
-rw-r--r--cli/tests/unit/globals_test.ts25
-rw-r--r--cli/tests/unit/headers_test.ts24
-rw-r--r--cli/tests/unit/request_test.ts16
-rw-r--r--cli/tests/unit/streams_internal_test.ts35
-rw-r--r--cli/tests/unit/url_search_params_test.ts14
11 files changed, 98 insertions, 91 deletions
diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts
index fd91b5ced..a6df3102e 100644
--- a/cli/tests/unit/body_test.ts
+++ b/cli/tests/unit/body_test.ts
@@ -42,8 +42,8 @@ unitTest(
const body = buildBody(text);
- // @ts-expect-error
- body.contentType = "multipart/form-data;boundary=boundary";
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (body as any).contentType = "multipart/form-data;boundary=boundary";
const formData = await body.formData();
assert(formData.has("field_1"));
@@ -62,8 +62,8 @@ unitTest(
const body = buildBody(text);
- // @ts-expect-error
- body.contentType = "application/x-www-form-urlencoded";
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (body as any).contentType = "application/x-www-form-urlencoded";
const formData = await body.formData();
assert(formData.has("field_1"));
diff --git a/cli/tests/unit/dispatch_json_test.ts b/cli/tests/unit/dispatch_json_test.ts
index 51c33befd..ebb8217e3 100644
--- a/cli/tests/unit/dispatch_json_test.ts
+++ b/cli/tests/unit/dispatch_json_test.ts
@@ -19,14 +19,19 @@ unitTest(
}
);
+/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-explicit-any,no-var */
+declare global {
+ namespace Deno {
+ var core: any;
+ }
+}
+/* eslint-enable */
+
unitTest(function malformedJsonControlBuffer(): void {
- // @ts-expect-error
const opId = Deno.core.ops()["op_open"];
- // @ts-expect-error
const res = Deno.core.send(opId, new Uint8Array([1, 2, 3, 4, 5]));
const resText = new TextDecoder().decode(res);
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const resJson = JSON.parse(resText) as any;
+ const resJson = JSON.parse(resText);
assert(!resJson.ok);
assert(resJson.err);
});
diff --git a/cli/tests/unit/dispatch_minimal_test.ts b/cli/tests/unit/dispatch_minimal_test.ts
index 1c7ba11f0..12cf4595c 100644
--- a/cli/tests/unit/dispatch_minimal_test.ts
+++ b/cli/tests/unit/dispatch_minimal_test.ts
@@ -25,10 +25,16 @@ unitTest(async function sendAsyncStackTrace(): Promise<void> {
}
});
+/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-explicit-any,no-var */
+declare global {
+ namespace Deno {
+ var core: any;
+ }
+}
+/* eslint-enable */
+
unitTest(function malformedMinimalControlBuffer(): void {
- // @ts-expect-error
const readOpId = Deno.core.ops()["op_read"];
- // @ts-expect-error
const res = Deno.core.send(readOpId, new Uint8Array([1, 2, 3, 4, 5]));
const header = res.slice(0, 12);
const buf32 = new Int32Array(
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 554cf31e9..b95ecfb96 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -92,9 +92,8 @@ unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise<
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
assertEquals(response.bodyUsed, false);
assertThrows((): void => {
- // Assigning to read-only property throws in the strict mode.
- // @ts-expect-error
- response.bodyUsed = true;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (response as any).bodyUsed = true;
});
await response.blob();
assertEquals(response.bodyUsed, true);
@@ -657,10 +656,9 @@ unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
assert(_json);
// All calls after the body was consumed, should fail
- const methods = ["json", "text", "formData", "arrayBuffer"];
+ const methods = ["json", "text", "formData", "arrayBuffer"] as const;
for (const method of methods) {
try {
- // @ts-expect-error
await response[method]();
fail(
"Reading body multiple times should failed, the stream should've been locked."
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts
index 9ab74be89..a1b532157 100644
--- a/cli/tests/unit/files_test.ts
+++ b/cli/tests/unit/files_test.ts
@@ -290,8 +290,8 @@ unitTest(
// writing null should throw an error
let err;
try {
- // @ts-expect-error
- await file.write(null);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ await file.write(null as any);
} catch (e) {
err = e;
}
@@ -322,8 +322,8 @@ unitTest(
// reading file into null buffer should throw an error
let err;
try {
- // @ts-expect-error
- await file.read(null);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ await file.read(null as any);
} catch (e) {
err = e;
}
diff --git a/cli/tests/unit/form_data_test.ts b/cli/tests/unit/form_data_test.ts
index 89f8ffa0e..de443889c 100644
--- a/cli/tests/unit/form_data_test.ts
+++ b/cli/tests/unit/form_data_test.ts
@@ -41,10 +41,10 @@ unitTest(function formDataParamsGetSuccess(): void {
formData.append("a", "true");
formData.append("b", "false");
formData.append("a", "null");
- // @ts-expect-error
- formData.append("d", undefined);
- // @ts-expect-error
- formData.append("e", null);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ formData.append("d", undefined as any);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ formData.append("e", null as any);
assertEquals(formData.get("a"), "true");
assertEquals(formData.get("b"), "false");
assertEquals(formData.get("c"), null);
@@ -70,11 +70,11 @@ unitTest(function formDataParamsSetSuccess(): void {
assertEquals(formData.getAll("b"), ["false"]);
formData.set("a", "false");
assertEquals(formData.getAll("a"), ["false"]);
- // @ts-expect-error
- formData.set("d", undefined);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ formData.set("d", undefined as any);
assertEquals(formData.get("d"), "undefined");
- // @ts-expect-error
- formData.set("e", null);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ formData.set("e", null as any);
assertEquals(formData.get("e"), "null");
});
@@ -143,8 +143,8 @@ unitTest(function formDataParamsArgumentsCheck(): void {
let hasThrown = 0;
let errMsg = "";
try {
- // @ts-expect-error
- formData[method]();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (formData as any)[method]();
hasThrown = 1;
} catch (err) {
errMsg = err.message;
@@ -167,8 +167,8 @@ unitTest(function formDataParamsArgumentsCheck(): void {
let errMsg = "";
try {
- // @ts-expect-error
- formData[method]();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (formData as any)[method]();
hasThrown = 1;
} catch (err) {
errMsg = err.message;
@@ -187,8 +187,8 @@ unitTest(function formDataParamsArgumentsCheck(): void {
hasThrown = 0;
errMsg = "";
try {
- // @ts-expect-error
- formData[method]("foo");
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (formData as any)[method]("foo");
hasThrown = 1;
} catch (err) {
errMsg = err.message;
diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts
index bb5e5c604..ccea6e74c 100644
--- a/cli/tests/unit/globals_test.ts
+++ b/cli/tests/unit/globals_test.ts
@@ -45,16 +45,24 @@ unitTest(function webAssemblyExists(): void {
assert(typeof WebAssembly.compile === "function");
});
+/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-explicit-any,no-var */
+declare global {
+ namespace Deno {
+ var core: any;
+ }
+}
+/* eslint-enable */
+
unitTest(function DenoNamespaceImmutable(): void {
const denoCopy = window.Deno;
try {
- // @ts-expect-error
- Deno = 1;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (Deno as any) = 1;
} catch {}
assert(denoCopy === Deno);
try {
- // @ts-expect-error
- window.Deno = 1;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (window as any).Deno = 1;
} catch {}
assert(denoCopy === Deno);
try {
@@ -64,8 +72,8 @@ unitTest(function DenoNamespaceImmutable(): void {
const { readFile } = Deno;
try {
- // @ts-expect-error
- Deno.readFile = 1;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (Deno as any).readFile = 1;
} catch {}
assert(readFile === Deno.readFile);
try {
@@ -73,19 +81,14 @@ unitTest(function DenoNamespaceImmutable(): void {
} catch {}
assert(readFile === Deno.readFile);
- // @ts-expect-error
const { print } = Deno.core;
try {
- // @ts-expect-error
Deno.core.print = 1;
} catch {}
- // @ts-expect-error
assert(print === Deno.core.print);
try {
- // @ts-expect-error
delete Deno.core.print;
} catch {}
- // @ts-expect-error
assert(print === Deno.core.print);
});
diff --git a/cli/tests/unit/headers_test.ts b/cli/tests/unit/headers_test.ts
index 722c55fb5..84c342fd8 100644
--- a/cli/tests/unit/headers_test.ts
+++ b/cli/tests/unit/headers_test.ts
@@ -22,8 +22,8 @@ unitTest(function newHeaderTest(): void {
new Headers(undefined);
new Headers({});
try {
- // @ts-expect-error
- new Headers(null);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ new Headers(null as any);
} catch (e) {
assertEquals(
e.message,
@@ -36,8 +36,8 @@ const headerDict: Record<string, string> = {
name1: "value1",
name2: "value2",
name3: "value3",
- // @ts-expect-error
- name4: undefined,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ name4: undefined as any,
"Content-Type": "value4",
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -264,17 +264,17 @@ unitTest(function headerParamsShouldThrowTypeError(): void {
});
unitTest(function headerParamsArgumentsCheck(): void {
- const methodRequireOneParam = ["delete", "get", "has", "forEach"];
+ const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const;
- const methodRequireTwoParams = ["append", "set"];
+ const methodRequireTwoParams = ["append", "set"] as const;
methodRequireOneParam.forEach((method): void => {
const headers = new Headers();
let hasThrown = 0;
let errMsg = "";
try {
- // @ts-expect-error
- headers[method]();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (headers as any)[method]();
hasThrown = 1;
} catch (err) {
errMsg = err.message;
@@ -297,8 +297,8 @@ unitTest(function headerParamsArgumentsCheck(): void {
let errMsg = "";
try {
- // @ts-expect-error
- headers[method]();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (headers as any)[method]();
hasThrown = 1;
} catch (err) {
errMsg = err.message;
@@ -317,8 +317,8 @@ unitTest(function headerParamsArgumentsCheck(): void {
hasThrown = 0;
errMsg = "";
try {
- // @ts-expect-error
- headers[method]("foo");
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (headers as any)[method]("foo");
hasThrown = 1;
} catch (err) {
errMsg = err.message;
diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts
index be6e956b7..24f5b6d82 100644
--- a/cli/tests/unit/request_test.ts
+++ b/cli/tests/unit/request_test.ts
@@ -10,22 +10,22 @@ unitTest(function fromInit(): void {
},
});
- // @ts-expect-error
- assertEquals("ahoyhoy", req._bodySource);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertEquals("ahoyhoy", (req as any)._bodySource);
assertEquals(req.url, "https://example.com");
assertEquals(req.headers.get("test-header"), "value");
});
unitTest(function fromRequest(): void {
const r = new Request("https://example.com");
- // @ts-expect-error
- r._bodySource = "ahoyhoy";
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (r as any)._bodySource = "ahoyhoy";
r.headers.set("test-header", "value");
const req = new Request(r);
- // @ts-expect-error
- assertEquals(req._bodySource, r._bodySource);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertEquals((req as any)._bodySource, (r as any)._bodySource);
assertEquals(req.url, r.url);
assertEquals(req.headers.get("test-header"), r.headers.get("test-header"));
});
@@ -44,6 +44,6 @@ unitTest(async function cloneRequestBodyStream(): Promise<void> {
assertEquals(b1, b2);
- // @ts-expect-error
- assert(r1._bodySource !== r2._bodySource);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assert((r1 as any)._bodySource !== (r2 as any)._bodySource);
});
diff --git a/cli/tests/unit/streams_internal_test.ts b/cli/tests/unit/streams_internal_test.ts
index f49c9f494..346ec27af 100644
--- a/cli/tests/unit/streams_internal_test.ts
+++ b/cli/tests/unit/streams_internal_test.ts
@@ -2,15 +2,12 @@
import { unitTest, assertThrows } from "./test_util.ts";
unitTest(function streamReadableHwmError() {
- const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
- new ReadableStream<number>(
- undefined,
- // @ts-expect-error
- { highWaterMark }
- );
+ new ReadableStream<number>(undefined, { highWaterMark });
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:"
@@ -20,20 +17,20 @@ unitTest(function streamReadableHwmError() {
assertThrows(() => {
new ReadableStream<number>(
undefined,
- // @ts-expect-error
- { highWaterMark: Symbol("hwk") }
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ { highWaterMark: Symbol("hwk") as any }
);
}, TypeError);
});
unitTest(function streamWriteableHwmError() {
- const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new WritableStream(
undefined,
- // @ts-expect-error
new CountQueuingStrategy({ highWaterMark })
);
},
@@ -45,23 +42,19 @@ unitTest(function streamWriteableHwmError() {
assertThrows(() => {
new WritableStream(
undefined,
- // @ts-expect-error
- new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") })
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") as any })
);
}, TypeError);
});
unitTest(function streamTransformHwmError() {
- const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
- new TransformStream(
- undefined,
- undefined,
- // @ts-expect-error
- { highWaterMark }
- );
+ new TransformStream(undefined, undefined, { highWaterMark });
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:"
@@ -72,8 +65,8 @@ unitTest(function streamTransformHwmError() {
new TransformStream(
undefined,
undefined,
- // @ts-expect-error
- { highWaterMark: Symbol("hwmk") }
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ { highWaterMark: Symbol("hwmk") as any }
);
}, TypeError);
});
diff --git a/cli/tests/unit/url_search_params_test.ts b/cli/tests/unit/url_search_params_test.ts
index ce55a7520..227deeda7 100644
--- a/cli/tests/unit/url_search_params_test.ts
+++ b/cli/tests/unit/url_search_params_test.ts
@@ -177,8 +177,8 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void {
const searchParams = new URLSearchParams();
let hasThrown = 0;
try {
- // @ts-expect-error
- searchParams[method]();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (searchParams as any)[method]();
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
@@ -194,8 +194,8 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void {
const searchParams = new URLSearchParams();
let hasThrown = 0;
try {
- // @ts-expect-error
- searchParams[method]("foo");
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (searchParams as any)[method]("foo");
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
@@ -235,8 +235,10 @@ unitTest(function urlSearchParamsCustomSymbolIterator(): void {
unitTest(
function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
const params = {};
- // @ts-expect-error
- params[Symbol.iterator] = function* (): IterableIterator<[number, number]> {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (params as any)[Symbol.iterator] = function* (): IterableIterator<
+ [number, number]
+ > {
yield [1, 2];
};
const params1 = new URLSearchParams((params as unknown) as string[][]);