diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/dom_iterable_test.ts | 88 | ||||
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 10 | ||||
-rw-r--r-- | cli/tests/unit/headers_test.ts | 48 | ||||
-rw-r--r-- | cli/tests/unit/unit_tests.ts | 1 |
4 files changed, 11 insertions, 136 deletions
diff --git a/cli/tests/unit/dom_iterable_test.ts b/cli/tests/unit/dom_iterable_test.ts deleted file mode 100644 index 4e94cfdba..000000000 --- a/cli/tests/unit/dom_iterable_test.ts +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -import { assert, assertEquals, unitTest } from "./test_util.ts"; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -function setup() { - const dataSymbol = Symbol("data symbol"); - class Base { - [dataSymbol] = new Map<string, number>(); - - constructor( - data: Array<[string, number]> | IterableIterator<[string, number]>, - ) { - for (const [key, value] of data) { - this[dataSymbol].set(key, value); - } - } - } - - return { - Base, - // This is using an internal API we don't want published as types, so having - // to cast to any to "trick" TypeScript - // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol - DomIterable: Deno[Deno.internal].DomIterableMixin(Base, dataSymbol), - }; -} - -unitTest(function testDomIterable(): void { - const { DomIterable, Base } = setup(); - - const fixture: Array<[string, number]> = [ - ["foo", 1], - ["bar", 2], - ]; - - const domIterable = new DomIterable(fixture); - - assertEquals(Array.from(domIterable.entries()), fixture); - assertEquals(Array.from(domIterable.values()), [1, 2]); - assertEquals(Array.from(domIterable.keys()), ["foo", "bar"]); - - let result: Array<[string, number]> = []; - for (const [key, value] of domIterable) { - assert(key != null); - assert(value != null); - result.push([key, value]); - } - assertEquals(fixture, result); - - result = []; - const scope = {}; - function callback( - this: typeof scope, - value: number, - key: string, - parent: typeof domIterable, - ): void { - assertEquals(parent, domIterable); - assert(key != null); - assert(value != null); - assert(this === scope); - result.push([key, value]); - } - domIterable.forEach(callback, scope); - assertEquals(fixture, result); - - assertEquals(DomIterable.name, Base.name); -}); - -unitTest(function testDomIterableScope(): void { - const { DomIterable } = setup(); - - const domIterable = new DomIterable([["foo", 1]]); - - // deno-lint-ignore no-explicit-any - function checkScope(thisArg: any, expected: any): void { - function callback(this: typeof thisArg): void { - assertEquals(this, expected); - } - domIterable.forEach(callback, thisArg); - } - - checkScope(0, Object(0)); - checkScope("", Object("")); - checkScope(null, window); - checkScope(undefined, window); -}); diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 0fb9da8f4..427ab9b53 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -661,8 +661,8 @@ unitTest( const actual = new TextDecoder().decode(buf.bytes()); const expected = [ "POST /blah HTTP/1.1\r\n", - "hello: World\r\n", "foo: Bar\r\n", + "hello: World\r\n", "accept: */*\r\n", `user-agent: Deno/${Deno.version.deno}\r\n`, "accept-encoding: gzip, br\r\n", @@ -695,9 +695,9 @@ unitTest( const actual = new TextDecoder().decode(buf.bytes()); const expected = [ "POST /blah HTTP/1.1\r\n", - "hello: World\r\n", - "foo: Bar\r\n", "content-type: text/plain;charset=UTF-8\r\n", + "foo: Bar\r\n", + "hello: World\r\n", "accept: */*\r\n", `user-agent: Deno/${Deno.version.deno}\r\n`, "accept-encoding: gzip, br\r\n", @@ -733,8 +733,8 @@ unitTest( const actual = new TextDecoder().decode(buf.bytes()); const expected = [ "POST /blah HTTP/1.1\r\n", - "hello: World\r\n", "foo: Bar\r\n", + "hello: World\r\n", "accept: */*\r\n", `user-agent: Deno/${Deno.version.deno}\r\n`, "accept-encoding: gzip, br\r\n", @@ -1115,8 +1115,8 @@ unitTest( const actual = new TextDecoder().decode(buf.bytes()); const expected = [ "POST /blah HTTP/1.1\r\n", - "hello: World\r\n", "foo: Bar\r\n", + "hello: World\r\n", "accept: */*\r\n", `user-agent: Deno/${Deno.version.deno}\r\n`, "accept-encoding: gzip, br\r\n", diff --git a/cli/tests/unit/headers_test.ts b/cli/tests/unit/headers_test.ts index aa8834052..c79673d84 100644 --- a/cli/tests/unit/headers_test.ts +++ b/cli/tests/unit/headers_test.ts @@ -1,10 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertStringIncludes, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, unitTest } from "./test_util.ts"; const { inspectArgs, // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol @@ -25,10 +20,7 @@ unitTest(function newHeaderTest(): void { // deno-lint-ignore no-explicit-any new Headers(null as any); } catch (e) { - assertEquals( - e.message, - "Failed to construct 'Headers'; The provided value was not valid", - ); + assert(e instanceof TypeError); } }); @@ -271,13 +263,11 @@ unitTest(function headerParamsArgumentsCheck(): void { methodRequireOneParam.forEach((method): void => { const headers = new Headers(); let hasThrown = 0; - let errMsg = ""; try { // deno-lint-ignore no-explicit-any (headers as any)[method](); hasThrown = 1; } catch (err) { - errMsg = err.message; if (err instanceof TypeError) { hasThrown = 2; } else { @@ -285,23 +275,17 @@ unitTest(function headerParamsArgumentsCheck(): void { } } assertEquals(hasThrown, 2); - assertStringIncludes( - errMsg, - `${method} requires at least 1 argument, but only 0 present`, - ); }); methodRequireTwoParams.forEach((method): void => { const headers = new Headers(); let hasThrown = 0; - let errMsg = ""; try { // deno-lint-ignore no-explicit-any (headers as any)[method](); hasThrown = 1; } catch (err) { - errMsg = err.message; if (err instanceof TypeError) { hasThrown = 2; } else { @@ -309,19 +293,13 @@ unitTest(function headerParamsArgumentsCheck(): void { } } assertEquals(hasThrown, 2); - assertStringIncludes( - errMsg, - `${method} requires at least 2 arguments, but only 0 present`, - ); hasThrown = 0; - errMsg = ""; try { // deno-lint-ignore no-explicit-any (headers as any)[method]("foo"); hasThrown = 1; } catch (err) { - errMsg = err.message; if (err instanceof TypeError) { hasThrown = 2; } else { @@ -329,10 +307,6 @@ unitTest(function headerParamsArgumentsCheck(): void { } } assertEquals(hasThrown, 2); - assertStringIncludes( - errMsg, - `${method} requires at least 2 arguments, but only 1 present`, - ); }); }); @@ -361,8 +335,8 @@ unitTest(function headersAppendMultiple(): void { const actual = [...headers]; assertEquals(actual, [ ["set-cookie", "foo=bar"], - ["x-deno", "foo, bar"], ["set-cookie", "bar=baz"], + ["x-deno", "foo, bar"], ]); }); @@ -372,22 +346,12 @@ unitTest(function headersAppendDuplicateSetCookieKey(): void { headers.append("Set-cookie", "baz=bar"); const actual = [...headers]; assertEquals(actual, [ + ["set-cookie", "foo=bar"], ["set-cookie", "foo=baz"], ["set-cookie", "baz=bar"], ]); }); -unitTest(function headersSetDuplicateCookieKey(): void { - const headers = new Headers([["Set-Cookie", "foo=bar"]]); - headers.set("set-Cookie", "foo=baz"); - headers.set("set-cookie", "bar=qat"); - const actual = [...headers]; - assertEquals(actual, [ - ["set-cookie", "foo=baz"], - ["set-cookie", "bar=qat"], - ]); -}); - unitTest(function headersGetSetCookie(): void { const headers = new Headers([ ["Set-Cookie", "foo=bar"], @@ -411,7 +375,7 @@ unitTest(function customInspectReturnsCorrectHeadersFormat(): void { const singleHeader = new Headers([["Content-Type", "application/json"]]); assertEquals( stringify(singleHeader), - "Headers { content-type: application/json }", + `Headers { "content-type": "application/json" }`, ); const multiParamHeader = new Headers([ ["Content-Type", "application/json"], @@ -419,6 +383,6 @@ unitTest(function customInspectReturnsCorrectHeadersFormat(): void { ]); assertEquals( stringify(multiParamHeader), - "Headers { content-type: application/json, content-length: 1337 }", + `Headers { "content-length": "1337", "content-type": "application/json" }`, ); }); diff --git a/cli/tests/unit/unit_tests.ts b/cli/tests/unit/unit_tests.ts index 4cfd3d961..28924165f 100644 --- a/cli/tests/unit/unit_tests.ts +++ b/cli/tests/unit/unit_tests.ts @@ -35,7 +35,6 @@ import "./io_test.ts"; import "./link_test.ts"; import "./make_temp_test.ts"; import "./metrics_test.ts"; -import "./dom_iterable_test.ts"; import "./mkdir_test.ts"; import "./net_test.ts"; import "./os_test.ts"; |