mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
Fix isomorphic-fetch module setup (#9144)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/// <reference path="isomorphic-fetch.d.ts"/>
|
||||
|
||||
function test_isomorphicFetchTestCases() {
|
||||
import fetchImportedViaCommonJS = require('isomorphic-fetch');
|
||||
import * as fetchImportedViaES6Module from 'isomorphic-fetch';
|
||||
|
||||
function test_isomorphicFetchTestCases_ambient() {
|
||||
expectSuccess(fetch('http://localhost:3000/good'), 'Good response');
|
||||
|
||||
fetch('http://localhost:3000/bad')
|
||||
@@ -11,7 +14,30 @@ function test_isomorphicFetchTestCases() {
|
||||
});
|
||||
}
|
||||
|
||||
function test_whatwgTestCases() {
|
||||
function test_isomorphicFetchTestCases_commonjs() {
|
||||
expectSuccess(fetchImportedViaCommonJS('http://localhost:3000/good'), 'Good response');
|
||||
|
||||
fetchImportedViaCommonJS('http://localhost:3000/bad')
|
||||
.then((response: IResponse) => {
|
||||
return response.text();
|
||||
})
|
||||
.catch((err) => {
|
||||
});
|
||||
}
|
||||
|
||||
function test_isomorphicFetchTestCases_es6() {
|
||||
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/good'), 'Good response');
|
||||
|
||||
fetchImportedViaES6Module('http://localhost:3000/bad')
|
||||
.then((response: IResponse) => {
|
||||
return response.text();
|
||||
})
|
||||
.catch((err) => {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function test_whatwgTestCases_ambient() {
|
||||
var headers = new Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
var requestOptions: RequestInit = {
|
||||
@@ -43,6 +69,72 @@ function test_whatwgTestCases() {
|
||||
|
||||
expectSuccess(fetch(request), 'Post response:');
|
||||
}
|
||||
|
||||
function test_whatwgTestCases_commonjs() {
|
||||
var headers = new Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
mode: 'same-origin',
|
||||
credentials: 'omit',
|
||||
cache: 'default'
|
||||
};
|
||||
|
||||
expectSuccess(fetchImportedViaCommonJS('http://localhost:3000/poster', requestOptions), 'Post response:');
|
||||
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
expectSuccess(fetchImportedViaCommonJS('http://localhost:3000/poster', requestOptions), 'Post response:');
|
||||
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
var request: Request = new Request('http://localhost:3000/poster', requestOptions);
|
||||
|
||||
expectSuccess(fetchImportedViaCommonJS(request), 'Post response:');
|
||||
}
|
||||
|
||||
function test_whatwgTestCases_es6() {
|
||||
var headers = new Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
mode: 'same-origin',
|
||||
credentials: 'omit',
|
||||
cache: 'default'
|
||||
};
|
||||
|
||||
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:');
|
||||
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:');
|
||||
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
var request: Request = new Request('http://localhost:3000/poster', requestOptions);
|
||||
|
||||
expectSuccess(fetchImportedViaES6Module(request), 'Post response:');
|
||||
}
|
||||
|
||||
function expectSuccess(promise: Promise<IResponse>, responseText: string) {
|
||||
promise.then((response: IResponse) => {
|
||||
|
||||
8
isomorphic-fetch/isomorphic-fetch.d.ts
vendored
8
isomorphic-fetch/isomorphic-fetch.d.ts
vendored
@@ -112,8 +112,8 @@ interface IFetchStatic {
|
||||
(url: string | IRequest, init?: RequestInit): Promise<IResponse>;
|
||||
}
|
||||
|
||||
declare module "isomorphic-fetch" {
|
||||
export default IFetchStatic;
|
||||
}
|
||||
|
||||
declare var fetch: IFetchStatic;
|
||||
|
||||
declare module "isomorphic-fetch" {
|
||||
export = fetch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user