0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

chore: add jsdoc to 26_fetch.js and enable some fetch tests (#9305)

This commit is contained in:
Luca Casonato 2021-01-28 21:37:21 +01:00 committed by GitHub
parent 7bda0f567e
commit 6ecc86cf2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 728 additions and 306 deletions

View file

@ -436,175 +436,6 @@ declare interface Crypto {
): T;
}
declare class URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams,
);
static toString(): string;
/** Appends a specified key/value pair as a new search parameter.
*
* ```ts
* let searchParams = new URLSearchParams();
* searchParams.append('name', 'first');
* searchParams.append('name', 'second');
* ```
*/
append(name: string, value: string): void;
/** Deletes the given search parameter and its associated value,
* from the list of all search parameters.
*
* ```ts
* let searchParams = new URLSearchParams([['name', 'value']]);
* searchParams.delete('name');
* ```
*/
delete(name: string): void;
/** Returns all the values associated with a given search parameter
* as an array.
*
* ```ts
* searchParams.getAll('name');
* ```
*/
getAll(name: string): string[];
/** Returns the first value associated to the given search parameter.
*
* ```ts
* searchParams.get('name');
* ```
*/
get(name: string): string | null;
/** Returns a Boolean that indicates whether a parameter with the
* specified name exists.
*
* ```ts
* searchParams.has('name');
* ```
*/
has(name: string): boolean;
/** Sets the value associated with a given search parameter to the
* given value. If there were several matching values, this method
* deletes the others. If the search parameter doesn't exist, this
* method creates it.
*
* ```ts
* searchParams.set('name', 'value');
* ```
*/
set(name: string, value: string): void;
/** Sort all key/value pairs contained in this object in place and
* return undefined. The sort order is according to Unicode code
* points of the keys.
*
* ```ts
* searchParams.sort();
* ```
*/
sort(): void;
/** Calls a function for each element contained in this object in
* place and return undefined. Optionally accepts an object to use
* as this when executing callback as second argument.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* params.forEach((value, key, parent) => {
* console.log(value, key, parent);
* });
* ```
*
*/
forEach(
callbackfn: (value: string, key: string, parent: this) => void,
thisArg?: any,
): void;
/** Returns an iterator allowing to go through all keys contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const key of params.keys()) {
* console.log(key);
* }
* ```
*/
keys(): IterableIterator<string>;
/** Returns an iterator allowing to go through all values contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const value of params.values()) {
* console.log(value);
* }
* ```
*/
values(): IterableIterator<string>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params.entries()) {
* console.log(key, value);
* }
* ```
*/
entries(): IterableIterator<[string, string]>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params) {
* console.log(key, value);
* }
* ```
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
/** Returns a query string suitable for use in a URL.
*
* ```ts
* searchParams.toString();
* ```
*/
toString(): string;
}
/** The URL interface represents an object providing static methods used for creating object URLs. */
declare class URL {
constructor(url: string, base?: string | URL);
createObjectURL(object: any): string;
revokeObjectURL(url: string): void;
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
}
interface MessageEventInit<T = any> extends EventInit {
data?: T;
origin?: string;

View file

@ -108,10 +108,9 @@ 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 => {
// deno-lint-ignore no-explicit-any
(response as any).bodyUsed = true;
});
// deno-lint-ignore no-explicit-any
(response as any).bodyUsed = true;
assertEquals(response.bodyUsed, false);
await response.blob();
assertEquals(response.bodyUsed, true);
});

View file

