Skip to content

Commit ad43020

Browse files
author
Benjamin Lichtman
committed
Add tests
1 parent 1b9507a commit ad43020

10 files changed

+132
-4
lines changed

src/testRunner/unittests/convertToAsyncFunction.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ function [#|f|]() {
817817
);
818818
_testConvertToAsyncFunction("convertToAsyncFunction_Scope1", `
819819
function [#|f|]() {
820-
var var1:Promise<Response>, var2;
820+
var var1: Response, var2;
821821
return fetch('https://typescriptlang.org').then( _ =>
822822
Promise.resolve().then( res => {
823823
var2 = "test";
@@ -1190,6 +1190,30 @@ function [#|f|]() {
11901190
function res(result) {
11911191
return Promise.resolve().then(x => console.log(result));
11921192
}
1193+
`);
1194+
1195+
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromise", `
1196+
function [#|f|]() {
1197+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
1198+
}
1199+
`);
1200+
1201+
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromiseInBlock", `
1202+
function [#|f|]() {
1203+
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
1204+
}
1205+
`);
1206+
1207+
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsFixablePromise", `
1208+
function [#|f|]() {
1209+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
1210+
}
1211+
`);
1212+
1213+
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromiseLastInChain", `
1214+
function [#|f|]() {
1215+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
1216+
}
11931217
`);
11941218

11951219
});

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Scope1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==ORIGINAL==
22

33
function /*[#|*/f/*|]*/() {
4-
var var1:Promise<Response>, var2;
4+
var var1: Response, var2;
55
return fetch('https://typescriptlang.org').then( _ =>
66
Promise.resolve().then( res => {
77
var2 = "test";
@@ -18,11 +18,11 @@ function /*[#|*/f/*|]*/() {
1818
// ==ASYNC FUNCTION::Convert to async function==
1919

2020
async function f() {
21-
var var1:Promise<Response>, var2;
21+
var var1: Response, var2;
2222
await fetch('https://typescriptlang.org');
2323
const res = await Promise.resolve();
2424
var2 = "test";
25-
const res_1 = fetch("https://microsoft.com");
25+
const res_1 = await fetch("https://microsoft.com");
2626
const response = var1 === res_1;
2727
return res(response);
2828
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const st = await Promise.resolve(s.statusText);
12+
const x = st.length;
13+
return console.log(x + 5);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const st = await Promise.resolve(s.statusText);
12+
const x = st.length;
13+
return console.log(x + 5);
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const x = await Promise.resolve(s.statusText.length);
12+
return console.log(x + 5);
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const x = await Promise.resolve(s.statusText.length);
12+
return console.log(x + 5);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const x = await Promise.resolve(s.statusText.length);
12+
return x + 5;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
const x = await Promise.resolve(s.statusText.length);
12+
return x + 5;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
return Promise.resolve(s.statusText.length);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
async function f() {
10+
const s = await fetch('https://typescriptlang.org');
11+
return Promise.resolve(s.statusText.length);
12+
}

0 commit comments

Comments
 (0)