@ -78,7 +78,7 @@ unitTest(function formDataParamsSetSuccess(): void {
assertEquals(formData.get("e"), "null");
});
unitTest(function fromDataUseDomFile(): void {
unitTest(function fromDataUseFile(): void {
const formData = new FormData();
const file = new File(["foo"], "bar", {
type: "text/plain",

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, unitTest } from "./test_util.ts";
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function fromInit(): void {
unitTest(async function fromInit(): Promise<void> {
const req = new Request("http://foo/", {
body: "ahoyhoy",
method: "POST",
@ -10,22 +10,18 @@ unitTest(function fromInit(): void {
},
});
// deno-lint-ignore no-explicit-any
assertEquals("ahoyhoy", (req as any)._bodySource);
assertEquals("ahoyhoy", await req.text());
assertEquals(req.url, "http://foo/");
assertEquals(req.headers.get("test-header"), "value");
});
unitTest(function fromRequest(): void {
const r = new Request("http://foo/");
// deno-lint-ignore no-explicit-any
(r as any)._bodySource = "ahoyhoy";
unitTest(async function fromRequest(): Promise<void> {
const r = new Request("http://foo/", { body: "ahoyhoy" });
r.headers.set("test-header", "value");
const req = new Request(r);
// deno-lint-ignore no-explicit-any
assertEquals((req as any)._bodySource, (r as any)._bodySource);
assertEquals(await r.text(), await req.text());
assertEquals(req.url, r.url);
assertEquals(req.headers.get("test-header"), r.headers.get("test-header"));
});
@ -65,7 +61,4 @@ unitTest(async function cloneRequestBodyStream(): Promise<void> {
const b2 = await r2.text();
assertEquals(b1, b2);
// deno-lint-ignore no-explicit-any
assert((r1 as any)._bodySource !== (r2 as any)._bodySource);
});

39
core/lib.deno_core.d.ts vendored Normal file
View file

@ -0,0 +1,39 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare namespace Deno {
declare namespace core {
/** Send a JSON op to Rust, and synchronously recieve the result. */
function jsonOpSync(
opName: string,
args: any,
...zeroCopy: Uint8Array[]
): any;
/** Send a JSON op to Rust, and asynchronously recieve the result. */
function jsonOpAsync(
opName: string,
args: any,
...zeroCopy: Uint8Array[]
): Promise<any>;
/**
* Retrieve a list of all registered ops, in the form of a map that maps op
* name to internal numerical op id.
*/
function ops(): Record<string, number>;
/**
* Retrieve a list of all open resources, in the form of a map that maps
* resource id to the resource name.
*/
function resources(): Record<string, string>;
/** Close the resource with the specified op id. */
function close(rid: number): void;
}
}

File diff suppressed because it is too large Load diff

27
op_crates/fetch/internal.d.ts vendored Normal file
View file

@ -0,0 +1,27 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare namespace globalThis {
declare namespace __bootstrap {
declare var fetchUtil: {
requiredArguments(name: string, length: number, required: number): void;
};
declare var domIterable: {
DomIterableMixin(base: any, dataSymbol: symbol): any;
};
declare var headers: {
Headers: typeof Headers;
};
declare var streams: {
ReadableStream: typeof ReadableStream;
isReadableStreamDisturbed(stream: ReadableStream): boolean;
};
}
}

16
op_crates/web/internal.d.ts vendored Normal file
View file

@ -0,0 +1,16 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare namespace globalThis {
declare namespace __bootstrap {
declare var url: {
URLSearchParams: typeof URLSearchParams;
};
declare var location: {
getLocationHref(): string | undefined;
};
}
}

View file

@ -313,3 +313,172 @@ declare var FileReader: {
readonly EMPTY: number;
readonly LOADING: number;
};
declare class URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams,
);
static toString(): string;
/** Appends a specified key/value pair as a new search parameter.
*
* ```ts
* let searchParams = new URLSearchParams();
* searchParams.append('name', 'first');
* searchParams.append('name', 'second');
* ```
*/
append(name: string, value: string): void;
/** Deletes the given search parameter and its associated value,
* from the list of all search parameters.
*
* ```ts
* let searchParams = new URLSearchParams([['name', 'value']]);
* searchParams.delete('name');
* ```
*/
delete(name: string): void;
/** Returns all the values associated with a given search parameter
* as an array.
*
* ```ts
* searchParams.getAll('name');
* ```
*/
getAll(name: string): string[];
/** Returns the first value associated to the given search parameter.
*
* ```ts
* searchParams.get('name');
* ```
*/
get(name: string): string | null;
/** Returns a Boolean that indicates whether a parameter with the
* specified name exists.
*
* ```ts
* searchParams.has('name');
* ```
*/
has(name: string): boolean;
/** Sets the value associated with a given search parameter to the
* given value. If there were several matching values, this method
* deletes the others. If the search parameter doesn't exist, this
* method creates it.
*
* ```ts
* searchParams.set('name', 'value');
* ```
*/
set(name: string, value: string): void;
/** Sort all key/value pairs contained in this object in place and
* return undefined. The sort order is according to Unicode code
* points of the keys.
*
* ```ts
* searchParams.sort();
* ```
*/
sort(): void;
/** Calls a function for each element contained in this object in
* place and return undefined. Optionally accepts an object to use
* as this when executing callback as second argument.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* params.forEach((value, key, parent) => {
* console.log(value, key, parent);
* });
* ```
*
*/
forEach(
callbackfn: (value: string, key: string, parent: this) => void,
thisArg?: any,
): void;
/** Returns an iterator allowing to go through all keys contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const key of params.keys()) {
* console.log(key);
* }
* ```
*/
keys(): IterableIterator<string>;
/** Returns an iterator allowing to go through all values contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const value of params.values()) {
* console.log(value);
* }
* ```
*/
values(): IterableIterator<string>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params.entries()) {
* console.log(key, value);
* }
* ```
*/
entries(): IterableIterator<[string, string]>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params) {
* console.log(key, value);
* }
* ```
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
/** Returns a query string suitable for use in a URL.
*
* ```ts
* searchParams.toString();
* ```
*/
toString(): string;
}
/** The URL interface represents an object providing static methods used for creating object URLs. */
declare class URL {
constructor(url: string, base?: string | URL);
createObjectURL(object: any): string;
revokeObjectURL(url: string): void;
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
}

View file

@ -210,7 +210,7 @@ delete Object.prototype.__proto__;
ErrorEvent: util.nonEnumerable(ErrorEvent),
Event: util.nonEnumerable(Event),
EventTarget: util.nonEnumerable(EventTarget),
File: util.nonEnumerable(fetch.DomFile),
File: util.nonEnumerable(fetch.File),
FileReader: util.nonEnumerable(fileReader.FileReader),
FormData: util.nonEnumerable(fetch.FormData),
Headers: util.nonEnumerable(headers.Headers),

@ -1 +1 @@
Subproject commit 928edf7353e946398020326964d42de56b3cd542
Subproject commit ec40449a41939504a6adc039e7d98f52ec8894c9

View file

@ -961,14 +961,8 @@
"URLSearchParams constructed with: %EF%BB%BFtest=%EF%BB%BF",
"request.formData() with input: test=",
"response.formData() with input: test=",
"request.formData() with input: %FE%FF",
"response.formData() with input: %FE%FF",
"request.formData() with input: %FF%FE",
"response.formData() with input: %FF%FE",
"request.formData() with input: %C2",
"response.formData() with input: %C2",
"request.formData() with input: %C2x",
"response.formData() with input: %C2x",
"request.formData() with input: †&†=x",
"response.formData() with input: †&†=x",
"request.formData() with input: _charset_=windows-1252&test=%C2x",
"response.formData() with input: _charset_=windows-1252&test=%C2x",
"request.formData() with input: %=a",
@ -1006,5 +1000,23 @@
"urlsearchparams-set.any.js": true,
"urlsearchparams-sort.any.js": true,
"urlsearchparams-stringifier.any.js": true
},
"fetch": {
"api": {
"request": {
"request-structure.any.js": [
"Check destination attribute",
"Check referrer attribute",
"Check referrerPolicy attribute",
"Check mode attribute",
"Check credentials attribute",
"Check cache attribute",
"Check redirect attribute",
"Check integrity attribute",
"Check isReloadNavigation attribute",
"Check isHistoryNavigation attribute"
]
}
}
}
}